From 919bfb0b45b6678189c5c2a0e26a1a99dda0fa63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sat, 18 Apr 2015 01:14:10 +0600 Subject: [PATCH 1/4] [YoutubeDL] Make `bestvideo+bestaudio/best` default format when merger is available --- youtube_dl/YoutubeDL.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index a68b24ab4..4b08fbfed 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1091,7 +1091,11 @@ class YoutubeDL(object): req_format = self.params.get('format') if req_format is None: - req_format = 'best' + req_format_list = [] + if info_dict['extractor'] == 'youtube' and FFmpegMergerPP(self).available: + req_format_list.append('bestvideo+bestaudio') + req_format_list.append('best') + req_format = '/'.join(req_format_list) formats_to_download = [] if req_format == 'all': formats_to_download = formats From cbb393f97cfd276f0da1283efa844f6d95012488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sat, 18 Apr 2015 03:00:35 +0600 Subject: [PATCH 2/4] [YoutubeDL] Merge incompatible formats into mkv (#5456) --- youtube_dl/YoutubeDL.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 4b08fbfed..047887509 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1373,7 +1373,29 @@ class YoutubeDL(object): ' The formats won\'t be merged') else: postprocessors = [merger] - for f in info_dict['requested_formats']: + + def compatible_formats(formats): + video, audio = formats + # Check extension + video_ext, audio_ext = audio.get('ext'), video.get('ext') + if video_ext and audio_ext: + COMPATIBLE_EXTS = ( + ('mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v'), + ('webm') + ) + for exts in COMPATIBLE_EXTS: + if video_ext in exts and audio_ext in exts: + return True + # TODO: Check acodec/vcodec + return False + + requested_formats = info_dict['requested_formats'] + # Merge incompatible formats into mkv + if not compatible_formats(requested_formats): + filename = os.path.splitext(filename)[0] + '.mkv' + self.report_warning('You have requested formats uncompatible for merge. ' + 'The formats will be merged into mkv') + for f in requested_formats: new_info = dict(info_dict) new_info.update(f) fname = self.prepare_filename(new_info) From 2faab8557ea6629de3a1b8628939aa818138d6d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sat, 18 Apr 2015 03:07:59 +0600 Subject: [PATCH 3/4] [parameters.json] Set default `format` parameter to `best` --- test/parameters.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parameters.json b/test/parameters.json index cbff9bd16..48b5a062e 100644 --- a/test/parameters.json +++ b/test/parameters.json @@ -7,7 +7,7 @@ "forcethumbnail": false, "forcetitle": false, "forceurl": false, - "format": null, + "format": "best", "format_limit": null, "ignoreerrors": false, "listformats": null, From 20d1e21f7ffecf7a1235cf6b9d479acea1fdc72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sun, 19 Apr 2015 20:15:18 +0600 Subject: [PATCH 4/4] [YoutubeDL] Skip the whole processing if final merged file already exists --- youtube_dl/YoutubeDL.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 047887509..1b90ba6fa 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1390,9 +1390,15 @@ class YoutubeDL(object): return False requested_formats = info_dict['requested_formats'] - # Merge incompatible formats into mkv + uncompatible_merge_warn = False + # Incompatible formats will be merged into mkv if not compatible_formats(requested_formats): filename = os.path.splitext(filename)[0] + '.mkv' + uncompatible_merge_warn = True + if os.path.exists(encodeFilename(filename)): + self.report_file_already_downloaded(filename) + return + if uncompatible_merge_warn: self.report_warning('You have requested formats uncompatible for merge. ' 'The formats will be merged into mkv') for f in requested_formats: