Skip to content

Commit

Permalink
Moved swfhash into FlashVideo::Utils so other Site modules can use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
zakflash committed May 23, 2009
1 parent 58a2d9a commit b8a9511
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 1 addition & 23 deletions FlashVideo/Site/Mtvnservices.pm
Expand Up @@ -5,8 +5,6 @@ use strict;
use FlashVideo::Utils;
use URI::Escape;

use constant FP_KEY => "Genuine Adobe Flash Player 001";

sub find_video {
my ($self, $browser, $embed_url) = @_;

Expand Down Expand Up @@ -81,33 +79,13 @@ sub handle_feed {
flv => $filename,
rtmp => $url,
pageUrl => $page_url,
$self->swfhash($browser, "http://media.mtvnservices.com/player/release/")
swfhash($browser, "http://media.mtvnservices.com/player/release/")
};
}

return $url, $filename;
}

sub swfhash {
my($self, $browser, $url) = @_;

die "Must have Compress::Zlib and Digest::SHA for Mtvnservices RTMP downloads\n"
unless eval {
require Compress::Zlib;
require Digest::SHA;
};

$browser->get($url);

my $data = "F" . substr($browser->content, 1, 7)
. Compress::Zlib::uncompress(substr $browser->content, 8);

return
swfsize => length $data,
swfhash => Digest::SHA::hmac_sha256_hex($data, FP_KEY),
swfUrl => $url;
}

sub can_handle {
my($self, $browser) = @_;

Expand Down
24 changes: 23 additions & 1 deletion FlashVideo/Utils.pm
Expand Up @@ -7,8 +7,10 @@ use HTML::Entities;
use HTML::TokeParser;
use Encode;

use constant FP_KEY => "Genuine Adobe Flash Player 001";

our @EXPORT = qw(extract_title extract_info title_to_filename get_video_filename
debug info error);
debug info error swfhash);

sub extract_title {
my($browser) = @_;
Expand Down Expand Up @@ -36,6 +38,26 @@ sub extract_info {
};
}

sub swfhash {
my($browser, $url) = @_;

die "Must have Compress::Zlib and Digest::SHA for this RTMP download\n"
unless eval {
require Compress::Zlib;
require Digest::SHA;
};

$browser->get($url);

my $data = "F" . substr($browser->content, 1, 7)
. Compress::Zlib::uncompress(substr $browser->content, 8);

return
swfsize => length $data,
swfhash => Digest::SHA::hmac_sha256_hex($data, FP_KEY),
swfUrl => $url;
}

sub title_to_filename {
my($title, $type) = @_;
$type ||= "flv";
Expand Down

0 comments on commit b8a9511

Please sign in to comment.