logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

palcomp3.py (4532B)


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