old.c 3.63 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * old.c : Old playlist format import
 *****************************************************************************
4
 * Copyright (C) 2004 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
6
 *
7
 * Authors: Clément Stenac <zorglub@videolan.org>
zorglub's avatar
zorglub committed
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * 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
dionoea's avatar
dionoea committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
zorglub's avatar
zorglub committed
22
23
24
25
26
27
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <vlc/vlc.h>
28
#include <vlc/input.h>
zorglub's avatar
zorglub committed
29
#include <vlc/intf.h>
30
#include "charset.h"
zorglub's avatar
zorglub committed
31
32
33
34
35
36
37
38
39
40
41
42

#define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static int Demux( demux_t *p_demux);
static int Control( demux_t *p_demux, int i_query, va_list args );

/*****************************************************************************
 * Import_Old : main import function
 *****************************************************************************/
43
int E_(Import_Old)( vlc_object_t *p_this )
zorglub's avatar
zorglub committed
44
45
46
47
{
    demux_t *p_demux = (demux_t *)p_this;
    uint8_t *p_peek;

48
49
    if( stream_Peek( p_demux->s, &p_peek, 31 ) < 31 ) return VLC_EGENERIC;

50
    if( strncmp( (char *)p_peek, PLAYLIST_FILE_HEADER , 31 ) ) return VLC_EGENERIC;
zorglub's avatar
zorglub committed
51

hartman's avatar
hartman committed
52
    msg_Dbg( p_demux, "found valid old playlist file");
zorglub's avatar
zorglub committed
53
54
55
56
57
58
59
60
61
62
63
64
65
    p_demux->pf_control = Control;
    p_demux->pf_demux = Demux;

    return VLC_SUCCESS;
}

static int Demux( demux_t *p_demux)
{
    char *psz_line;
    /* Attach playlist and start reading data */
    playlist_t *p_playlist;

    p_playlist = (playlist_t*)vlc_object_find( p_demux,
zorglub's avatar
zorglub committed
66
                         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
zorglub's avatar
zorglub committed
67
68
69
70
71
72
73
74
    if( !p_playlist )
    {
        msg_Err( p_demux, "cannot attach playlist" );
        return VLC_EGENERIC;
    }

    while( ( psz_line = stream_ReadLine( p_demux->s) ) != NULL )
    {
75
76
        char *psz_unicode;

zorglub's avatar
zorglub committed
77
78
79
80
81
82
83
84
85
86
87
88
89
        if( ( psz_line[0] == '#' ) || (psz_line[0] == '\r') ||
            ( psz_line[0] == '\n') || (psz_line[0] == (char)0) )
        {
            continue;
        }
        /* Remove end of line */
        if( psz_line[strlen(psz_line) -1 ] == '\n' ||
            psz_line[strlen(psz_line) -1 ] == '\r' )
        {
            psz_line[ strlen(psz_line) -1 ] = (char)0;
            if( psz_line[strlen(psz_line) - 1 ] == '\r' )
                psz_line[strlen(psz_line) - 1 ] = (char)0;
        }
90
91

        psz_unicode = FromLocale( psz_line );
92
93
//        playlist_Add( p_playlist, psz_unicode, psz_unicode, PLAYLIST_APPEND,
//                      PLAYLIST_END );
zorglub's avatar
zorglub committed
94
95

        free( psz_line );
96
        LocaleFree( psz_line );
zorglub's avatar
zorglub committed
97
98
99
100
101
102
103
104
105
106
107
    }

    p_demux->b_die = VLC_TRUE;
    vlc_object_release( p_playlist );
    return VLC_SUCCESS;
}

static int Control( demux_t *p_demux, int i_query, va_list args )
{
    return VLC_EGENERIC;
}