aboutsummaryrefslogtreecommitdiffstats
path: root/lib/WWW/FairViewer/Videos.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WWW/FairViewer/Videos.pm')
-rw-r--r--lib/WWW/FairViewer/Videos.pm105
1 files changed, 89 insertions, 16 deletions
diff --git a/lib/WWW/FairViewer/Videos.pm b/lib/WWW/FairViewer/Videos.pm
index 4acd866..72ad523 100644
--- a/lib/WWW/FairViewer/Videos.pm
+++ b/lib/WWW/FairViewer/Videos.pm
@@ -149,7 +149,7 @@ When C<$part> is C<undef>, it defaults to I<snippet>.
=cut
-sub video_details {
+sub _invidious_video_details {
my ($self, $id, $fields) = @_;
$fields //= $self->basic_video_info_fields;
@@ -159,24 +159,92 @@ sub video_details {
return $info;
}
+ return;
+}
+
+sub _ytdl_video_details {
+ my ($self, $id) = @_;
+ $self->_info_from_ytdl($id);
+}
+
+sub _fallback_video_details {
+ my ($self, $id, $fields) = @_;
+
+ if ($self->get_debug) {
+ say STDERR ":: Extracting video info with hypervideo...";
+ }
+
+ my $info = $self->_ytdl_video_details($id);
+
+ if (defined($info) and ref($info) eq 'HASH') {
+ return scalar {
+
+ title => $info->{fulltitle} // $info->{title},
+ videoId => $id,
+
+ videoThumbnails => [
+ map {
+ scalar {
+ quality => 'medium',
+ url => $_->{url},
+ width => $_->{width},
+ height => $_->{height},
+ }
+ } @{$info->{thumbnails}}
+ ],
+
+ liveNow => ($info->{is_live} ? 1 : 0),
+ description => $info->{description},
+ lengthSeconds => $info->{duration},
+
+ likeCount => $info->{like_count},
+ dislikeCount => $info->{dislike_count},
+
+ category => eval { $info->{categories}[0] } // $info->{category},
+ publishDate => $info->{upload_date},
+
+ keywords => $info->{tags},
+ viewCount => $info->{view_count},
+
+ author => $info->{channel},
+ authorId => $info->{channel_id} // $info->{uploader_id},
+ rating => $info->{average_rating},
+ };
+ }
+ else {
+ #$info = $self->_invidious_video_details($id, $fields); # too slow
+ }
+
+ return {};
+}
+
+sub video_details {
+ my ($self, $id, $fields) = @_;
+
if ($self->get_debug) {
say STDERR ":: Extracting video info using the fallback method...";
}
- # Fallback using the `get_video_info` URL
my %video_info = $self->_get_video_info($id);
- my $video = $self->parse_json_string($video_info{player_response} // return);
+ my $video = $self->parse_json_string($video_info{player_response} // return $self->_fallback_video_details($id, $fields));
+
+ my $videoDetails = {};
+ my $microformat = {};
if (exists $video->{videoDetails}) {
- $video = $video->{videoDetails};
+ $videoDetails = $video->{videoDetails};
}
else {
- return;
+ return $self->_fallback_video_details($id, $fields);
+ }
+
+ if (exists $video->{microformat}) {
+ $microformat = eval { $video->{microformat}{playerMicroformatRenderer} } // {};
}
my %details = (
- title => $video->{title},
- videoId => $video->{videoId},
+ title => eval { $microformat->{title}{simpleText} } // $videoDetails->{title},
+ videoId => $videoDetails->{videoId},
videoThumbnails => [
map {
@@ -186,19 +254,22 @@ sub video_details {
width => $_->{width},
height => $_->{height},
}
- } @{$video->{thumbnail}{thumbnails}}
+ } @{$videoDetails->{thumbnail}{thumbnails}}
],
- liveNow => $video->{isLiveContent},
- description => $video->{shortDescription},
- lengthSeconds => $video->{lengthSeconds},
+ liveNow => ($videoDetails->{isLiveContent} || (($videoDetails->{lengthSeconds} || 0) == 0)),
+ description => eval { $microformat->{description}{simpleText} } // $videoDetails->{shortDescription},
+ lengthSeconds => $videoDetails->{lengthSeconds} // $microformat->{lengthSeconds},
- keywords => $video->{keywords},
- viewCount => $video->{viewCount},
+ category => $microformat->{category},
+ publishDate => $microformat->{publishDate},
- author => $video->{author},
- authorId => $video->{channelId},
- rating => $video->{averageRating},
+ keywords => $videoDetails->{keywords},
+ viewCount => $videoDetails->{viewCount} // $microformat->{viewCount},
+
+ author => $videoDetails->{author} // $microformat->{ownerChannelName},
+ authorId => $videoDetails->{channelId} // $microformat->{externalChannelId},
+ rating => $videoDetails->{averageRating},
);
return \%details;
@@ -218,6 +289,8 @@ with a HASH ref for each result. An example of the item array's content are show
=head1 AUTHOR
+Trizen, C<< <echo dHJpemVuQHByb3Rvbm1haWwuY29tCg== | base64 -d> >>
+
Jesus, C<< <echo aGVja3llbEBoeXBlcmJvbGEuaW5mbw== | base64 -d> >>