X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FWWW%2FOffliberty.pm;h=01623629f69f49c9187ace2d33c85f0e98fdbfae;hb=121ecfa49ab23cf8c362d6b53dd6cf8c0f23fc89;hp=fc9c348d83c8cc53475f356af8677711b31ab934;hpb=de48830a28800ad0465048ce165b23a74a966265;p=www-offliberty.git diff --git a/lib/WWW/Offliberty.pm b/lib/WWW/Offliberty.pm index fc9c348..0162362 100644 --- a/lib/WWW/Offliberty.pm +++ b/lib/WWW/Offliberty.pm @@ -1,22 +1,25 @@ package WWW::Offliberty; -use 5.014; +use 5.008009; use strict; use warnings; use parent qw/Exporter/; -our $VERSION = '0.001'; +our $VERSION = '1.000002'; our @EXPORT_OK = qw/off/; +use constant OFF_URL => 'http://offliberty.com/off03.php'; + use HTML::TreeBuilder; -use LWP::UserAgent; +use HTTP::Tiny; -my $ua = LWP::UserAgent->new; +our $http = HTTP::Tiny->new(agent => "WWW-Offliberty/$VERSION ", default_headers => {Referer => 'http://offliberty.com/'}); sub off{ - my ($url, @params) = @_; - my $content = $ua->post("http://offliberty.com/off.php", {track => $url, @params})->decoded_content; - my $root = HTML::TreeBuilder->new_from_content($content); - map { $_->attr('href') } $root->look_down(qw/_tag a class download/); + my ($url, @params) = @_; + my $ret = $http->post_form(OFF_URL, {track => $url, @params}); + die $ret->{reason} unless $ret->{success}; ## no critic (RequireCarping) + my $root = HTML::TreeBuilder->new_from_content($ret->{content}); + map { $_->attr('href') } $root->look_down(qw/_tag a class download/); } 1; @@ -35,9 +38,20 @@ WWW::Offliberty - interface to offliberty.com download service WWW::Offliberty is a simple interface to the offliberty.com download service. -It exports a single function: B(I, [I => value...]). -This function that returns a list of download links, -as returned by the service. +The module exports (on request) a single function, B(I, +[I => value, ...]). It takes a URL and an optional list of +parameters (key/value pairs). It returns a list of download links. An +empty list is returned if the Offliberty service returns no URLs (for +example if Offliberty encounters an error or the URL is invalid). Dies +if unable to contact Offliberty (for example if there is no internet +connection or a firewall blocks the connection). + +The supported services and parameters are undocumented. From empirical +testing, when requesting a YouTube URL the service will return an +audio-only URL when called with no parameters, and two URLs +(audio-only and audio/video) when called with the parameter +B set to B<1>. In contrast, Vimeo URLs with no parameters +return both audio-only and audio/video variants. =head1 SEE ALSO @@ -49,7 +63,7 @@ Marius Gavrilescu, Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2013 by Marius Gavrilescu +Copyright (C) 2013-2015 by Marius Gavrilescu This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.1 or,