From acd69589a54d03f60a018a298c74a4c8aef2abc2 Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Wed, 30 Apr 2014 10:02:03 +0200 Subject: [PATCH] [YoutubeDL] Do not require default output template to be set --- youtube_dl/YoutubeDL.py | 9 ++++++--- youtube_dl/__init__.py | 3 ++- youtube_dl/extractor/vine.py | 4 ++-- youtube_dl/utils.py | 2 ++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index e9811bd05..f3666573a 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -31,6 +31,7 @@ ContentTooShortError, date_from_str, DateRange, + DEFAULT_OUTTMPL, determine_ext, DownloadError, encodeFilename, @@ -440,7 +441,8 @@ def prepare_filename(self, info_dict): if v is not None) template_dict = collections.defaultdict(lambda: 'NA', template_dict) - tmpl = os.path.expanduser(self.params['outtmpl']) + outtmpl = self.params.get('outtmpl', DEFAULT_OUTTMPL) + tmpl = os.path.expanduser(outtmpl) filename = tmpl % template_dict return filename except ValueError as err: @@ -1025,10 +1027,11 @@ def dl(name, info): def download(self, url_list): """Download a given list of URLs.""" + outtmpl = self.params.get('outtmpl', DEFAULT_OUTTMPL) if (len(url_list) > 1 and - '%' not in self.params['outtmpl'] + '%' not in outtmpl and self.params.get('max_downloads') != 1): - raise SameFileError(self.params['outtmpl']) + raise SameFileError(outtmpl) for url in url_list: try: diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 42ef13786..1d8cf9a09 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -72,6 +72,7 @@ compat_getpass, compat_print, DateRange, + DEFAULT_OUTTMPL, decodeOption, get_term_width, DownloadError, @@ -705,7 +706,7 @@ def _real_main(argv=None): or (opts.usetitle and u'%(title)s-%(id)s.%(ext)s') or (opts.useid and u'%(id)s.%(ext)s') or (opts.autonumber and u'%(autonumber)s-%(id)s.%(ext)s') - or u'%(title)s-%(id)s.%(ext)s') + or DEFAULT_OUTTMPL) if not os.path.splitext(outtmpl)[1] and opts.extractaudio: parser.error(u'Cannot download a video and extract audio into the same' u' file! Use "{0}.%(ext)s" instead of "{0}" as the output' diff --git a/youtube_dl/extractor/vine.py b/youtube_dl/extractor/vine.py index 5bbc8ba88..689b8dc2a 100644 --- a/youtube_dl/extractor/vine.py +++ b/youtube_dl/extractor/vine.py @@ -31,7 +31,7 @@ def _real_extract(self, url): data = json.loads(self._html_search_regex( r'window\.POST_DATA = { %s: ({.+?}) }' % video_id, webpage, 'vine data')) - + print(json.dumps(data, indent=2)) formats = [ { 'url': data['videoLowURL'], @@ -57,4 +57,4 @@ def _real_extract(self, url): 'comment_count': data['comments']['count'], 'repost_count': data['reposts']['count'], 'formats': formats, - } \ No newline at end of file + } diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index a3a7226d8..2a93d3e34 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1423,3 +1423,5 @@ def q(qid): return -1 return q + +DEFAULT_OUTTMPL = '%(title)s-%(id)s.%(ext)s'