playlist.c 4.96 KB
Newer Older
zorglub's avatar
zorglub committed
1 2 3 4
/*****************************************************************************
 * playlist.c :  Playlist import module
 *****************************************************************************
 * Copyright (C) 2004 VideoLAN
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 36 37

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
vlc_module_begin();
    add_shortcut( "playlist" );
zorglub's avatar
zorglub committed
38 39
    set_category( CAT_INPUT );
    set_subcategory( SUBCAT_INPUT_DEMUX );
zorglub's avatar
zorglub committed
40 41 42

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


/**
 * Find directory part of the path to the playlist file, in case of
 * relative paths inside
 */
char *FindPrefix( demux_t *p_demux )
{
    char *psz_name;
    char *psz_path = strdup( p_demux->psz_path );

#ifndef WIN32
    psz_name = strrchr( psz_path, '/' );
#else
    psz_name = strrchr( psz_path, '\\' );
85
    if( !psz_name ) psz_name = strrchr( psz_path, '/' );
sigmunau's avatar
sigmunau committed
86
#endif
87
    if( psz_name ) psz_name[1] = '\0';
sigmunau's avatar
sigmunau committed
88
    else *psz_path = '\0';
89

sigmunau's avatar
sigmunau committed
90 91 92 93 94 95 96 97 98
    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
 */
char *ProcessMRL( char *psz_mrl, char *psz_prefix )
{
99 100
    /* Check for a protocol name.
     * for URL, we should look for "://"
sigmunau's avatar
sigmunau committed
101
     * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
102 103
     * 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
104

105 106 107 108 109 110
    /* 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
111

112 113 114 115 116 117 118 119
    /* 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;
}
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

vlc_bool_t FindItem( demux_t *p_demux, playlist_t *p_playlist,
                     playlist_item_t **pp_item )
{
     vlc_bool_t b_play;
     if( &p_playlist->status.p_item->input ==
         ((input_thread_t *)p_demux->p_parent)->input.p_item )
     {
         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;
136
         *pp_item = playlist_LockItemGetByInput( p_playlist, p_current );
137 138 139 140 141 142 143 144 145
         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;
}