]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/musescore.py
[MuseScore] Add Extractor (#918)
[yt-dlp.git] / yt_dlp / extractor / musescore.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class MuseScoreIE(InfoExtractor):
8 _VALID_URL = r'(?:https?://)(?:www\.)?musescore\.com/(?:user/\d+|[^/]+)(?:/scores)?/(?P<id>[^#&?]+)'
9 _TESTS = [{
10 'url': 'https://musescore.com/user/73797/scores/142975',
11 'info_dict': {
12 'id': '142975',
13 'ext': 'mp3',
14 'title': 'WA Mozart Marche Turque (Turkish March fingered)',
15 'description': 'md5:7ede08230e4eaabd67a4a98bb54d07be',
16 'thumbnail': r're:(?:https?://)(?:www\.)?musescore\.com/.*\.png[^$]+',
17 'uploader': 'PapyPiano',
18 'creator': 'Wolfgang Amadeus Mozart',
19 }
20 }, {
21 'url': 'https://musescore.com/user/36164500/scores/6837638',
22 'info_dict': {
23 'id': '6837638',
24 'ext': 'mp3',
25 'title': 'Sweet Child O\' Mine – Guns N\' Roses sweet child',
26 'description': 'md5:4dca71191c14abc312a0a4192492eace',
27 'thumbnail': r're:(?:https?://)(?:www\.)?musescore\.com/.*\.png[^$]+',
28 'uploader': 'roxbelviolin',
29 'creator': 'Guns N´Roses Arr. Roxbel Violin',
30 }
31 }, {
32 'url': 'https://musescore.com/classicman/fur-elise',
33 'info_dict': {
34 'id': '33816',
35 'ext': 'mp3',
36 'title': 'Für Elise – Beethoven',
37 'description': 'md5:49515a3556d5ecaf9fa4b2514064ac34',
38 'thumbnail': r're:(?:https?://)(?:www\.)?musescore\.com/.*\.png[^$]+',
39 'uploader': 'ClassicMan',
40 'creator': 'Ludwig van Beethoven (1770–1827)',
41 }
42 }, {
43 'url': 'https://musescore.com/minh_cuteee/scores/6555384',
44 'only_matching': True,
45 }]
46
47 def _real_extract(self, url):
48 webpage = self._download_webpage(url, None)
49 url = self._og_search_url(webpage) or url
50 id = self._match_id(url)
51 mp3_url = self._download_json(f'https://musescore.com/api/jmuse?id={id}&index=0&type=mp3&v2=1', id,
52 headers={'authorization': '63794e5461e4cfa046edfbdddfccc1ac16daffd2'})['info']['url']
53 formats = [{
54 'url': mp3_url,
55 'ext': 'mp3',
56 'vcodec': 'none',
57 }]
58
59 return {
60 'id': id,
61 'formats': formats,
62 'title': self._og_search_title(webpage),
63 'description': self._og_search_description(webpage),
64 'thumbnail': self._og_search_thumbnail(webpage),
65 'uploader': self._html_search_meta('musescore:author', webpage, 'uploader'),
66 'creator': self._html_search_meta('musescore:composer', webpage, 'composer'),
67 }