Compare commits
2 Commits
1a4e78567e
...
9e9a1e19d5
Author | SHA1 | Date | |
---|---|---|---|
9e9a1e19d5 | |||
7e68eb982b |
19
README.md
19
README.md
@ -1,2 +1,21 @@
|
||||
# yt-unlist-saver
|
||||
|
||||
This program will download all unlisted videos and descriptions in a given YouTube playlist that were uploaded on or before 2017.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone the repository.
|
||||
2. Install youtube-dl Python library
|
||||
```sh
|
||||
pip install youtube_dl
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
1. Go to the desired playlist in your browser.
|
||||
2. On the address bar you will see an URL like the following: https://www.youtube.com/watch?v=swRkBEDmaqk&list=PLRmPOFgS7WQFiijsHm-nAlpVAZaNXYRkx
|
||||
3. The playlist ID is after the `list=` On the playlist above it would be `PLRmPOFgS7WQFiijsHm-nAlpVAZaNXYRkx`
|
||||
4. Run the following command to download the playlist.
|
||||
```sh
|
||||
python yt-unlist-saver.py [Playlist ID]
|
||||
```
|
||||
|
@ -8,12 +8,29 @@ import youtube_dl
|
||||
def getYouTubeAPIKey():
|
||||
return open('youtube.key', 'r').read()
|
||||
|
||||
def getTitle(info):
|
||||
return info[0]
|
||||
|
||||
def getUploadTime(info):
|
||||
return info[1]
|
||||
|
||||
def getYear(info):
|
||||
return int(getUploadTime(info)[:4])
|
||||
|
||||
def getChannel(info):
|
||||
return info[2]
|
||||
|
||||
def getChannelId(info):
|
||||
return info[3]
|
||||
|
||||
def getDescription(info):
|
||||
return info[4]
|
||||
|
||||
def getTags(info):
|
||||
if isinstance(info[5], list):
|
||||
return '[' + ','.join(info[5]) + ']'
|
||||
return info[5]
|
||||
|
||||
def getPrivacy(info):
|
||||
return info[6]
|
||||
|
||||
@ -47,9 +64,24 @@ videoInfo = [api.getVideoInfo(video['snippet']['resourceId']['videoId']) for vid
|
||||
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)
|
||||
'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(['https://www.youtube.com/watch?v='+getId(v)])
|
||||
ydl.download([videoURL])
|
||||
|
||||
# Save metadata to file
|
||||
description = open('{}/{}-{}-{}.txt'.format(playlistDir,
|
||||
getChannel(v),
|
||||
getTitle(v),
|
||||
getId(v)), 'w')
|
||||
description.write('Title: ' + getTitle(v) + '\n')
|
||||
description.write('Uploaded: ' + getUploadTime(v) + '\n')
|
||||
description.write('Channel: ' + getChannel(v) + '\n')
|
||||
description.write('Channel ID: ' + getChannelId(v) + '\n')
|
||||
description.write('Description: ' + getDescription(v) + '\n')
|
||||
description.write('Tags: ' + getTags(v) + '\n')
|
||||
description.write('Video ID: ' + getId(v) + '\n')
|
||||
description.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user