Working playlist downloading
This commit is contained in:
parent
8bd3b26900
commit
1a4e78567e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
youtube.key
|
youtube.key
|
||||||
|
/playlists/
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from youtube_api import YouTubeAPI
|
from youtube_api import YouTubeAPI
|
||||||
import sys
|
import sys, os
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
|
|
||||||
# Read YouTube API Key.
|
# Read YouTube API Key.
|
||||||
@ -28,15 +28,27 @@ def printVideoInfo(info):
|
|||||||
print('Channel: {} ({})'.format(channel, channelId) )
|
print('Channel: {} ({})'.format(channel, channelId) )
|
||||||
print('Description: ' + description)
|
print('Description: ' + description)
|
||||||
print('Tags: ', tags)
|
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())
|
api = YouTubeAPI(getYouTubeAPIKey())
|
||||||
videos = api.getPlaylistVideos(sys.argv[1])
|
videos = api.getPlaylistVideos(playlistId)
|
||||||
|
|
||||||
videoInfo = [api.getVideoInfo(video['snippet']['resourceId']['videoId']) for video in videos]
|
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]
|
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:
|
for v in filteredVideos:
|
||||||
print(getYear(v), getId(v))
|
print(getYear(v), getId(v))
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user