aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/gtk-straw-viewer43
-rwxr-xr-xbin/straw-viewer21
-rw-r--r--lib/WWW/StrawViewer.pm9
-rw-r--r--lib/WWW/StrawViewer/Channels.pm5
-rw-r--r--lib/WWW/StrawViewer/PlaylistItems.pm27
-rw-r--r--lib/WWW/StrawViewer/Utils.pm25
6 files changed, 78 insertions, 52 deletions
diff --git a/bin/gtk-straw-viewer b/bin/gtk-straw-viewer
index 870b654..821f202 100755
--- a/bin/gtk-straw-viewer
+++ b/bin/gtk-straw-viewer
@@ -2523,6 +2523,10 @@ sub display_results {
use Data::Dump qw(pp);
pp $items;
+ if (ref($items) eq 'HASH' and $items->{type} eq 'playlist') {
+ $items = $items->{videos};
+ }
+
hide_feeds_window();
#~ if (not $from_history) {
@@ -2596,7 +2600,7 @@ sub display_results {
if ($yv_utils->is_playlist($item)) {
- my $playlist_id = $yv_utils->get_playlist_id($item) || next;
+ #~ my $playlist_id = $yv_utils->get_playlist_id($item) || next;
#~ if (exists($info->{__extra_info__}{$playlist_id})) {
#~ @{$item}{qw(contentDetails)} =
@@ -2613,7 +2617,7 @@ sub display_results {
}
elsif ($yv_utils->is_video($item)) {
- my $video_id = $yv_utils->get_video_id($item) || next;
+ #~ my $video_id = $yv_utils->get_video_id($item) || next;
#~ if (exists($info->{__extra_info__}{$video_id})) {
#~ @{$item}{qw(id contentDetails statistics snippet)} =
@@ -2773,7 +2777,7 @@ sub add_channel_entry {
my ($channel) = @_;
my $iter = $liststore->append;
- my $title = $yv_utils->get_title($channel);
+ my $title = $yv_utils->get_channel_title($channel);
my $channel_id = $yv_utils->get_channel_id($channel);
my $description = $yv_utils->get_description($channel);
my $row_description = make_row_description($description);
@@ -2840,8 +2844,8 @@ sub add_playlist_entry {
my $num_items_template = "<b>$symbols{numero}</b> %d items\n";
my $num_items_text = "";
- if (defined($playlist->{contentDetails}{itemCount})) {
- $num_items_text = sprintf($num_items_template, $playlist->{contentDetails}->{itemCount});
+ if (defined($playlist->{videoCount})) {
+ $num_items_text = sprintf($num_items_template, $playlist->{videoCount});
}
my $type_label = reflow_text("<b>$symbols{diamond}</b> " . 'Playlist' . "\n" . $num_items_text);
@@ -2865,6 +2869,7 @@ sub list_playlist {
my ($playlist_id) = @_;
my $results = $yv_obj->videos_from_playlist_id($playlist_id);
+
if ($yv_utils->has_entries($results)) {
$liststore->clear if $CONFIG{clear_search_list};
display_results($results);
@@ -3575,37 +3580,39 @@ sub set_entry_details {
my $info = $yv_obj->parse_json_string($liststore->get($iter, 8));
+ my %thumbs = (
+ start => 1,
+ middle => 2,
+ end => 3,
+ );
+
# Getting thumbs
- foreach my $nr (qw(1 2 3)) {
+ foreach my $type (keys %thumbs) {
- $gui->get_object("image$nr")->set_from_pixbuf($default_thumb);
+ $gui->get_object("image$thumbs{$type}")->set_from_pixbuf($default_thumb);
Glib::Idle->add(
sub {
- my ($nr) = @{$_[0]};
+ my ($type) = @{$_[0]};
- if ($code =~ /$valid_video_id_re/) {
+ my $url = $yv_utils->get_thumbnail_url($info, $type);
- my $thumbnail = $info->{snippet}{thumbnails}{medium};
- my $url = $thumbnail->{url};
+ #~ my $thumbnail = $info->{snippet}{thumbnails}{medium};
+ #~ my $url = $thumbnail->{url};
if ($url =~ /_live\.\w+\z/) {
## no extra thumbnails available while video is LIVE
}
else {
- $url =~ s{/\w+\.(\w+)\z}{/mq$nr.$1};
+ $url =~ s{/\w+\.(\w+)\z}{/mq$thumbs{$type}.$1};
}
my $pixbuf = get_pixbuf_thumbnail_from_url($url, 160, 90);
- $gui->get_object("image$nr")->set_from_pixbuf($pixbuf);
- }
- else {
- $gui->get_object("image$nr")->set_from_pixbuf($default_thumb);
- }
+ $gui->get_object("image$thumbs{$type}")->set_from_pixbuf($pixbuf);
return 0;
},
- [$nr],
+ [$type],
Glib::G_PRIORITY_DEFAULT_IDLE
);
}
diff --git a/bin/straw-viewer b/bin/straw-viewer
index ef3b6f2..fbd0829 100755
--- a/bin/straw-viewer
+++ b/bin/straw-viewer
@@ -2570,8 +2570,7 @@ sub print_channels {
}
my $url = $results->{url};
- my $info = $results->{results} // {};
- my $channels = $info->{items} // [];
+ my $channels = $results->{results} // [];
foreach my $i (0 .. $#{$channels}) {
my $channel = $channels->[$i];
@@ -2579,7 +2578,7 @@ sub print_channels {
if ($opt{results_with_details}) {
printf(
"\n%s. %s\n %s: %-23s %s: %-12s\n%s\n",
- colored(sprintf('%2d', $i + 1), 'bold') => colored($yv_utils->get_title($channel), 'bold blue'),
+ colored(sprintf('%2d', $i + 1), 'bold') => colored($yv_utils->get_channel_title($channel), 'bold blue'),
colored('Updated' => 'bold') => $yv_utils->get_publication_date($channel),
colored('Author' => 'bold') => $yv_utils->get_channel_title($channel),
wrap_text(
@@ -2593,7 +2592,7 @@ sub print_channels {
print "\n" if $i == 0;
printf("%s. %s (%s)\n",
colored(sprintf('%2d', $i + 1), 'bold'),
- colored($yv_utils->get_title($channel), 'blue'),
+ colored($yv_utils->get_channel_title($channel), 'blue'),
colored($yv_utils->get_publication_date($channel), 'magenta'),
);
}
@@ -2612,7 +2611,7 @@ sub print_channels {
foreach my $i (0 .. $#{$channels}) {
my $channel = $channels->[$i];
- my $title = clear_title($yv_utils->get_title($channel));
+ my $title = clear_title($yv_utils->get_channel_title($channel));
printf "%s. %s %s [%*s]\n", colored(sprintf('%2d', $i + 1), 'bold'),
adjust_width($title, $title_length),
@@ -2642,7 +2641,7 @@ sub print_channels {
sub => __SUB__,
url => $url,
res => $channels,
- info => $info,
+ info => $results,
)
) {
## ok
@@ -2872,8 +2871,7 @@ sub print_playlists {
}
my $url = $results->{url};
- my $info = $results->{results} // {};
- my $playlists = $info->{items} // [];
+ my $playlists = $results->{results} // [];
state $info_format = <<"FORMAT";
@@ -2965,7 +2963,7 @@ FORMAT
sub => __SUB__,
url => $url,
res => $playlists,
- info => $info,
+ info => $results,
mode => 'playlists',
)
) {
@@ -3637,6 +3635,11 @@ sub print_videos {
my $url = $results->{url};
my $videos = $results->{results} // [];
+
+ if (ref($videos) eq 'HASH' and exists $videos->{videos}) {
+ $videos = $videos->{videos};
+ }
+
#my $videos = $info->{items} // [];
#~ foreach my $entry (@$videos) {
diff --git a/lib/WWW/StrawViewer.pm b/lib/WWW/StrawViewer.pm
index ecd31c9..336811e 100644
--- a/lib/WWW/StrawViewer.pm
+++ b/lib/WWW/StrawViewer.pm
@@ -485,7 +485,14 @@ sub default_arguments {
sub _make_feed_url {
my ($self, $path, %args) = @_;
- $self->get_feeds_url() . $path . '?' . $self->default_arguments(%args);
+ my $extra_args = $self->default_arguments(%args);
+ my $url = $self->get_feeds_url() . $path;
+
+ if ($extra_args) {
+ $url .= '?' . $extra_args;
+ }
+
+ return $url;
}
sub _extract_from_invidious {
diff --git a/lib/WWW/StrawViewer/Channels.pm b/lib/WWW/StrawViewer/Channels.pm
index d48c744..309aa07 100644
--- a/lib/WWW/StrawViewer/Channels.pm
+++ b/lib/WWW/StrawViewer/Channels.pm
@@ -23,6 +23,11 @@ sub _make_channels_url {
return $self->_make_feed_url('channels', %opts);
}
+sub videos_from_channel_id {
+ my ($self, $channel_id) = @_;
+ return $self->_get_results($self->_make_feed_url("channels/$channel_id/videos"));
+}
+
=head2 channels_from_categoryID($category_id)
Return the YouTube channels associated with the specified category.
diff --git a/lib/WWW/StrawViewer/PlaylistItems.pm b/lib/WWW/StrawViewer/PlaylistItems.pm
index 046e065..ab41a0d 100644
--- a/lib/WWW/StrawViewer/PlaylistItems.pm
+++ b/lib/WWW/StrawViewer/PlaylistItems.pm
@@ -80,18 +80,7 @@ Get videos from a specific playlistID.
sub videos_from_playlist_id {
my ($self, $id) = @_;
- return $self->_get_results($self->_make_playlistItems_url(playlistId => $id, part => 'contentDetails,snippet'));
-}
-
-=head2 videos_from_id($playlist_id)
-
-Get videos from a specific playlistID.
-
-=cut
-
-sub playlists_from_id {
- my ($self, $id) = @_;
- return $self->_get_results($self->_make_playlistItems_url(id => $id));
+ $self->_get_results($self->_make_feed_url("playlists/$id"));
}
=head2 favorites($channel_id)
@@ -120,22 +109,12 @@ Get the favorites, uploads and likes for a given YouTube username.
*{__PACKAGE__ . '::' . $name . '_from_username'} = sub {
my ($self, $username) = @_;
- my $playlist_id = $self->get_playlist_id(
- $name, $username
- ? (forUsername => $username)
- : do { $self->get_access_token() // return; (mine => 'true') }
- ) // return;
- $self->videos_from_playlist_id($playlist_id);
+ $self->videos_from_username($username);
};
*{__PACKAGE__ . '::' . $name} = sub {
my ($self, $channel_id) = @_;
- my $playlist_id = $self->get_playlist_id(
- $name, ($channel_id and $channel_id ne 'mine')
- ? (id => $channel_id)
- : do { $self->get_access_token() // return; (mine => 'true') }
- ) // return;
- $self->videos_from_playlist_id($playlist_id);
+ $self->videos_from_channel_id($channel_id);
};
}
}
diff --git a/lib/WWW/StrawViewer/Utils.pm b/lib/WWW/StrawViewer/Utils.pm
index f3855b8..87a7ac0 100644
--- a/lib/WWW/StrawViewer/Utils.pm
+++ b/lib/WWW/StrawViewer/Utils.pm
@@ -221,6 +221,11 @@ Returns true if a given result has entries.
sub has_entries {
my ($self, $result) = @_;
+
+ if (ref($result->{results}) eq 'HASH' and $result->{results}{type} eq 'playlist') {
+ return $result->{results}{videoCount} > 0;
+ }
+
scalar(@{$result->{results}}) > 0;
#ref($result) eq 'HASH' and ($result->{results}{pageInfo}{totalResults} > 0);
}
@@ -450,6 +455,22 @@ Get thumbnail URL.
sub get_thumbnail_url {
my ($self, $info, $type) = @_;
+
+ if (exists $info->{videoId}) {
+ $info->{type} = 'video';
+ }
+
+ if ($info->{type} eq 'playlist') {
+ return $info->{playlistThumbnail};
+ }
+
+ if ($info->{type} eq 'channel') {
+ ref($info->{authorThumbnails}) eq 'ARRAY' or return '';
+ return $info->{authorThumbnails}[0]{url};
+ }
+
+ ref($info->{videoThumbnails}) eq 'ARRAY' or return '';
+
my @thumbs = @{$info->{videoThumbnails}};
my @wanted = grep{$_->{quality} eq $type} @thumbs;
@@ -655,6 +676,10 @@ sub get_comments {
*{__PACKAGE__ . '::' . 'is_' . $pair->[0]} = sub {
my ($self, $item) = @_;
+ if ($pair->[0] eq 'video') {
+ return 1 if exists $item->{videoId};
+ }
+
exists $pair->[1]{$item->{type} // ''};
#~ if (ref($item->{id}) eq 'HASH') {