Working playlist downloading
This commit is contained in:
		
							
								
								
									
										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.
 | 
				
			||||||
@@ -30,13 +30,25 @@ 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 = {}
 | 
					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:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user