Compare commits
2 Commits
5d58428cd9
...
1a4e78567e
Author | SHA1 | Date | |
---|---|---|---|
1a4e78567e | |||
8bd3b26900 |
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
|
||||||
|
@ -19,9 +19,9 @@ class YouTubeAPI(object):
|
|||||||
def getVideo(self, part, id):
|
def getVideo(self, part, id):
|
||||||
return self.getRequest('videos?part={}&id={}'.format(part, id))
|
return self.getRequest('videos?part={}&id={}'.format(part, id))
|
||||||
|
|
||||||
def getVideoInfo(self, tag):
|
def getVideoInfo(self, id):
|
||||||
snippet = self.getVideo('snippet', tag)
|
snippet = self.getVideo('snippet', id)
|
||||||
status = self.getVideo('status', tag)
|
status = self.getVideo('status', id)
|
||||||
snippet = snippet['items'][0]['snippet']
|
snippet = snippet['items'][0]['snippet']
|
||||||
status = status['items'][0]['status']
|
status = status['items'][0]['status']
|
||||||
title = snippet['title']
|
title = snippet['title']
|
||||||
@ -34,7 +34,7 @@ class YouTubeAPI(object):
|
|||||||
except:
|
except:
|
||||||
tags = ''
|
tags = ''
|
||||||
privacy = status['privacyStatus']
|
privacy = status['privacyStatus']
|
||||||
return title, date, channel, channelId, description, tags, privacy
|
return title, date, channel, channelId, description, tags, privacy, id
|
||||||
|
|
||||||
def getPlaylist(self, id, pageToken=''):
|
def getPlaylist(self, id, pageToken=''):
|
||||||
if(pageToken):
|
if(pageToken):
|
||||||
|
@ -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.
|
||||||
@ -17,6 +17,9 @@ def getYear(info):
|
|||||||
def getPrivacy(info):
|
def getPrivacy(info):
|
||||||
return info[6]
|
return info[6]
|
||||||
|
|
||||||
|
def getId(info):
|
||||||
|
return info[7]
|
||||||
|
|
||||||
# Print out information about a video.
|
# Print out information about a video.
|
||||||
def printVideoInfo(info):
|
def printVideoInfo(info):
|
||||||
title, date, channel, channelId, description, tags, privacy = info
|
title, date, channel, channelId, description, tags, privacy = info
|
||||||
@ -27,11 +30,26 @@ def printVideoInfo(info):
|
|||||||
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 = {
|
||||||
|
'outtmpl': '{}/%(extractor)s-%(id)s-%(title)s.%(ext)s'.format(playlistDir)
|
||||||
|
}
|
||||||
for v in filteredVideos:
|
for v in filteredVideos:
|
||||||
print(getYear(v))
|
print(getYear(v), getId(v))
|
||||||
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
ydl.download(['https://www.youtube.com/watch?v='+getId(v)])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user