From 6a09bcde7c96528543d6c7f161924477544cae2f Mon Sep 17 00:00:00 2001 From: Glenn Slayden <5589855+glenn-slayden@users.noreply.github.com> Date: Tue, 6 Jul 2021 14:02:30 -0700 Subject: [PATCH 1/6] Early extraction of duration metadata via playlist thumbnail overlay Early gathering of item video durations from playlist metadata, prior to downloading individual item metadata pages, so that video duration values are (e.g.) shown in `--flat-playlist` or `--simulate`, and/or can be used as a download filtering criterion. --- youtube_dl/extractor/youtube.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index dc4bd4a77..7b1560c07 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -316,8 +316,12 @@ class YoutubeBaseInfoExtractor(InfoExtractor): description = try_get( renderer, lambda x: x['descriptionSnippet']['runs'][0]['text'], compat_str) - duration = parse_duration(try_get( - renderer, lambda x: x['lengthText']['simpleText'], compat_str)) + duration_text = try_get( + renderer, + (lambda x: x['lengthText']['simpleText'], + lambda x: x['thumbnailOverlays'][0]['thumbnailOverlayTimeStatusRenderer']['text']['simpleText']), + compat_str) + duration = parse_duration(duration_text) view_count_text = try_get( renderer, lambda x: x['viewCountText']['simpleText'], compat_str) or '' view_count = str_to_int(self._search_regex( From a80c44ea8e99aaac587b12cd706c1746b6dfbe9c Mon Sep 17 00:00:00 2001 From: Glenn Slayden <5589855+glenn-slayden@users.noreply.github.com> Date: Tue, 6 Jul 2021 14:10:41 -0700 Subject: [PATCH 2/6] Adjust hanging alignment, if you prefer? --- youtube_dl/extractor/youtube.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 7b1560c07..9db32c639 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -319,8 +319,8 @@ class YoutubeBaseInfoExtractor(InfoExtractor): duration_text = try_get( renderer, (lambda x: x['lengthText']['simpleText'], - lambda x: x['thumbnailOverlays'][0]['thumbnailOverlayTimeStatusRenderer']['text']['simpleText']), - compat_str) + lambda x: x['thumbnailOverlays'][0]['thumbnailOverlayTimeStatusRenderer']['text']['simpleText']), + compat_str) duration = parse_duration(duration_text) view_count_text = try_get( renderer, lambda x: x['viewCountText']['simpleText'], compat_str) or '' From 6c43aeea5c6a77c8a1fbf3f59a87cfc2a4664206 Mon Sep 17 00:00:00 2001 From: Glenn Slayden <5589855+glenn-slayden@users.noreply.github.com> Date: Tue, 6 Jul 2021 14:19:52 -0700 Subject: [PATCH 3/6] ...or is this what the linter wants? --- youtube_dl/extractor/youtube.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 9db32c639..2112df856 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -318,7 +318,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor): compat_str) duration_text = try_get( renderer, - (lambda x: x['lengthText']['simpleText'], + (lambda x: x['lengthText']['simpleText'], lambda x: x['thumbnailOverlays'][0]['thumbnailOverlayTimeStatusRenderer']['text']['simpleText']), compat_str) duration = parse_duration(duration_text) From d8aa72b0063c3d91aa12c6f2a026f388dff94bbb Mon Sep 17 00:00:00 2001 From: Glenn Slayden <5589855+glenn-slayden@users.noreply.github.com> Date: Tue, 6 Jul 2021 14:37:21 -0700 Subject: [PATCH 4/6] I'll get this right sooner or later... --- youtube_dl/extractor/youtube.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 2112df856..7eb724941 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -318,7 +318,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor): compat_str) duration_text = try_get( renderer, - (lambda x: x['lengthText']['simpleText'], + (lambda x: x['lengthText']['simpleText'], lambda x: x['thumbnailOverlays'][0]['thumbnailOverlayTimeStatusRenderer']['text']['simpleText']), compat_str) duration = parse_duration(duration_text) From 3da4918c8b8c4a55dc389c41cd2bb5ad70ed5b1b Mon Sep 17 00:00:00 2001 From: Glenn Slayden <5589855+glenn-slayden@users.noreply.github.com> Date: Tue, 6 Jul 2021 14:51:18 -0700 Subject: [PATCH 5/6] lint indentation compliance --- youtube_dl/extractor/youtube.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 7eb724941..a9eb1e483 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -315,11 +315,11 @@ class YoutubeBaseInfoExtractor(InfoExtractor): lambda x: x['title']['simpleText']), compat_str) description = try_get( renderer, lambda x: x['descriptionSnippet']['runs'][0]['text'], - compat_str) + compat_str) duration_text = try_get( - renderer, - (lambda x: x['lengthText']['simpleText'], - lambda x: x['thumbnailOverlays'][0]['thumbnailOverlayTimeStatusRenderer']['text']['simpleText']), + renderer, + (lambda x: x['lengthText']['simpleText'], + lambda x: x['thumbnailOverlays'][0]['thumbnailOverlayTimeStatusRenderer']['text']['simpleText']), compat_str) duration = parse_duration(duration_text) view_count_text = try_get( From 112e8e497068205af8fbc1698f61bc3b9dc52e96 Mon Sep 17 00:00:00 2001 From: Glenn Slayden <5589855+glenn-slayden@users.noreply.github.com> Date: Tue, 6 Jul 2021 15:11:46 -0700 Subject: [PATCH 6/6] Early extraction of duration metadata via playlist thumbnail overlay Early gathering of item video durations from playlist metadata, prior to downloading individual item metadata pages, so that video duration values are (e.g.) shown in `--flat-playlist` or `--simulate`, and/or can be used as a download filtering criterion. --- youtube_dl/extractor/youtube.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index a9eb1e483..a485c4f80 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -315,7 +315,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor): lambda x: x['title']['simpleText']), compat_str) description = try_get( renderer, lambda x: x['descriptionSnippet']['runs'][0]['text'], - compat_str) + compat_str) duration_text = try_get( renderer, (lambda x: x['lengthText']['simpleText'],