Working playlist downloading
This commit is contained in:
parent
8bd3b26900
commit
1a4e78567e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
youtube.key
|
||||
/playlists/
|
||||
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
|
@ -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.
|
||||
@ -30,13 +30,25 @@ def printVideoInfo(info):
|
||||
print('Tags: ', tags)
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user