vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Wed Mar 1 20:14:39 2017 +0200| [c6163786db1533d379c6be8a521423a11105510e] | committer: Rémi Denis-Courmont
m3u export: write relative URLs sometimes (fixes #3095) If the URL points within the same directory as the output playlist file or descendent of that directory, use relative URL. There are no ways to guess 100% how relative the URL should be. This is purely a heuristic. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c6163786db1533d379c6be8a521423a11105510e --- modules/misc/playlist/m3u.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/misc/playlist/m3u.c b/modules/misc/playlist/m3u.c index 4f7b308..6a31f14 100644 --- a/modules/misc/playlist/m3u.c +++ b/modules/misc/playlist/m3u.c @@ -50,6 +50,14 @@ int Export_M3U8( vlc_object_t * ); static void DoChildren( playlist_export_t *p_export, playlist_item_t *p_root, int (*pf_fprintf) (FILE *, const char *, ...) ) { + size_t prefix_len = -1; + if( likely(p_export->base_url != NULL) ) + { + const char *p = strrchr( p_export->base_url, '/' ); + assert(p != NULL); + prefix_len = (p + 1) - p_export->base_url; + } + /* Write header */ fputs( "#EXTM3U\n", p_export->p_file ); @@ -104,7 +112,15 @@ static void DoChildren( playlist_export_t *p_export, playlist_item_t *p_root, } vlc_mutex_unlock( &p_current->p_input->lock ); - fprintf( p_export->p_file, "%s\n", psz_uri ); + /* We cannot really know if relative or absolute URL is better. As a + * heuristic, we write a relative URL if the item is in the same + * directory as the playlist, or a sub-directory thereof. */ + size_t skip = 0; + if( likely(prefix_len != (size_t)-1) + && !strncmp( p_export->base_url, psz_uri, prefix_len ) ) + skip = prefix_len; + + fprintf( p_export->p_file, "%s\n", psz_uri + skip ); free( psz_uri ); } } _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
