Update to API v2
[webservice-strike.git] / lib / WebService / Strike / Torrent.pm
index 33d4b515f9f747759204d6ed9f9da3dfe565639a..1f0dae5e359b9c883dc31fba5738a4b43fc8ced5 100644 (file)
@@ -9,10 +9,9 @@ our $VERSION = '0.002';
 
 use Date::Parse qw/str2time/;
 use JSON::MaybeXS qw/decode_json/;
-use URI::Escape qw/uri_escape/;
 use WebService::Strike;
 
-__PACKAGE__->mk_ro_accessors(qw/torrent_hash torrent_title torrent_category sub_category seeds leeches file_count size upload_date uploader_username file_info file_names file_lengths/);
+__PACKAGE__->mk_ro_accessors(qw/torrent_hash torrent_title torrent_category sub_category seeds leeches file_count size upload_date uploader_username file_info file_names file_lengths magnet_uri/);
 
 BEGIN {
        *hash     = *torrent_hash;
@@ -23,6 +22,7 @@ BEGIN {
        *uploader = *uploader_username;
        *names    = *file_names;
        *lengths  = *file_lengths;
+       *magnet   = *magnet_uri;
 };
 
 sub new{
@@ -31,20 +31,15 @@ sub new{
        $self->{torrent_hash} = uc $self->hash;
        $self->{upload_date} = str2time $self->date, 'UTC';
        if ($self->file_info) {
-               $self->{file_names} = $self->file_info->[0]->{file_names};
-               $self->{file_lengths} = $self->file_info->[0]->{file_lengths};
+               $self->{file_names} = $self->file_info->{file_names};
+               $self->{file_lengths} = $self->file_info->{file_lengths};
        }
        $self
 }
 
-sub magnet{
-       my ($self) = @_;
-       'magnet:?xt=urn:btih:' . $self->hash . '&dn=' . uri_escape $self->title
-}
-
 sub torrent{
        my ($self, $file) = @_;
-       my $url = $WebService::Strike::BASE_URL . '/downloads/?hash=' . $self->hash;
+       my $url = $WebService::Strike::BASE_URL . '/download/?hash=' . $self->hash;
        my $ht = WebService::Strike::_ht(); ## no critic (ProtectPrivate)
        my $response = $ht->get($url);
        return unless $response->{success};
@@ -80,7 +75,7 @@ WebService::Strike::Torrent - Class representing information about a torrent
   say $t->seeds;
   say $t->leeches;
   say $t->count;            # 1
-  say $t->size;             # 587 MB
+  say $t->size;             # 615514112
   say $t->date;             # 1420502400
   say $t->uploader;         # The_Doctor-
   say @{$t->names};         # archlinux-2015.01.01-dual.iso
@@ -128,8 +123,7 @@ The number of files contained in the torrent.
 
 =item B<size>
 
-The total size of the files in the torrent as a human-readable string.
-See B<file_lengths> for exact sizes.
+The total size of the files in the torrent in bytes.
 
 =item B<date>, B<upload_date>
 
@@ -147,7 +141,7 @@ Arrayref of paths of files in the torrent.
 
 Arrayref of lengths of files in the torrent, in bytes.
 
-=item B<magnet>
+=item B<magnet>, B<magnet_uri>
 
 Magnet link for the torrent.
 
This page took 0.011525 seconds and 4 git commands to generate.