From b02b5b87b3bae22a9c2667c5b1652ddd7e5afbcb Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 6 Aug 2018 19:25:14 -0700 Subject: list music used in video if available --- youtube/shared.css | 8 ++++++-- youtube/watch.py | 30 ++++++++++++++++++++++++++++ youtube_dl/extractor/youtube.py | 43 +++++++++++++++++++++++++++++++++++++++++ yt_watch_template.html | 19 +++++++++++++++++- 4 files changed, 97 insertions(+), 3 deletions(-) diff --git a/youtube/shared.css b/youtube/shared.css index f99baa1..151111d 100644 --- a/youtube/shared.css +++ b/youtube/shared.css @@ -227,11 +227,15 @@ address{ grid-column: 1 / span 2; grid-row: 6; } + .full-item .music-list{ + grid-row:7; + grid-column: 1 / span 2; + } .full-item .comments{ - grid-row: 7; + grid-row: 8; } .full-item .more-comments{ - grid-row: 8; + grid-row: 9; } .medium-item-box{ diff --git a/youtube/watch.py b/youtube/watch.py index c669f5e..cfe827b 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -296,6 +296,10 @@ def extract_info(downloader, *args, **kwargs): except YoutubeError as e: return str(e) +music_list_table_row = Template(''' + $attribute + $value +''') def get_watch_page(query_string): id = urllib.parse.parse_qs(query_string)['v'][0] downloader = YoutubeDL(params={'youtube_include_dash_manifest':False}) @@ -343,7 +347,32 @@ def get_watch_page(query_string): else: related_videos_html = '' + music_list = info['music_list'] + if len(music_list) == 0: + music_list_html = '' + else: + music_list_html = '''
+ + + + + + + +''' + for track in music_list: + music_list_html += '''\n''' + for attribute in ('artist', 'title', 'album'): + try: + value = track[attribute] + except KeyError: + music_list_html += '''''' + else: + music_list_html += '''''' + music_list_html += '''\n''' + music_list_html += '''
Music
ArtistTitleAlbum
''' + html.escape(value) + '''
\n''' + download_options = '' for format in info['formats']: @@ -371,5 +400,6 @@ def get_watch_page(query_string): related = related_videos_html, comments = comments_html, more_comments_button = more_comments_button, + music_list = music_list_html, ) return page \ No newline at end of file diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index c120cfb..39e4ca5 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -10,6 +10,7 @@ import random import re import time import traceback +import html from .common import InfoExtractor, SearchInfoExtractor from ..jsinterp import JSInterpreter @@ -1479,6 +1480,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor): }) return chapters + ul_tag_pattern = re.compile(r'(\s*(Song|Music|Artist|Album)\s*\s*