diff options
author | Seungwon Jeong <seungwon0@gmail.com> | 2012-07-03 23:51:13 +0900 |
---|---|---|
committer | Seungwon Jeong <seungwon0@gmail.com> | 2012-07-03 23:52:49 +0900 |
commit | baf03e18c256540d2a3869272c3cf9ec83c66ba4 (patch) | |
tree | bd73551f0b25055b34ef1aa01fae8e211ac6d941 | |
parent | d630a98d8a5b1b2186d1a5a42bf24291aa232487 (diff) | |
download | get-flash-videos-baf03e18c256540d2a3869272c3cf9ec83c66ba4.tar.gz |
[Daum] Fix Daum
-rw-r--r-- | lib/FlashVideo/Site/Daum.pm | 120 |
1 files changed, 55 insertions, 65 deletions
diff --git a/lib/FlashVideo/Site/Daum.pm b/lib/FlashVideo/Site/Daum.pm index 25fb5f4..2846ebc 100644 --- a/lib/FlashVideo/Site/Daum.pm +++ b/lib/FlashVideo/Site/Daum.pm @@ -10,15 +10,15 @@ sub find_video { # Step 1: Get video ID my $video_id = get_video_id($browser); - debug "Video ID: $video_id"; + debug "Video ID: ${video_id}"; # Step 2: Get video title my $video_title = get_video_title($browser, $video_id); - debug "Video title: $video_title"; + debug "Video title: ${video_title}"; # Step 3: Get video URL my $video_url = get_video_url($browser, $video_id); - debug "Video URL: $video_url"; + debug "Video URL: ${video_url}"; return $video_url, title_to_filename($video_title); } @@ -30,9 +30,9 @@ sub is_valid_video_id { return if !defined $video_id; - return if length $video_id != 12; + return if length $video_id != 12 && length $video_id != 23; - return if $video_id !~ /\$$/xms; + return if length $video_id == 12 && $video_id !~ /\$$/xms; return 1; } @@ -40,64 +40,47 @@ sub is_valid_video_id { sub get_video_id { my ($browser) = @_; - my $singer_url - = quotemeta 'http://media.daum.net/entertain/showcase/singer/'; - my $singer_url_pattern = qr{^ $singer_url .* [#] (\d+) $}xmsi; - if ( $browser->uri()->as_string() =~ $singer_url_pattern ) { - my $id = $1; - return get_video_id_for_singer($browser, $id); - } - # http://tvpot.daum.net/best/Top.do?from=gnb#clipid=31946003 - if ( $browser->uri()->as_string() =~ /[#] clipid = (\d+)/xmsi ) { + if ( $browser->uri()->as_string() =~ /[#?&] clipid = (\d+)/xmsi ) { my $url = 'http://tvpot.daum.net/clip/ClipView.do?clipid=' . $1; $browser->get($url); - if ( !$browser->success() ) { - die "Cannot fetch the document identified by the given URL: $url\n"; - } + die "Cannot fetch '${url}'\n" if !$browser->success(); } my $document = $browser->content(); # "http://flvs.daum.net/flvPlayer.swf?vid=FlVGvam5dPM$" my $flv_player_url = quotemeta 'http://flvs.daum.net/flvPlayer.swf'; - my $video_id_pattern_1 = qr{['"] $flv_player_url [?] vid = ([^'"&]+)}xmsi; + my $video_id_pattern_1 = qr{['"] ${flv_player_url} [?] vid = ([^'"&]+)}xmsi; - # Story.UI.PlayerManager.createViewer('2oHFG_aR9uA$'); - my $function_name = quotemeta 'Story.UI.PlayerManager.createViewer'; - my $video_id_pattern_2 = qr{$function_name [(] '(.+?)' [)]}xms; + my $func_name; - if ( $document !~ $video_id_pattern_1 - && $document !~ $video_id_pattern_2 ) - { - die "Cannot find video ID from the document.\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; -} + # Story.UI.PlayerManager.createViewer('2oHFG_aR9uA$'); + $func_name = quotemeta 'Story.UI.PlayerManager.createViewer'; + my $video_id_pattern_2 = qr{${func_name} [(] ' (.+?) ' [)]}xms; -sub get_video_id_for_singer { - my ($browser, $id) = @_; + # 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; - my $document = $browser->content(); + # controller/video/viewer/VideoView.html?vid=90-m2tl87zM$&play_loc=... + my $video_id_pattern_4 + = qr{/video/viewer/VideoView.html [?] vid = (.+?) &}xms; - # id:'16', vid:'HZYz4R8qUEU$' - my $video_id_pattern = qr{id:'$id', \s* vid:'(.+?)'}xms; - if ( $document !~ $video_id_pattern ) { - die "Cannot find video ID from the document.\n"; + 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); + die "Invalid video ID: ${video_id}\n" if !is_valid_video_id($video_id); return $video_id; } @@ -105,21 +88,15 @@ sub get_video_id_for_singer { sub get_video_title { my ($browser, $video_id) = @_; - my $query_url = "http://tvpot.daum.net/clip/ClipInfoXml.do?vid=$video_id"; - + my $query_url = "http://tvpot.daum.net/clip/ClipInfoXml.do?vid=${video_id}"; $browser->get($query_url); - if ( !$browser->success() ) { - die "Cannot fetch the document identified by the given URL: $query_url\n"; - } - + 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; - if ( $document !~ $video_title_pattern ) { - die "Cannot find video title from the document.\n"; - } + die "Cannot find video title.\n" if $document !~ $video_title_pattern; my $video_title = $1; # & => & @@ -132,23 +109,36 @@ sub get_video_url { my ($browser, $video_id) = @_; my $query_url - = 'http://stream.tvpot.daum.net/fms/pos_query2.php' - . '?service_id=1001&protocol=http&out_type=xml' - . "&s_idx=$video_id"; - + = 'http://videofarm.daum.net/controller/api/open/v1_2/' + . 'MovieLocation.apixml' + . "?vid=${video_id}&preset=main"; $browser->get($query_url); - if ( !$browser->success() ) { - die "Cannot fetch the document identified by the given URL: $query_url\n"; - } - + die "Cannot fetch '${query_url}'.\n" if !$browser->success(); my $document = $browser->content(); - # movieURL="http://stream.tvpot.daum.net/swxwT-/InNM6w/JgEM-E/OxDQ$$.flv" - my $video_url_pattern = qr{movieURL = "(.+?)"}xmsi; - if ( $document !~ $video_url_pattern ) { - die "Cannot find video URL from the document.\n"; + # <![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; } - my $video_url = $1; return $video_url; } |