Compare commits
4 Commits
9e9a1e19d5
...
master
Author | SHA1 | Date | |
---|---|---|---|
668e497ae0 | |||
3c522c6459 | |||
2a89badcb6 | |||
4084f836cc |
@ -6,6 +6,8 @@ This program will download all unlisted videos and descriptions in a given YouTu
|
||||
|
||||
1. Clone the repository.
|
||||
2. Install youtube-dl Python library
|
||||
3. Get a YouTube API key following the instructions here [YouTube Data API Overview](https://developers.google.com/youtube/registering_an_application)
|
||||
4. Save the API key to a file called `youtube.key`
|
||||
```sh
|
||||
pip install youtube_dl
|
||||
```
|
||||
|
@ -22,6 +22,10 @@ class YouTubeAPI(object):
|
||||
def getVideoInfo(self, id):
|
||||
snippet = self.getVideo('snippet', id)
|
||||
status = self.getVideo('status', id)
|
||||
|
||||
# Check for private videos
|
||||
if len(snippet['items']) == 0:
|
||||
return '', '', '', '', '', '', 'private', id
|
||||
snippet = snippet['items'][0]['snippet']
|
||||
status = status['items'][0]['status']
|
||||
title = snippet['title']
|
||||
|
@ -66,17 +66,16 @@ filteredVideos = [video for video in videoInfo if getPrivacy(video) == 'unlisted
|
||||
ydl_opts = {
|
||||
'outtmpl': '{}/%(uploader)s-%(title)s-%(id)s.%(ext)s'.format(playlistDir)
|
||||
}
|
||||
for v in filteredVideos:
|
||||
print(getYear(v), getId(v))
|
||||
videoURL = 'https://www.youtube.com/watch?v='+getId(v)
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download([videoURL])
|
||||
|
||||
# Save metadata to file
|
||||
description = open('{}/{}-{}-{}.txt'.format(playlistDir,
|
||||
getChannel(v),
|
||||
getTitle(v),
|
||||
getId(v)), 'w')
|
||||
for v in filteredVideos:
|
||||
|
||||
# Save metadata to file
|
||||
descriptionFile = '{}/{}-{}-{}.txt'.format(playlistDir,
|
||||
getChannel(v),
|
||||
getTitle(v).replace('/', ''),
|
||||
getId(v))
|
||||
if not os.path.exists(descriptionFile):
|
||||
description = open(descriptionFile, 'w')
|
||||
description.write('Title: ' + getTitle(v) + '\n')
|
||||
description.write('Uploaded: ' + getUploadTime(v) + '\n')
|
||||
description.write('Channel: ' + getChannel(v) + '\n')
|
||||
@ -85,3 +84,8 @@ for v in filteredVideos:
|
||||
description.write('Tags: ' + getTags(v) + '\n')
|
||||
description.write('Video ID: ' + getId(v) + '\n')
|
||||
description.close()
|
||||
|
||||
videoURL = 'https://www.youtube.com/watch?v='+getId(v)
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download([videoURL])
|
||||
|
||||
|
Reference in New Issue
Block a user