Skip to content

Commit

Permalink
** Added support for saving videos to a selected playlist with stdin …
Browse files Browse the repository at this point in the history
…options: "ps" (playlist save) or "s2p" (save to playlist).

** Added the '--pos' option to specifiy an optional position where to save the video in the playlist. (default: 1)
  • Loading branch information
Trizen committed Feb 1, 2015
1 parent 265c2de commit 38f25fa
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 19 deletions.
2 changes: 1 addition & 1 deletion WWW-YoutubeViewer/META.json
Expand Up @@ -4,7 +4,7 @@
"Daniel \"Trizen\" Șuteu <trizenx@gmail.com>"
],
"dynamic_config" : 1,
"generated_by" : "Module::Build version 0.421",
"generated_by" : "Module::Build version 0.4211",
"license" : [
"perl_5"
],
Expand Down
2 changes: 1 addition & 1 deletion WWW-YoutubeViewer/META.yml
Expand Up @@ -7,7 +7,7 @@ build_requires:
configure_requires:
Module::Build: '0'
dynamic_config: 1
generated_by: 'Module::Build version 0.421, CPAN::Meta::Converter version 2.142060'
generated_by: 'Module::Build version 0.4211, CPAN::Meta::Converter version 2.143240'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
Expand Down
30 changes: 15 additions & 15 deletions WWW-YoutubeViewer/Makefile.PL
@@ -1,27 +1,27 @@
# Note: this file was auto-generated by Module::Build::Compat version 0.4210
# Note: this file was auto-generated by Module::Build::Compat version 0.4211
use ExtUtils::MakeMaker;
WriteMakefile
(
'PL_FILES' => {},
'INSTALLDIRS' => 'site',
'EXE_FILES' => [
'bin/youtube-viewer'
],
'NAME' => 'WWW::YoutubeViewer',
'VERSION_FROM' => 'lib/WWW/YoutubeViewer.pm',
'PREREQ_PM' => {
'LWP::UserAgent' => 0,
'Text::ParseWords' => 0,
'Data::Dump' => 0,
'File::Path' => 0,
'File::Spec::Functions' => 0,
'Test::More' => 0,
'Getopt::Long' => 0,
'HTTP::Request' => 0,
'Data::Dump' => 0,
'Text::Wrap' => 0,
'LWP::UserAgent' => 0,
'Term::ANSIColor' => 0,
'Term::ReadLine' => 0,
'URI::Escape' => 0,
'File::Path' => 0
'Test::More' => 0,
'Text::ParseWords' => 0,
'Text::Wrap' => 0,
'URI::Escape' => 0
},
'VERSION_FROM' => 'lib/WWW/YoutubeViewer.pm',
'NAME' => 'WWW::YoutubeViewer'
'INSTALLDIRS' => 'site',
'EXE_FILES' => [
'bin/youtube-viewer'
],
'PL_FILES' => {}
)
;
1 change: 1 addition & 0 deletions WWW-YoutubeViewer/bin/gtk-youtube-viewer
Expand Up @@ -361,6 +361,7 @@ local $SIG{__DIE__} = sub {
if ($error =~ m{^Can't locate (.+?)\.pm\b}) {
my $module = $1;
$module =~ s{[/\\]+}{::}g;
return 1 if $module eq 'XML::Fast';
"\nThe module $module is required!\n\nTo install the module, just type in terminal:\n\tsudo cpan $module\n";
}
}
Expand Down
35 changes: 33 additions & 2 deletions WWW-YoutubeViewer/bin/youtube-viewer
Expand Up @@ -18,14 +18,15 @@
#-------------------------------------------------------
# Appname: youtube-viewer
# Created on: 02 June 2010
# Latest edit on: 06 January 2015
# Latest edit on: 01 February 2015
# Websites: http://trizen.googlecode.com
# https://github.com/trizen/youtube-viewer
#-------------------------------------------------------
#
# youtube-viewer is a command line utility for viewing youtube-videos in MPlayer.
#
# [CHANGELOG]
# - Added the stdin commands ":ps" and "s2p" to add one or more videos to a selected playlist - NEW (v3.1.2)
# - Added the `--std-input=s` option which can be used to specify the first standard input - NEW (v3.1.1)
# - Added input history support across sessions, with the 'save_input_history' config-key - NEW (v3.1.1)
# - Added support for more video players (--player=s) // Added support for shows (--us=author) - NEW (v3.1.0)
Expand Down Expand Up @@ -86,8 +87,10 @@
# - gotbletu (for the great video review of youtube-viewer: http://www.youtube.com/watch?v=FnJ67oAxVQ4)
# - Julian Ospald (for adding youtube-viewer in the gentoo portage tree: http://packages.gentoo.org/package/net-misc/youtube-viewer)
# - 666philb (for packaging gtk-youtube-viewer for Puppy Linux: http://www.murga-linux.com/puppy/viewtopic.php?t=76835)
# - Kevin Lemonnier (for adding proxy support - https://github.com/Ulrar)
# - Kevin Lemonnier (for adding proxy support - https://github.com/trizen/youtube-viewer/pull/18)
# - Georgo (for adding the 'Watch Later' feature - https://github.com/trizen/youtube-viewer/pull/44)
# - Daniel Wallace (for adding youtube-viewer in the Arch Official Community repository - https://www.archlinux.org/packages/community/any/youtube-viewer/)
# - NTmatter (for adding reverse range support - https://github.com/trizen/youtube-viewer/pull/2)

=head1 NAME
Expand Down Expand Up @@ -542,6 +545,7 @@ usage: $execname [options] ([url] | [keywords])
--playlist=s : list a playlist of videos by playlistID
--pp=s,s : play the videos from the given playlist IDs
--disco : YouTube discovery - search and display a disco playlist
--pos=i : the position in a playlist where to add a video
-up --user-pl=s : list the playlists created by a specific user
* Channels
Expand Down Expand Up @@ -1305,6 +1309,7 @@ sub parse_arguments {
'gdata-url=s' => \$opt{get_gdata_url},
'gcap=s' => \$opt{gcap},
'combine-multiple-videos|combine!' => \$opt{combine_multiple_videos},
'pos|position' => \$opt{position},

'quiet|q!' => \$opt{quiet},
'really-quiet!' => \$opt{really_quiet},
Expand Down Expand Up @@ -2862,6 +2867,9 @@ FORMAT
given ($key) {
when (\&youtube_urls) { } # do nothing
when (valid_num($_, $playlists) and not $contains_keywords) {
if ($args{return_playlist_id}) {
return $playlists->[$_ - 1]{playlistID};
}
get_and_print_videos_from_playlist($playlists->[$_ - 1]{playlistID});
}
default {
Expand Down Expand Up @@ -3411,6 +3419,29 @@ sub print_videos {
warn_no_thing_selected('video');
}
}
when (/^(?:ps|s2p)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$videos}, $1)) {

my $request = $yv_obj->get_playlists_from_username('default') // last;
my $playlist_id = print_playlists($request, return_playlist_id => 1);

if (defined($playlist_id)) {
foreach my $i (@nums) {
say "** Adding video `$videos->[$i]{title}' to the playlist selected...";
$yv_obj->add_video_to_playlist($playlist_id, $videos->[$i]{videoID}, $opt{position} || 1)
|| do {
warn "[!] An error occurred!!!\n";
};
}
}
else {
warn_no_thing_selected('playlist');
}
}
else {
warn_no_thing_selected('video');
}
}
when (/^(?:p(?:laylists?)?|up)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$videos}, $1)) {
foreach my $id (@nums) {
Expand Down
30 changes: 30 additions & 0 deletions WWW-YoutubeViewer/lib/WWW/YoutubeViewer.pm
Expand Up @@ -1445,6 +1445,28 @@ sub full_gdata_arguments {
return $self->list_to_gdata_arguments(%hash);
}

=head2 add_video_to_playlist($playlistID, $videoID; $position=1)
Add a video to given playlist ID, at position 1 (by default)
=cut

sub add_video_to_playlist {
my ($self, $playlist_id, $video_id, $position) = @_;

$position //= 1;
my $uri = $self->get_feeds_url() . "/playlists/$playlist_id";

return $self->_save('POST', $uri, <<"XML_HEADER");
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<id>$video_id</id>
<yt:position>$position</yt:position>
</entry>
XML_HEADER
}

=head2 send_rating_to_video($videoID, $rating)
Send rating to a video. $rating can be either 'like' or 'dislike'.
Expand Down Expand Up @@ -1682,6 +1704,14 @@ sub get_video_info {

*{__PACKAGE__ . '::get_' . $method->[0]} = sub {
my ($self, $id) = @_;

if ( $id eq 'default'
and $method->[0] ~~ [qw(playlists_from_username shows_from_username videos_from_username)]
and not defined $self->get_access_token) {
warn "\n[!] The method 'get_$method->[0]' requires authentication!\n";
return;
}

my $url = $self->_prepare_feed_url(sprintf($method->[1], $id));
return {
url => $url,
Expand Down

0 comments on commit 38f25fa

Please sign in to comment.