/usr/share/perl5/FlashVideo/Site/Daum.pm is in get-flash-videos 1.25~git2014.03.23-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 52 53 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | # Part of get-flash-videos. See get_flash_videos for copyright.
package FlashVideo::Site::Daum;
use strict;
use FlashVideo::Utils;
use HTML::Entities qw(decode_entities);
sub find_video {
my ($self, $browser) = @_;
# Step 1: Get video ID
my $video_id = get_video_id($browser);
debug "Video ID: $video_id";
# Step 2: Get video title
my $video_title = get_video_title($browser, $video_id);
debug "Video title: $video_title";
# Step 3: Get video URL
my $video_url = get_video_url($browser, $video_id);
debug "Video URL: $video_url";
# Step 4: Get video type
my $video_type = ( $video_url =~ /[.]mp4/xms ) ? 'mp4' : 'flv';
return $video_url, title_to_filename($video_title, $video_type);
}
# Internal subroutines
sub is_valid_video_id {
my ($video_id) = @_;
return if !defined $video_id;
return if length $video_id != 12 && length $video_id != 23;
return if length $video_id == 12 && $video_id !~ /\$$/xms;
return 1;
}
sub get_video_id {
my ($browser) = @_;
# http://tvpot.daum.net/best/Top.do?from=gnb#clipid=31946003
if ( $browser->uri()->as_string() =~ /[#?&] clipid = (\d+)/xmsi ) {
my $url = 'http://tvpot.daum.net/clip/ClipView.do?clipid=' . $1;
$browser->get($url);
die "Cannot fetch '$url'\n" if !$browser->success();
}
if ($browser->response->is_redirect()) {
my $url = $browser->response->header('Location');
$browser->get($url);
die "Cannot fetch '$url'\n" if !$browser->success();
}
my $document = $browser->content();
# VodPlayer.swf?vid=3i5f_JquGsk$
my $video_id_pattern_1 = qr{VodPlayer[.]swf [?] vid = (.+?) ["'&]}xmsi;
my $func_name;
# Story.UI.PlayerManager.createViewer('2oHFG_aR9uA$');
$func_name = quotemeta 'Story.UI.PlayerManager.createViewer';
my $video_id_pattern_2 = qr{$func_name [(] ' (.+?) '}xms;
# daum.Music.VideoPlayer.add("body_mv_player", "_nACjJ65nKg$",
$func_name = quotemeta 'daum.Music.VideoPlayer.add';
my $video_id_pattern_3
= qr{$func_name [(] "body_mv_player", \s* " (.+?) " ,}xms;
# controller/video/viewer/VideoView.html?vid=90-m2tl87zM$&play_loc=...
my $video_id_pattern_4
= qr{/video/viewer/VideoView.html [?] vid = (.+?) &}xmsi;
if ( $document !~ $video_id_pattern_1
&& $document !~ $video_id_pattern_2
&& $document !~ $video_id_pattern_3
&& $document !~ $video_id_pattern_4 )
{
die "Cannot find video ID.\n";
}
my $video_id = $1;
# Remove white spaces in video ID.
$video_id =~ s/\s+//xmsg;
die "Invalid video ID: $video_id\n" if !is_valid_video_id($video_id);
return $video_id;
}
sub get_video_title {
my ($browser, $video_id) = @_;
my $query_url = "http://tvpot.daum.net/clip/ClipInfoXml.do?vid=$video_id";
$browser->get($query_url);
die "Cannot fetch '$query_url'.\n" if !$browser->success();
my $document = $browser->content();
# <TITLE><![CDATA[Just The Way You Are]]></TITLE>
my $video_title_pattern
= qr{<TITLE> <!\[CDATA \[ (.+?) \] \]> </TITLE>}xmsi;
die "Cannot find video title.\n" if $document !~ $video_title_pattern;
my $video_title = $1;
# & => &
$video_title = decode_entities($video_title);
return $video_title;
}
sub get_video_url {
my ($browser, $video_id) = @_;
my $query_url
= 'http://videofarm.daum.net/controller/api/open/v1_2/'
. 'MovieLocation.apixml'
. "?vid=$video_id&preset=main";
$browser->get($query_url);
die "Cannot fetch '$query_url'.\n" if !$browser->success();
my $document = $browser->content();
# <![CDATA[
# http://cdn.flvs.daum.net/fms/pos_query2.php?service_id=1001&protocol=...
# ]]>
my $url_pattern = qr{<!\[CDATA\[ \s* (.+?) \s* \]\]>}xmsi;
die "Cannot find URL.\n" if $document !~ $url_pattern;
my $url = $1;
my $video_url;
# http://cdn.flvs.daum.net/fms/pos_query2.php?service_id=1001&protocol=...
if ( $url =~ /pos_query2[.]php/xms ) {
$browser->get($url);
die "Cannot fetch '$url'.\n" if !$browser->success();
$document = $browser->content();
# movieURL="http://stream.tvpot.daum.net/swxwT-/InNM6w/JgEM-E/..."
my $video_url_pattern = qr{movieURL = " (.+?) "}xmsi;
die "Cannot find video URL.\n" if $document !~ $video_url_pattern;
$video_url = $1;
}
else {
$video_url = $url;
}
return $video_url;
}
1;
|