Skip to content

Commit

Permalink
CLI: added support for streams and popular streams from a given chann…
Browse files Browse the repository at this point in the history
…el ID.

Via the command-line options:

	--streams=s
	--popular-streams=s

And also via the STDIN options:

	:us=i		# user streams
	:ps=i		# popular streams
  • Loading branch information
trizen committed Nov 24, 2022
1 parent 6224bb8 commit ab6da59
Showing 1 changed file with 130 additions and 3 deletions.
133 changes: 130 additions & 3 deletions bin/pipe-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ my $channels_help = <<"CHANNELS_HELP" . $general_help;
# Select a channel
<number> : latest uploads from channel
:us=i : latest streams from channel
:ps=i : popular streams from channel
:pv=i :popular=i : popular uploads from channel
:p=i :playlists=i : playlists from channel
Expand All @@ -408,7 +410,9 @@ $control_options
:c(omments)=i : display video comments
:r(elated)=i : display related videos
:u(ploads)=i : display author's latest uploads
:us=i : display author's latest streams
:pv=i :popular=i : display author's popular uploads
:ps=i : display author's popular streams
:p(laylists)=i : display author's playlists
:subscribe=i : subscribe to author's channel
:(dis)like=i : like or dislike a video
Expand Down Expand Up @@ -767,7 +771,9 @@ usage: $execname [options] ([url] | [keywords])
* Videos
-uv --uploads=s : list videos uploaded by a specific channel or user
-us --streams=s : list livestream videos by a specific channel or user
-pv --popular=s : list the most popular videos from a specific channel
-ps --pstreams=s : list the most popular streams from a specific channel
-id --videoids=s,s : play YouTube videos by their IDs
-rv --related=s : show related videos for a video ID or URL
-sv --search-videos : search for YouTube videos (default mode)
Expand Down Expand Up @@ -1382,6 +1388,22 @@ sub apply_configuration {
}
}

if (defined $opt->{streams}) {
my $str = delete $opt->{streams};

if ($str) {
if (my $id = extract_channel_id($str)) {
print_videos($yv_obj->streams($id));
}
else {
warn_invalid("username or channel ID", $str);
}
}
else {
warn_invalid("username or channel ID", $str);
}
}

if (defined $opt->{popular_videos}) {
my $str = delete $opt->{popular_videos};

Expand All @@ -1404,6 +1426,25 @@ sub apply_configuration {
}
}

if (defined $opt->{popular_streams}) {
my $str = delete $opt->{popular_streams};

if (my $id = extract_channel_id($str)) {

if (not $yv_utils->is_channelID($id)) {
$id = $yv_obj->channel_id_from_username($id) // do {
warn_invalid("username or channel ID", $id);
undef;
};
}

print_videos($yv_obj->popular_streams($id));
}
else {
warn_invalid("username or channel ID", $str);
}
}

if (defined $opt->{trending}) {
my $cat_id = delete $opt->{trending};
print_videos($yv_obj->trending_videos_from_category($cat_id));
Expand Down Expand Up @@ -1516,6 +1557,7 @@ sub parse_arguments {
'search-movie|movies|sm!' => \$opt{search_movies},

'uploads|U|user|user-videos|uv|u=s' => \$opt{uploads},
'streams|user-streams|us=s' => \$opt{streams},
'favorites|F' => \$opt{favorites},
'playlists|P|user-playlists|up:s' => \$opt{playlists},
'likes|L|user-likes' => \$opt{likes},
Expand All @@ -1528,8 +1570,9 @@ sub parse_arguments {
# English-UK friendly
'favorite|favourite|favorite-video|favourite-video|fav=s' => \$opt{favorite_video},

'related-videos|rv=s' => \$opt{related_videos},
'popular-videos|popular|pv:s' => \$opt{popular_videos},
'related-videos|rv=s' => \$opt{related_videos},
'popular-videos|popular|pv:s' => \$opt{popular_videos},
'popular-streams|pstreams|ps=s' => \$opt{popular_streams},

'cookie-file|cookies=s' => \$opt{cookie_file},
'user-agent|agent=s' => \$opt{user_agent},
Expand Down Expand Up @@ -2485,6 +2528,28 @@ sub print_channels {
}
}

# :us=i, :streams=i
elsif ($opt =~ /^(?:us|streams)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$channels}, $1)) {

foreach my $id (@nums) {

my $channel_id = $yv_utils->get_channel_id($channels->[$id]);
my $request = $yv_obj->streams($channel_id);

if ($yv_utils->has_entries($request)) {
print_videos($request);
}
else {
warn_no_results('streams');
}
}
}
else {
warn_no_thing_selected('channel');
}
}

# :pv=i, :popular=i
elsif ($opt =~ /^(?:pv|popular)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$channels}, $1)) {
Expand All @@ -2507,6 +2572,28 @@ sub print_channels {
}
}

# :ps=i, :popular-streams=i
elsif ($opt =~ /^(?:ps|pstreams|popular-streams)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$channels}, $1)) {

foreach my $id (@nums) {

my $channel_id = $yv_utils->get_channel_id($channels->[$id]);
my $request = $yv_obj->popular_streams($channel_id);

if ($yv_utils->has_entries($request)) {
print_videos($request);
}
else {
warn_no_results('popular streams');
}
}
}
else {
warn_no_thing_selected('channel');
}
}

# :p=i, :playlist=i, :up=i
elsif ($opt =~ /^(?:p|l|playlists?|up)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$channels}, $1)) {
Expand Down Expand Up @@ -4277,6 +4364,25 @@ sub print_videos {
}
}

# :streams=i, :us=i
elsif ($opt =~ /^(?:streams|us)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$videos}, $1)) {
foreach my $id (@nums) {
my $channel_id = $yv_utils->get_channel_id($videos->[$id]);
my $request = $yv_obj->streams($channel_id);
if ($yv_utils->has_entries($request)) {
__SUB__->($request);
}
else {
warn_no_results('stream');
}
}
}
else {
warn_no_thing_selected('video');
}
}

# :s=i, :subscribe=i
elsif ($opt =~ /^(?:s|sub(?:scribe)?)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$videos}, $1)) {
Expand Down Expand Up @@ -4305,7 +4411,7 @@ sub print_videos {
}
}

# :popular=i, :pv=i
# :pv=i, :popular=i
elsif ($opt =~ /^(?:pv|popular)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$videos}, $1)) {
foreach my $id (@nums) {
Expand All @@ -4324,6 +4430,25 @@ sub print_videos {
}
}

# :ps=i, :popular-streams=i
elsif ($opt =~ /^(?:ps|pstreams|popular-streams)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$videos}, $1)) {
foreach my $id (@nums) {
my $channel_id = $yv_utils->get_channel_id($videos->[$id]);
my $request = $yv_obj->popular_streams($channel_id);
if ($yv_utils->has_entries($request)) {
__SUB__->($request);
}
else {
warn_no_results('popular streams');
}
}
}
else {
warn_no_thing_selected('video');
}
}

# :p=i, :playlist=i, :up=i
elsif ($opt =~ /^(?:p|l|playlists?|up)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$videos}, $1)) {
Expand Down Expand Up @@ -4352,6 +4477,8 @@ sub print_videos {
warn_no_thing_selected('video');
}
}

# :fav=i, :favorite=i
elsif ($opt =~ /^(?:fav|favorite|F)${digit_or_equal_re}(.*)/) {
if (my @nums = get_valid_numbers($#{$videos}, $1)) {
favorite_videos(map { $videos->[$_] } @nums);
Expand Down

0 comments on commit ab6da59

Please sign in to comment.