Skip to content

Commit

Permalink
gtk3: added support for saving videos inside local playlists.
Browse files Browse the repository at this point in the history
Via the right-click "Add to" menu.

gtk3: added the "Reverse playlist entries" option in the "Playlists" tab.

When enabled, it displays a local playlist in reverse order.
  • Loading branch information
trizen committed Mar 5, 2021
1 parent 4d9d31f commit 48d07f6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
50 changes: 50 additions & 0 deletions bin/gtk-youtube-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,37 @@ sub menu_popup {
}
}

if ($type eq 'video') {

# Separator
{
my $item = 'Gtk3::SeparatorMenuItem'->new;
$item->show;
$menu->append($item);
}

# Add-to submenu
{
my $add_to = 'Gtk3::Menu'->new;
my $cat = 'Gtk3::ImageMenuItem'->new("Add to");
$cat->set_image('Gtk3::Image'->new_from_icon_name("add", q{menu}));
$cat->show;

foreach my $filename ($yv_utils->get_local_playlist_filenames($local_playlists_dir)) {
my $playlist = $yv_utils->local_playlist_snippet($filename);
my $item = 'Gtk3::ImageMenuItem'->new($yv_utils->get_title($playlist));
$item->signal_connect(activate => sub { save_video_to_file($filename) });
$item->set_property(tooltip_text => "Save video to playlist");
$item->set_image('Gtk3::Image'->new_from_icon_name("list", q{menu}));
$item->show;
$add_to->append($item);
}

$cat->set_submenu($add_to);
$menu->append($cat);
}
}

if ($type eq 'video' or $type eq 'playlist') {

# Separator
Expand Down Expand Up @@ -2491,6 +2522,21 @@ sub decode_entities {
return $text;
}

sub save_video_to_file {
my ($filename) = @_;

my $video_id = get_selected_entry_code(type => 'video') // return;

open(my $fh, '>>', $filename) or do {
warn "[!] Can't open file <<$filename>> for appending: $!";
return;
};

say {$fh} $video_id;

close $fh;
}

sub get_code {
my ($code, $iter) = get_selected_entry_code();

Expand Down Expand Up @@ -3501,6 +3547,10 @@ sub list_local_playlist {
@video_ids = reverse(@video_ids);
}

if ($gui->get_object('reverse_playlist')->get_active) {
@video_ids = reverse(@video_ids);
}

$liststore->clear if $CONFIG{clear_search_list};
display_results(get_results_from_list(ids => \@video_ids));
}
Expand Down
14 changes: 14 additions & 0 deletions share/gtk3-youtube-viewer.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,20 @@ When the specified resolution is not found, the best available resolution is use
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="reverse_playlist">
<property name="label" translatable="yes">Reverse playlist entries</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down

0 comments on commit 48d07f6

Please sign in to comment.