]> git.bitcoin.ninja Git - youtube-dl/commitdiff
implement --no-playlist to only download current video - closes #755
authorFilippo Valsorda <filippo.valsorda@gmail.com>
Mon, 30 Sep 2013 20:26:25 +0000 (16:26 -0400)
committerFilippo Valsorda <filippo.valsorda@gmail.com>
Mon, 30 Sep 2013 20:26:25 +0000 (16:26 -0400)
README.md
youtube_dl/YoutubeDL.py
youtube_dl/__init__.py
youtube_dl/extractor/youtube.py

index fc8070c376b9187ca71787bbcd7ae4a65a21e73a..66a483b76c33572222e8480a9d352f6f71bbbe39 100644 (file)
--- a/README.md
+++ b/README.md
@@ -50,6 +50,7 @@ which means you can modify it, redistribute it or use it however you like.
     --date DATE                download only videos uploaded in this date
     --datebefore DATE          download only videos uploaded before this date
     --dateafter DATE           download only videos uploaded after this date
+    --no-playlist              download only the currently playing video
 
 ## Download Options:
     -r, --rate-limit LIMIT     maximum download rate (e.g. 50k or 44.6m)
index 44a272e7ecd9d1a6cf23783b651405faa0aa29cd..2503fd09b976b86da60c9a82fd31495266106c97 100644 (file)
@@ -83,6 +83,7 @@ class YoutubeDL(object):
     skip_download:     Skip the actual download of the video file
     cachedir:          Location of the cache files in the filesystem.
                        None to disable filesystem cache.
+    noplaylist:        Download single video instead of a playlist if in doubt.
     
     The following parameters are not used by YoutubeDL itself, they are used by
     the FileDownloader:
index 28a7bdd929447d05a545e8c2e46bbe7395db8596..c9e75eab430b0bc6330858170b855f2e87cc4df0 100644 (file)
@@ -187,6 +187,7 @@ def parseOpts(overrideArguments=None):
     selection.add_option('--date', metavar='DATE', dest='date', help='download only videos uploaded in this date', default=None)
     selection.add_option('--datebefore', metavar='DATE', dest='datebefore', help='download only videos uploaded before this date', default=None)
     selection.add_option('--dateafter', metavar='DATE', dest='dateafter', help='download only videos uploaded after this date', default=None)
+    selection.add_option('--no-playlist', action='store_true', dest='noplaylist', help='download only the currently playing video', default=False)
 
 
     authentication.add_option('-u', '--username',
@@ -599,6 +600,7 @@ def _real_main(argv=None):
         'progress_with_newline': opts.progress_with_newline,
         'playliststart': opts.playliststart,
         'playlistend': opts.playlistend,
+        'noplaylist': opts.noplaylist,
         'logtostderr': opts.outtmpl == '-',
         'consoletitle': opts.consoletitle,
         'nopart': opts.nopart,
index 53f13b51664dbcdf3b89dacab4ba3e0c1c53ba46..c6876c69f01f78e406f11b825bc49045d854b267 100644 (file)
@@ -13,6 +13,7 @@ import struct
 import traceback
 import xml.etree.ElementTree
 import zlib
+import urlparse
 
 from .common import InfoExtractor, SearchInfoExtractor
 from .subtitles import SubtitlesInfoExtractor
@@ -1523,9 +1524,19 @@ class YoutubePlaylistIE(InfoExtractor):
         mobj = re.match(self._VALID_URL, url, re.VERBOSE)
         if mobj is None:
             raise ExtractorError(u'Invalid URL: %s' % url)
+        playlist_id = mobj.group(1) or mobj.group(2)
+
+        # Check if it's a video-specific URL
+        query_dict = urlparse.parse_qs(urlparse.urlparse(url).query)
+        if 'v' in query_dict:
+            video_id = query_dict['v'][0]
+            if self._downloader.params.get('noplaylist'):
+                self.to_screen(u'Downloading just video %s because of --no-playlist' % video_id)
+                return self.url_result('https://www.youtube.com/watch?v=' + video_id, 'Youtube')
+            else:
+                self.to_screen(u'Downloading playlist PL%s - add --no-playlist to just download video %s' % (playlist_id, video_id))
 
         # Download playlist videos from API
-        playlist_id = mobj.group(1) or mobj.group(2)
         videos = []
 
         for page_num in itertools.count(1):