age FlashVideo::JSON;
# Very simple JSON parser, loosely based on
# http://code.google.com/p/json-sans-eval
# Public domain.
use strict;
use base 'Exporter';
our @EXPORT = qw(from_json);
my $number
^\0-\x08\x0a-\x1f\"\\]|\\(?:["/\\bfnrt]|u[0-9A-Fa-f]{4}))};
my $string = qr{(?:"$oneChar*")};
my $jsonToken = qr{(?:false|true|null|[\{\}\[\]]|$number|$string)};
my $escapeSequence = qr{\\(?:([^u])|u(
'f' => "\f",
'n' => "\xA",
'r' => "\xD",
't' => "\t"
);
sub from_json {
my($in) = @_;
my @tokens = $in =~ /$jsonToken/go;
my $result = $tokens[0] eq '{' ? {} : [];
# Handle something
//www.wat.tv/interface/contentv2/$video_id");
my $title = json_unescape(($browser->content =~ /title":"(.*?)",/)[0]);
my $url = json_unescape(($browser->content =~ /files.*?url":"(.*?)",/)[0]);
ponse is a JSON data structure
return parse_video_info( $browser, $browser->content );
}
# The JSON video info hash has everything we need
sub parse_video_info {
my ( $browser, $json ) = @_;
debug "Video data: $json";
=begin
JSON structure:
{
"data": [
{
"tt": "0",
"ct": "f",
"cs": "2128",
"logo": "http:\/\/vimg8.yoqoo.com\/1100641F464A093EE7A01B01
( $json =~ /"seed":(\d+)/ );
die "Can't find the seed value in the video info JSON"
unless $shuffle_seed;
# Sometimes, the video has a HQ version in mp4 format
my ( $streams ) = ( $json =~
} else {
die "Unable to find download link";
}
# TODO - support subtitles. Available in JSON (urgh):
# http://www.ted.com/talks/subtitles/id/453/lang/eng
# The ID can be pulled out of
ion => '1.6.0.3');
my($content) = $browser->content =~ /content":\s*"(.*?)"\s*}/;
$content = json_unescape($content);
debug "Content is '$content'";
$browser->update_html($content);
}
sub tr
ite::Youtube;
use strict;
use Encode;
use HTML::Entities;
use FlashVideo::Utils;
use FlashVideo::JSON;
use URI::Escape;
my @formats = (
{ id => 38, resolution => [4096, 2304] },
{ id => 37, reso
p method from page ($1)";
return $self->download_fmt_map($prefs, $browser, $title, {}, @{from_json $1});
}
my $video_id;
if ($browser->content =~ /(?:var pageVideoId =|(?:CFG_)?VIDEO_ID'?\s
\s*(\{.*?\});/ && (my $swf = from_json($1))) {
$swf_url = $swf->{url};
} elsif($browser->content =~ /src=\\['"]([^'"]+\.swf)/) {
$swf_url = json_unescape($1);
} else {
$browser, $embed_url) = @_;
my $metadata = { };
my ($video_id, $player_id);
# URL params, JSON, etc..
$video_id = ($browser->content =~ /(?:clip|video)Id["'\] ]*[:=]["' ]*(\d+)/i)[0];
$pl
hash_data EXTENSIONS get_user_config_dir get_win_codepage
is_program_on_path get_terminal_width json_unescape
convert_sami_subtitles_to_srt from_xml);
sub debug(@) {
# Remove some sensitive dat
per JSON parser, but want to avoid the dependency for now..
# (There is now one in FlashVideo::JSON, so consider that -- this is just here
# until we have a chance to fix things using it).
sub json_un