playlist.c 5.43 KB
Newer Older
zorglub's avatar
zorglub committed
1 2 3
/*****************************************************************************
 * playlist.c :  Playlist import module
 *****************************************************************************
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
4
 * Copyright (C) 2004 VideoLAN (Centrale Réseaux) and its contributors
5
 * $Id$
zorglub's avatar
zorglub committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * Authors: Clment Stenac <zorglub@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <vlc/vlc.h>
Laurent Aimar's avatar
Laurent Aimar committed
28
#include <vlc/input.h>
29
#include <vlc_playlist.h>
zorglub's avatar
zorglub committed
30

sigmunau's avatar
sigmunau committed
31
#include "playlist.h"
zorglub's avatar
zorglub committed
32 33 34 35

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
36 37 38 39
#define AUTOSTART_TEXT N_( "Auto start" )
#define AUTOSTART_LONGTEXT N_( "Automatically start the playlist when " \
    "it's loaded.\n" )

zorglub's avatar
zorglub committed
40 41
vlc_module_begin();
    add_shortcut( "playlist" );
zorglub's avatar
zorglub committed
42 43
    set_category( CAT_INPUT );
    set_subcategory( SUBCAT_INPUT_DEMUX );
zorglub's avatar
zorglub committed
44

45 46 47
    add_bool( "playlist-autostart", 1, NULL, AUTOSTART_TEXT, AUTOSTART_LONGTEXT,
              VLC_FALSE );

48
    set_shortname( _("Playlist") );
zorglub's avatar
zorglub committed
49 50
    set_description( _("Old playlist open") );
    add_shortcut( "old-open" );
51
    set_capability( "demux2", 10 );
52
    set_callbacks( E_(Import_Old), NULL );
zorglub's avatar
zorglub committed
53
#if 0
zorglub's avatar
zorglub committed
54
    add_submodule();
zorglub's avatar
zorglub committed
55 56 57
        set_description( _("Native playlist import") );
        add_shortcut( "playlist" );
        add_shortcut( "native-open" );
58
        set_capability( "demux2", 10 );
59
        set_callbacks( E_(Import_Native), E_(Close_Native) );
zorglub's avatar
zorglub committed
60
#endif
sigmunau's avatar
sigmunau committed
61
    add_submodule();
zorglub's avatar
zorglub committed
62 63
        set_description( _("M3U playlist import") );
        add_shortcut( "m3u-open" );
64
        set_capability( "demux2", 10 );
65
        set_callbacks( E_(Import_M3U), E_(Close_M3U) );
zorglub's avatar
zorglub committed
66 67 68
    add_submodule();
        set_description( _("PLS playlist import") );
        add_shortcut( "pls-open" );
69
        set_capability( "demux2", 10 );
70
        set_callbacks( E_(Import_PLS), E_(Close_PLS) );
71 72 73
    add_submodule();
        set_description( _("B4S playlist import") );
        add_shortcut( "b4s-open" );
74
        add_shortcut( "shout-b4s" );
75
        set_capability( "demux2", 10 );
76
        set_callbacks( E_(Import_B4S), E_(Close_B4S) );
zorglub's avatar
zorglub committed
77
vlc_module_end();
sigmunau's avatar
sigmunau committed
78 79 80 81 82 83


/**
 * Find directory part of the path to the playlist file, in case of
 * relative paths inside
 */
84
char *E_(FindPrefix)( demux_t *p_demux )
sigmunau's avatar
sigmunau committed
85 86 87 88 89 90 91 92
{
    char *psz_name;
    char *psz_path = strdup( p_demux->psz_path );

#ifndef WIN32
    psz_name = strrchr( psz_path, '/' );
#else
    psz_name = strrchr( psz_path, '\\' );
93
    if( !psz_name ) psz_name = strrchr( psz_path, '/' );
sigmunau's avatar
sigmunau committed
94
#endif
95
    if( psz_name ) psz_name[1] = '\0';
sigmunau's avatar
sigmunau committed
96
    else *psz_path = '\0';
97

sigmunau's avatar
sigmunau committed
98 99 100 101 102 103 104
    return psz_path;
}

/**
 * Add the directory part of the playlist file to the start of the
 * mrl, if the mrl is a relative file path
 */
105
char *E_(ProcessMRL)( char *psz_mrl, char *psz_prefix )
sigmunau's avatar
sigmunau committed
106
{
107 108
    /* Check for a protocol name.
     * for URL, we should look for "://"
sigmunau's avatar
sigmunau committed
109
     * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
110 111
     * we should look for ":", so we end up looking simply for ":"
     * PB: on some file systems, ':' are valid characters though */
sigmunau's avatar
sigmunau committed
112

113 114 115 116 117 118
    /* Simple cases first */
    if( !psz_mrl || !*psz_mrl ) return NULL;
    if( !psz_prefix || !*psz_prefix ) return strdup( psz_mrl );

    /* Check if the line specifies an absolute path */
    if( *psz_mrl == '/' || *psz_mrl == '\\' ) return strdup( psz_mrl );
sigmunau's avatar
sigmunau committed
119

120 121 122 123 124 125 126 127
    /* Check if the line specifies an mrl/url
     * (and on win32, contains a drive letter) */
    if( strchr( psz_mrl, ':' ) ) return strdup( psz_mrl );

    /* This a relative path, prepend the prefix */
    asprintf( &psz_mrl, "%s%s", psz_prefix, psz_mrl );
    return psz_mrl;
}
128

129
vlc_bool_t E_(FindItem)( demux_t *p_demux, playlist_t *p_playlist,
130 131
                     playlist_item_t **pp_item )
{
132 133 134 135 136
     vlc_bool_t b_play = var_CreateGetBool( p_demux, "playlist-autostart" );

     if( b_play && p_playlist->status.p_item &&
             &p_playlist->status.p_item->input ==
                ((input_thread_t *)p_demux->p_parent)->input.p_item )
137 138 139 140 141 142 143 144 145
     {
         msg_Dbg( p_playlist, "starting playlist playback" );
         *pp_item = p_playlist->status.p_item;
         b_play = VLC_TRUE;
     }
     else
     {
         input_item_t *p_current = ( (input_thread_t*)p_demux->p_parent)->
                                                        input.p_item;
146
         *pp_item = playlist_LockItemGetByInput( p_playlist, p_current );
147 148 149 150 151 152 153 154 155
         if( !*pp_item )
         {
             msg_Dbg( p_playlist, "unable to find item in playlist");
         }
         msg_Dbg( p_playlist, "not starting playlist playback");
         b_play = VLC_FALSE;
     }
     return b_play;
}