Working playlist downloading

This commit is contained in:
Christian Colglazier 2021-06-28 20:07:12 -04:00
parent 8bd3b26900
commit 1a4e78567e
2 changed files with 17 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
youtube.key
/playlists/
# ---> Python
# Byte-compiled / optimized / DLL files

View File

@ -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: