playlist.c 4.52 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>
zorglub's avatar
zorglub committed
29

sigmunau's avatar
sigmunau committed
30
#include "playlist.h"
zorglub's avatar
zorglub committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
vlc_module_begin();
    add_shortcut( "playlist" );

    set_description( _("Old playlist open") );
    add_shortcut( "old-open" );
    set_capability( "demux2" , 10 );
    set_callbacks( Import_Old , NULL );

    add_submodule();
        set_description( _("M3U playlist import") );
        add_shortcut( "m3u-open" );
        set_capability( "demux2" , 10 );
sigmunau's avatar
sigmunau committed
47 48 49 50 51 52
        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
53
vlc_module_end();
sigmunau's avatar
sigmunau committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126


/**
 * 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, '\\' );
    if ( ! psz_name ) psz_name = strrchr( psz_path, '/' );
#endif
    if( psz_name ) *psz_name = '\0';
    else *psz_path = '\0';
    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 )
{
    char *psz_name;
    /* check for a protocol name */
    /* for URL, we should look for "://"
     * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]),
     * we should look for ":"
     * so we end up looking simply for ":"*/
    /* PB: on some file systems, ':' are valid characters though*/
    psz_name = psz_mrl;
    while( *psz_name && *psz_name!=':' )
    {
        psz_name++;
    }
#ifdef WIN32
    if ( *psz_name && ( psz_name == psz_mrl + 1 ) )
    {
        /* if it is not an URL,
         * as it is unlikely to be an MRL (PB: if it is ?)
         * it should be an absolute file name with the drive letter */
        if ( *(psz_name+1) == '/' )/* "*:/" */
        {
            if ( *(psz_name+2) != '/' )/* not "*://" */
                while ( *psz_name ) *psz_name++;/* so now (*psz_name==0) */
        }
        else while ( *psz_name ) *psz_name++;/* "*:*"*/
    }
#endif

    /* if the line doesn't specify a protocol name,
     * check if the line has an absolute or relative path */
#ifndef WIN32
    if( !*psz_name && *psz_mrl != '/' )
         /* If this line doesn't begin with a '/' */
#else
    if( !*psz_name
            && *psz_mrl!='/'
            && *psz_mrl!='\\'
            && *(psz_mrl+1)!=':' )
         /* if this line doesn't begin with
          *  "/" or "\" or "*:" or "*:\" or "*:/" or "\\" */
#endif
    {
#ifndef WIN32
        psz_name = malloc( strlen(psz_prefix) + strlen(psz_mrl) + 2 );
        sprintf( psz_name, "%s/%s", psz_prefix, psz_mrl );
#else
gbazin's avatar
 
gbazin committed
127
        if ( *psz_prefix != '\0' )
sigmunau's avatar
sigmunau committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141
        {
            psz_name = malloc( strlen(psz_prefix) + strlen(psz_mrl) + 2 );
            sprintf( psz_name, "%s\\%s", psz_prefix, psz_mrl );
        }
        else psz_name = strdup( psz_mrl );
#endif
    }
    else
    {
        psz_name = strdup( psz_mrl );
    }
    return psz_name;
}