[youtube] Fix error reason extraction (#27081)
authorDaniel Peukert <daniel@peukert.cc>
Sat, 21 Nov 2020 14:52:20 +0000 (15:52 +0100)
committerGitHub <noreply@github.com>
Sat, 21 Nov 2020 14:52:20 +0000 (21:52 +0700)
youtube_dl/extractor/youtube.py

index fb4c31326863bbbf72457d328990b614774e2ce8..fb6d816cc6ff88763cc3e5189b726b163374b446 100644 (file)
@@ -2023,6 +2023,21 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
                     formats.append(a_format)
             else:
                 error_message = extract_unavailable_message()
+                if not error_message:
+                    reason_list = try_get(
+                        player_response,
+                        lambda x: x['playabilityStatus']['errorScreen']['playerErrorMessageRenderer']['subreason']['runs'],
+                        list) or []
+                    for reason in reason_list:
+                        if not isinstance(reason, dict):
+                            continue
+                        reason_text = try_get(reason, lambda x: x['text'], compat_str)
+                        if reason_text:
+                            if not error_message:
+                                error_message = ''
+                            error_message += reason_text
+                    if error_message:
+                        error_message = clean_html(error_message)
                 if not error_message:
                     error_message = clean_html(try_get(
                         player_response, lambda x: x['playabilityStatus']['reason'],