playlist.c 4.73 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 43 44

    set_description( _("Old playlist open") );
    add_shortcut( "old-open" );
    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 50 51
        set_description( _("Native playlist import") );
        add_shortcut( "playlist" );
        add_shortcut( "native-open" );
        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 56 57 58 59 60 61 62
        set_description( _("M3U playlist import") );
        add_shortcut( "m3u-open" );
        set_capability( "demux2" , 10 );
        set_callbacks( Import_M3U , Close_M3U );
    add_submodule();
        set_description( _("PLS playlist import") );
        add_shortcut( "pls-open" );
        set_capability( "demux2" , 10 );
        set_callbacks( Import_PLS , Close_PLS );
zorglub's avatar
zorglub committed
63
vlc_module_end();
sigmunau's avatar
sigmunau committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78


/**
 * 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, '\\' );
79
    if( !psz_name ) psz_name = strrchr( psz_path, '/' );
sigmunau's avatar
sigmunau committed
80
#endif
81
    if( psz_name ) psz_name[1] = '\0';
sigmunau's avatar
sigmunau committed
82
    else *psz_path = '\0';
83

sigmunau's avatar
sigmunau committed
84 85 86 87 88 89 90 91 92
    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 )
{
93 94
    /* Check for a protocol name.
     * for URL, we should look for "://"
sigmunau's avatar
sigmunau committed
95
     * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
96 97
     * 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
98

99 100 101 102 103 104
    /* 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
105

106 107 108 109 110 111 112 113
    /* 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;
}
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

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;
130
         *pp_item = playlist_LockItemGetByInput( p_playlist, p_current );
131 132 133 134 135 136 137 138 139
         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;
}