| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
#ifdef HAVE_CONFIG_H |
|---|
| 52 |
# include "config.h" |
|---|
| 53 |
#endif |
|---|
| 54 |
|
|---|
| 55 |
#include <vlc_common.h> |
|---|
| 56 |
#include <vlc_demux.h> |
|---|
| 57 |
|
|---|
| 58 |
#include "playlist.h" |
|---|
| 59 |
|
|---|
| 60 |
#define MAX_LINE 1024 |
|---|
| 61 |
|
|---|
| 62 |
struct demux_sys_t |
|---|
| 63 |
{ |
|---|
| 64 |
input_item_t *p_current_input; |
|---|
| 65 |
}; |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
static int Demux( demux_t *p_demux); |
|---|
| 71 |
static int Control( demux_t *p_demux, int i_query, va_list args ); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
int Import_GVP( vlc_object_t *p_this ) |
|---|
| 77 |
{ |
|---|
| 78 |
demux_t *p_demux = (demux_t *)p_this; |
|---|
| 79 |
int i_peek, i, b_found = false; |
|---|
| 80 |
const uint8_t *p_peek; |
|---|
| 81 |
|
|---|
| 82 |
i_peek = stream_Peek( p_demux->s, &p_peek, MAX_LINE ); |
|---|
| 83 |
|
|---|
| 84 |
for( i = 0; i < i_peek - (int)sizeof("gvp_version:"); i++ ) |
|---|
| 85 |
{ |
|---|
| 86 |
if( p_peek[i] == 'g' && p_peek[i+1] == 'v' && p_peek[i+2] == 'p' && |
|---|
| 87 |
!memcmp( p_peek+i, "gvp_version:", sizeof("gvp_version:") - 1 ) ) |
|---|
| 88 |
{ |
|---|
| 89 |
b_found = true; |
|---|
| 90 |
break; |
|---|
| 91 |
} |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
if( !b_found ) return VLC_EGENERIC; |
|---|
| 95 |
|
|---|
| 96 |
STANDARD_DEMUX_INIT_MSG( "using Google Video Playlist (gvp) import" ); |
|---|
| 97 |
p_demux->pf_control = Control; |
|---|
| 98 |
p_demux->pf_demux = Demux; |
|---|
| 99 |
MALLOC_ERR( p_demux->p_sys, demux_sys_t ); |
|---|
| 100 |
|
|---|
| 101 |
return VLC_SUCCESS; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
void Close_GVP( vlc_object_t *p_this ) |
|---|
| 108 |
{ |
|---|
| 109 |
demux_t *p_demux = (demux_t *)p_this; |
|---|
| 110 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 111 |
|
|---|
| 112 |
free( p_sys ); |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
static int Demux( demux_t *p_demux ) |
|---|
| 116 |
{ |
|---|
| 117 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 118 |
|
|---|
| 119 |
char *psz_line; |
|---|
| 120 |
char *psz_attrvalue; |
|---|
| 121 |
|
|---|
| 122 |
char *psz_version = NULL; |
|---|
| 123 |
char *psz_url = NULL; |
|---|
| 124 |
char *psz_docid = NULL; |
|---|
| 125 |
int i_duration = -1; |
|---|
| 126 |
char *psz_title = NULL; |
|---|
| 127 |
char *psz_description = NULL; |
|---|
| 128 |
input_item_t *p_input; |
|---|
| 129 |
|
|---|
| 130 |
INIT_PLAYLIST_STUFF; |
|---|
| 131 |
|
|---|
| 132 |
p_sys->p_current_input = p_current_input; |
|---|
| 133 |
|
|---|
| 134 |
while( ( psz_line = stream_ReadLine( p_demux->s ) ) ) |
|---|
| 135 |
{ |
|---|
| 136 |
if( *psz_line == '#' ) |
|---|
| 137 |
{ |
|---|
| 138 |
|
|---|
| 139 |
free( psz_line ); |
|---|
| 140 |
continue; |
|---|
| 141 |
} |
|---|
| 142 |
psz_attrvalue = strchr( psz_line, ':' ); |
|---|
| 143 |
if( !psz_attrvalue ) |
|---|
| 144 |
{ |
|---|
| 145 |
msg_Dbg( p_demux, "Unable to parse line (%s)", psz_line ); |
|---|
| 146 |
free( psz_line ); |
|---|
| 147 |
continue; |
|---|
| 148 |
} |
|---|
| 149 |
*psz_attrvalue = '\0'; |
|---|
| 150 |
psz_attrvalue++; |
|---|
| 151 |
if( !strcmp( psz_line, "gvp_version" ) ) |
|---|
| 152 |
{ |
|---|
| 153 |
psz_version = strdup( psz_attrvalue ); |
|---|
| 154 |
} |
|---|
| 155 |
else if( !strcmp( psz_line, "url" ) ) |
|---|
| 156 |
{ |
|---|
| 157 |
psz_url = strdup( psz_attrvalue ); |
|---|
| 158 |
} |
|---|
| 159 |
else if( !strcmp( psz_line, "docid" ) ) |
|---|
| 160 |
{ |
|---|
| 161 |
psz_docid = strdup( psz_attrvalue ); |
|---|
| 162 |
} |
|---|
| 163 |
else if( !strcmp( psz_line, "duration" ) ) |
|---|
| 164 |
{ |
|---|
| 165 |
i_duration = atoi( psz_attrvalue ); |
|---|
| 166 |
} |
|---|
| 167 |
else if( !strcmp( psz_line, "title" ) ) |
|---|
| 168 |
{ |
|---|
| 169 |
psz_title = strdup( psz_attrvalue ); |
|---|
| 170 |
} |
|---|
| 171 |
else if( !strcmp( psz_line, "description" ) ) |
|---|
| 172 |
{ |
|---|
| 173 |
char *buf; |
|---|
| 174 |
if( !psz_description ) |
|---|
| 175 |
{ |
|---|
| 176 |
psz_description = strdup( psz_attrvalue ); |
|---|
| 177 |
} |
|---|
| 178 |
else |
|---|
| 179 |
{ |
|---|
| 180 |
|
|---|
| 181 |
buf = malloc( strlen( psz_description ) |
|---|
| 182 |
+ strlen( psz_attrvalue ) + 2 ); |
|---|
| 183 |
sprintf( buf, "%s\n%s", psz_description, psz_attrvalue ); |
|---|
| 184 |
free( psz_description ); |
|---|
| 185 |
psz_description = buf; |
|---|
| 186 |
} |
|---|
| 187 |
|
|---|
| 188 |
buf = psz_description + strlen( psz_description ); |
|---|
| 189 |
if( buf != psz_description ) |
|---|
| 190 |
{ |
|---|
| 191 |
buf--; |
|---|
| 192 |
if( *buf == '\r' ) *buf = '\0'; |
|---|
| 193 |
} |
|---|
| 194 |
} |
|---|
| 195 |
free( psz_line ); |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
if( !psz_url ) |
|---|
| 199 |
{ |
|---|
| 200 |
msg_Err( p_demux, "URL not found" ); |
|---|
| 201 |
} |
|---|
| 202 |
else |
|---|
| 203 |
{ |
|---|
| 204 |
p_input = input_item_NewExt( p_demux, |
|---|
| 205 |
psz_url, psz_title, 0, NULL, -1 ); |
|---|
| 206 |
#define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \ |
|---|
| 207 |
p_input, _("Google Video"), _(type), "%s", field ) ; } |
|---|
| 208 |
SADD_INFO( "gvp_version", psz_version ); |
|---|
| 209 |
SADD_INFO( "docid", psz_docid ); |
|---|
| 210 |
SADD_INFO( "description", psz_description ); |
|---|
| 211 |
input_item_AddSubItem( p_current_input, p_input ); |
|---|
| 212 |
vlc_gc_decref( p_input ); |
|---|
| 213 |
} |
|---|
| 214 |
|
|---|
| 215 |
HANDLE_PLAY_AND_RELEASE; |
|---|
| 216 |
|
|---|
| 217 |
free( psz_version ); |
|---|
| 218 |
free( psz_url ); |
|---|
| 219 |
free( psz_docid ); |
|---|
| 220 |
free( psz_title ); |
|---|
| 221 |
free( psz_description ); |
|---|
| 222 |
|
|---|
| 223 |
return 0; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
static int Control( demux_t *p_demux, int i_query, va_list args ) |
|---|
| 227 |
{ |
|---|
| 228 |
VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args); |
|---|
| 229 |
return VLC_EGENERIC; |
|---|
| 230 |
} |
|---|