ahmedsadman commited on
Commit
03ef5f3
·
1 Parent(s): 9ad32bb

choose playlist download location

Browse files
Files changed (2) hide show
  1. README.md +3 -1
  2. pytube/contrib/playlist.py +9 -3
README.md CHANGED
@@ -140,9 +140,11 @@ You can also download a complete Youtube playlist:
140
  >>> from pytube import Playlist
141
  >>> pl = Playlist("https://www.youtube.com/watch?v=Edpy1szoG80&list=PL153hDY-y1E00uQtCVCVC8xJ25TYX8yPU")
142
  >>> pl.download_all()
 
 
143
  ```
144
  This will download the highest progressive stream available (generally 720p) from the given playlist. Later more option would be give users flexibility
145
- to choose video resolution. Playlist videos will be downloaded in the directory from where the command was run.
146
 
147
  Pytube allows you to filter on every property available (see the documentation for the complete list), let's take a look at some of the most useful ones.
148
 
 
140
  >>> from pytube import Playlist
141
  >>> pl = Playlist("https://www.youtube.com/watch?v=Edpy1szoG80&list=PL153hDY-y1E00uQtCVCVC8xJ25TYX8yPU")
142
  >>> pl.download_all()
143
+ >>> # of if you want to download in a specific path
144
+ >>> pl.download_all(download_path)
145
  ```
146
  This will download the highest progressive stream available (generally 720p) from the given playlist. Later more option would be give users flexibility
147
+ to choose video resolution.
148
 
149
  Pytube allows you to filter on every property available (see the documentation for the complete list), let's take a look at some of the most useful ones.
150
 
pytube/contrib/playlist.py CHANGED
@@ -66,7 +66,7 @@ class Playlist(object):
66
  complete_url = base_url + video_id
67
  self.video_urls.append(complete_url)
68
 
69
- def download_all(self):
70
  """Download all the videos in the the playlist. Initially, download
71
  resolution is 720p (or highest available), later more option
72
  should be added to download resolution of choice
@@ -81,8 +81,14 @@ class Playlist(object):
81
  for link in self.video_urls:
82
  yt = YouTube(link)
83
 
84
- yt.streams.filter(
85
  progressive=True, subtype='mp4',
86
- ).order_by('resolution').desc().first().download()
 
 
 
 
 
 
87
 
88
  logger.debug('download complete')
 
66
  complete_url = base_url + video_id
67
  self.video_urls.append(complete_url)
68
 
69
+ def download_all(self, download_path=None):
70
  """Download all the videos in the the playlist. Initially, download
71
  resolution is 720p (or highest available), later more option
72
  should be added to download resolution of choice
 
81
  for link in self.video_urls:
82
  yt = YouTube(link)
83
 
84
+ dl_stream = yt.streams.filter(
85
  progressive=True, subtype='mp4',
86
+ ).order_by('resolution').desc().first()
87
+
88
+ if download_path is not None:
89
+ logger.debug("download path: " + download_path)
90
+ dl_stream.download(download_path)
91
+ else:
92
+ dl_stream.download()
93
 
94
  logger.debug('download complete')