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