aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdownload_yt_playlist32
1 files changed, 6 insertions, 26 deletions
diff --git a/download_yt_playlist b/download_yt_playlist
index 32b50eb..9953239 100755
--- a/download_yt_playlist
+++ b/download_yt_playlist
@@ -1,28 +1,8 @@
-#!/usr/bin/env perl
+#!/bin/sh
-use strict;
-use warnings;
+if [ $# -ne 1 ]; then
+ echo "Usage: $0 <playlist_id>"
+ exit 1
+fi
-use JSON;
-
-my $ENDPOINT = "https://www.googleapis.com/youtube/v3";
-my $YT_API_KEY = $ENV{'YOUTUBE_API_KEY'}
- || die "Error: You need to define the env variable 'YOUTUBE_API_KEY'\n";
-
-sub decode_json_utf8 {
- my $json = join "", @_;
- utf8::encode($json);
- return decode_json($json);
-}
-
-sub api_playlist_videos {
- my $id = shift;
- my $videos = (decode_json_utf8 `curl -s '$ENDPOINT/playlistItems?part=snippet&maxResults=1000&playlistId=$id&key=$YT_API_KEY'`)->{items};
- return map { $_->{snippet}{resourceId}{videoId} } @$videos;
-}
-
-@ARGV == 1 or die "Usage: $0 <playlist_id>\n";
-my $pl_id = $ARGV[0];
-my @videos = map { "https://www.youtube.com/watch?v=" . $_ } api_playlist_videos($pl_id);
-
-`mkdir $pl_id && cd $pl_id && youtube-dl @videos\n`;
+exec youtube-dl -o '%(playlist)s/%(playlist_index)s %(title)s.%(ext)s' "https://www.youtube.com/playlist?list=$1"