]> git.sesse.net Git - vlc/blobdiff - modules/misc/playlist/m3u.c
M3U export: use local paths if applicable (fix #4063)
[vlc] / modules / misc / playlist / m3u.c
index 05b6b210c98dfcc7c2bf70e55746694cfe11347c..5e69ae3f292a6e739e3ab3066de36f6c9f9274ba 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
- * m3u.c :  M3U playlist export module
+ * m3u.c : M3U playlist export module
  *****************************************************************************
- * Copyright (C) 2004 the VideoLAN team
+ * Copyright (C) 2004-2009 the VideoLAN team
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
-#include <vlc_interface.h>
+#include <vlc_common.h>
 #include <vlc_playlist.h>
 #include <vlc_input.h>
 #include <vlc_meta.h>
-
-#include <errno.h>                                                 /* ENOMEM */
+#include <vlc_charset.h>
+#include <vlc_url.h>
 
 #include <assert.h>
 
  * Local prototypes
  *****************************************************************************/
 int Export_M3U ( vlc_object_t * );
+int Export_M3U8( vlc_object_t * );
 
 /*****************************************************************************
  * Export_M3U: main export function
  *****************************************************************************/
-static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export,
-                        playlist_item_t *p_root )
+static void DoChildren( playlist_export_t *p_export, playlist_item_t *p_root,
+                        int (*pf_fprintf) (FILE *, const char *, ...) )
 {
     int i, j;
 
@@ -63,7 +63,7 @@ static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export,
 
         if( p_current->i_children >= 0 )
         {
-            DoChildren( p_playlist, p_export, p_current );
+            DoChildren( p_export, p_current, pf_fprintf );
             continue;
         }
 
@@ -82,14 +82,14 @@ static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export,
             if( psz_artist && *psz_artist )
             {
                 /* write EXTINF with artist */
-                fprintf( p_export->p_file, "#EXTINF:%i,%s - %s\n",
-                          (int)( i_duration / 1000000 ), psz_artist, psz_name);
+                pf_fprintf( p_export->p_file, "#EXTINF:%"PRIu64",%s - %s\n",
+                            i_duration / CLOCK_FREQ, psz_artist, psz_name);
             }
             else
             {
                 /* write EXTINF without artist */
-                fprintf( p_export->p_file, "#EXTINF:%i,%s\n",
-                         (int)( i_duration / 1000000 ), psz_name);
+                pf_fprintf( p_export->p_file, "#EXTINF:%"PRIu64",%s\n",
+                            i_duration / CLOCK_FREQ, psz_name);
             }
             free( psz_artist );
         }
@@ -99,13 +99,20 @@ static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export,
         vlc_mutex_lock( &p_current->p_input->lock );
         for( j = 0; j < p_current->p_input->i_options; j++ )
         {
-            fprintf( p_export->p_file, "#EXTVLCOPT:%s\n",
-                     p_current->p_input->ppsz_options[j][0] == ':' ?
-                     p_current->p_input->ppsz_options[j] + 1 :
-                     p_current->p_input->ppsz_options[j] );
+            pf_fprintf( p_export->p_file, "#EXTVLCOPT:%s\n",
+                        p_current->p_input->ppsz_options[j][0] == ':' ?
+                        p_current->p_input->ppsz_options[j] + 1 :
+                        p_current->p_input->ppsz_options[j] );
         }
         vlc_mutex_unlock( &p_current->p_input->lock );
 
+        /* Stupid third party players don't understand file: URIs. */
+        char *psz_path = make_path( psz_uri );
+        if( psz_path != NULL )
+        {
+            free( psz_uri );
+            psz_uri = psz_path;
+        }
         fprintf( p_export->p_file, "%s\n", psz_uri );
         free( psz_uri );
     }
@@ -113,14 +120,26 @@ static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export,
 
 int Export_M3U( vlc_object_t *p_this )
 {
-    playlist_t *p_playlist = (playlist_t*)p_this;
-    playlist_export_t *p_export = (playlist_export_t *)p_playlist->p_private;
+    playlist_export_t *p_export = (playlist_export_t *)p_this;
+
+    msg_Dbg( p_export, "saving using M3U format");
+
+    /* Write header */
+    fputs( "#EXTM3U\n", p_export->p_file );
+
+    DoChildren( p_export, p_export->p_root, utf8_fprintf );
+    return VLC_SUCCESS;
+}
+
+int Export_M3U8( vlc_object_t *p_this )
+{
+    playlist_export_t *p_export = (playlist_export_t *)p_this;
 
-    msg_Dbg(p_playlist, "saving using M3U format");
+    msg_Dbg( p_export, "saving using M3U8 format");
 
     /* Write header */
-    fprintf( p_export->p_file, "#EXTM3U\n" );
+    fputs( "#EXTM3U\n", p_export->p_file );
 
-    DoChildren( p_playlist, p_export, p_export->p_root );
+    DoChildren( p_export, p_export->p_root, fprintf );
     return VLC_SUCCESS;
 }