diff options
author | zakflash <zakflashvideo@gmail.com> | 2012-07-10 12:50:21 -0700 |
---|---|---|
committer | zakflash <zakflashvideo@gmail.com> | 2012-07-10 12:50:21 -0700 |
commit | e848051e82064ae115cfbd032afbf0c9de392534 (patch) | |
tree | 9ec03cef7db144308877df432b637290de285c94 | |
parent | d630a98d8a5b1b2186d1a5a42bf24291aa232487 (diff) | |
parent | 8c230643e3158cb49eda4ec57d94b30cc139ea39 (diff) | |
download | get-flash-videos-e848051e82064ae115cfbd032afbf0c9de392534.tar.gz |
Merge pull request #71 from seungwon0/daum
Fix broken Daum plugin
-rw-r--r-- | lib/FlashVideo/Site/Daum.pm | 116 |
1 files changed, 57 insertions, 59 deletions
diff --git a/lib/FlashVideo/Site/Daum.pm b/lib/FlashVideo/Site/Daum.pm index 25fb5f4..7b10c6e 100644 --- a/lib/FlashVideo/Site/Daum.pm +++ b/lib/FlashVideo/Site/Daum.pm @@ -20,7 +20,10 @@ sub find_video { my $video_url = get_video_url($browser, $video_id); debug "Video URL: $video_url"; - return $video_url, title_to_filename($video_title); + # 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 @@ -30,9 +33,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,21 +43,11 @@ 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(); @@ -63,34 +56,32 @@ sub get_video_id { my $flv_player_url = quotemeta 'http://flvs.daum.net/flvPlayer.swf'; 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; + # Story.UI.PlayerManager.createViewer('2oHFG_aR9uA$'); + $func_name = quotemeta 'Story.UI.PlayerManager.createViewer'; + my $video_id_pattern_2 = qr{$func_name [(] ' (.+?) ' [)]}xms; - # Remove white spaces in video ID. - $video_id =~ s/\s+//xmsg; + # 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; - die "Invalid video ID: $video_id\n" if !is_valid_video_id($video_id); + # controller/video/viewer/VideoView.html?vid=90-m2tl87zM$&play_loc=... + my $video_id_pattern_4 + = qr{/video/viewer/VideoView.html [?] vid = (.+?) &}xms; - return $video_id; -} + # DaumVodPlayer.swf?vid=vd247EUCULRUVVUQSVytEDS&... + my $video_id_pattern_5 + = qr{DaumVodPlayer[.]swf [?] vid = (.+?) &}xmsi; -sub get_video_id_for_singer { - my ($browser, $id) = @_; - - my $document = $browser->content(); - - # 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 + && $document !~ $video_id_pattern_5 ) + { + die "Cannot find video ID.\n"; } my $video_id = $1; @@ -106,20 +97,14 @@ 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); - 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 +117,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; } |