diff --git a/.gitignore b/.gitignore index 7c10531..f7ea0ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ youtube.key +/playlists/ # ---> Python # Byte-compiled / optimized / DLL files diff --git a/yt-unlist-saver.py b/yt-unlist-saver.py index 7900548..c41816c 100644 --- a/yt-unlist-saver.py +++ b/yt-unlist-saver.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from youtube_api import YouTubeAPI -import sys +import sys, os import youtube_dl # Read YouTube API Key. @@ -28,15 +28,27 @@ def printVideoInfo(info): print('Channel: {} ({})'.format(channel, channelId) ) print('Description: ' + description) print('Tags: ', tags) - print('Privacy: ' + privacy) + print('Privacy: ' + privacy) +playlistId = sys.argv[1] + +# Create download directory +downloadDir = 'playlists' +playlistDir = downloadDir+'/'+playlistId +if not os.path.exists(downloadDir): + os.mkdir(downloadDir) +if not os.path.exists(playlistDir): + os.mkdir(playlistDir) + api = YouTubeAPI(getYouTubeAPIKey()) -videos = api.getPlaylistVideos(sys.argv[1]) +videos = api.getPlaylistVideos(playlistId) videoInfo = [api.getVideoInfo(video['snippet']['resourceId']['videoId']) for video in videos] filteredVideos = [video for video in videoInfo if getPrivacy(video) == 'unlisted' and getYear(video) <= 2017] -ydl_opts = {} +ydl_opts = { + 'outtmpl': '{}/%(extractor)s-%(id)s-%(title)s.%(ext)s'.format(playlistDir) +} for v in filteredVideos: print(getYear(v), getId(v)) with youtube_dl.YoutubeDL(ydl_opts) as ydl: