[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / palcomp3.py
blob138a7853ac2c885a9acb1a43ea4368d45eb3d8dc
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 str_or_none,
5 try_get,
9 class PalcoMP3BaseIE(InfoExtractor):
10 _GQL_QUERY_TMPL = '''{
11 artist(slug: "%s") {
14 }'''
15 _ARTIST_FIELDS_TMPL = '''music(slug: "%%s") {
17 }'''
18 _MUSIC_FIELDS = '''duration
19 hls
20 mp3File
21 musicID
22 plays
23 title'''
25 def _call_api(self, artist_slug, artist_fields):
26 return self._download_json(
27 'https://www.palcomp3.com.br/graphql/', artist_slug, query={
28 'query': self._GQL_QUERY_TMPL % (artist_slug, artist_fields),
29 })['data']
31 def _parse_music(self, music):
32 music_id = str(music['musicID'])
33 title = music['title']
35 formats = []
36 hls_url = music.get('hls')
37 if hls_url:
38 formats.append({
39 'url': hls_url,
40 'protocol': 'm3u8_native',
41 'ext': 'mp4',
43 mp3_file = music.get('mp3File')
44 if mp3_file:
45 formats.append({
46 'url': mp3_file,
49 return {
50 'id': music_id,
51 'title': title,
52 'formats': formats,
53 'duration': int_or_none(music.get('duration')),
54 'view_count': int_or_none(music.get('plays')),
57 def _real_initialize(self):
58 self._ARTIST_FIELDS_TMPL = self._ARTIST_FIELDS_TMPL % self._MUSIC_FIELDS
60 def _real_extract(self, url):
61 artist_slug, music_slug = self._match_valid_url(url).groups()
62 artist_fields = self._ARTIST_FIELDS_TMPL % music_slug
63 music = self._call_api(artist_slug, artist_fields)['artist']['music']
64 return self._parse_music(music)
67 class PalcoMP3IE(PalcoMP3BaseIE):
68 IE_NAME = 'PalcoMP3:song'
69 _VALID_URL = r'https?://(?:www\.)?palcomp3\.com(?:\.br)?/(?P<artist>[^/]+)/(?P<id>[^/?&#]+)'
70 _TESTS = [{
71 'url': 'https://www.palcomp3.com/maiaraemaraisaoficial/nossas-composicoes-cuida-bem-dela/',
72 'md5': '99fd6405b2d8fd589670f6db1ba3b358',
73 'info_dict': {
74 'id': '3162927',
75 'ext': 'mp3',
76 'title': 'Nossas Composições - CUIDA BEM DELA',
77 'duration': 210,
78 'view_count': int,
82 @classmethod
83 def suitable(cls, url):
84 return False if PalcoMP3VideoIE.suitable(url) else super().suitable(url)
87 class PalcoMP3ArtistIE(PalcoMP3BaseIE):
88 IE_NAME = 'PalcoMP3:artist'
89 _VALID_URL = r'https?://(?:www\.)?palcomp3\.com(?:\.br)?/(?P<id>[^/?&#]+)'
90 _TESTS = [{
91 'url': 'https://www.palcomp3.com.br/condedoforro/',
92 'info_dict': {
93 'id': '358396',
94 'title': 'Conde do Forró',
96 'playlist_mincount': 188,
98 _ARTIST_FIELDS_TMPL = '''artistID
99 musics {
100 nodes {
104 name'''
106 @classmethod
107 def suitable(cls, url):
108 return False if PalcoMP3IE._match_valid_url(url) else super().suitable(url)
110 def _real_extract(self, url):
111 artist_slug = self._match_id(url)
112 artist = self._call_api(artist_slug, self._ARTIST_FIELDS_TMPL)['artist']
114 def entries():
115 for music in (try_get(artist, lambda x: x['musics']['nodes'], list) or []):
116 yield self._parse_music(music)
118 return self.playlist_result(
119 entries(), str_or_none(artist.get('artistID')), artist.get('name'))
122 class PalcoMP3VideoIE(PalcoMP3BaseIE):
123 IE_NAME = 'PalcoMP3:video'
124 _VALID_URL = r'https?://(?:www\.)?palcomp3\.com(?:\.br)?/(?P<artist>[^/]+)/(?P<id>[^/?&#]+)/?#clipe'
125 _TESTS = [{
126 'url': 'https://www.palcomp3.com/maiaraemaraisaoficial/maiara-e-maraisa-voce-faz-falta-aqui-ao-vivo-em-vicosa-mg/#clipe',
127 'add_ie': ['Youtube'],
128 'info_dict': {
129 'id': '_pD1nR2qqPg',
130 'ext': 'mp4',
131 'title': 'Maiara e Maraisa - Você Faz Falta Aqui - DVD Ao Vivo Em Campo Grande',
132 'description': 'md5:7043342c09a224598e93546e98e49282',
133 'upload_date': '20161107',
134 'uploader_id': 'maiaramaraisaoficial',
135 'uploader': 'Maiara e Maraisa',
138 _MUSIC_FIELDS = 'youtubeID'
140 def _parse_music(self, music):
141 youtube_id = music['youtubeID']
142 return self.url_result(youtube_id, 'Youtube', youtube_id)