mx3.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import re
  2. from .common import InfoExtractor
  3. from ..networking import HEADRequest
  4. from ..utils import (
  5. get_element_by_class,
  6. int_or_none,
  7. try_call,
  8. url_or_none,
  9. urlhandle_detect_ext,
  10. )
  11. from ..utils.traversal import traverse_obj
  12. class Mx3BaseIE(InfoExtractor):
  13. _VALID_URL_TMPL = r'https?://(?:www\.)?%s/t/(?P<id>\w+)'
  14. _FORMATS = [{
  15. 'url': 'player_asset',
  16. 'format_id': 'default',
  17. 'quality': 0,
  18. }, {
  19. 'url': 'player_asset?quality=hd',
  20. 'format_id': 'hd',
  21. 'quality': 1,
  22. }, {
  23. 'url': 'download',
  24. 'format_id': 'download',
  25. 'quality': 2,
  26. }, {
  27. 'url': 'player_asset?quality=source',
  28. 'format_id': 'source',
  29. 'quality': 2,
  30. }]
  31. def _extract_formats(self, track_id):
  32. formats = []
  33. for fmt in self._FORMATS:
  34. format_url = f'https://{self._DOMAIN}/tracks/{track_id}/{fmt["url"]}'
  35. urlh = self._request_webpage(
  36. HEADRequest(format_url), track_id, fatal=False, expected_status=404,
  37. note=f'Checking for format {fmt["format_id"]}')
  38. if urlh and urlh.status == 200:
  39. formats.append({
  40. **fmt,
  41. 'url': format_url,
  42. 'ext': urlhandle_detect_ext(urlh),
  43. 'filesize': int_or_none(urlh.headers.get('Content-Length')),
  44. })
  45. return formats
  46. def _real_extract(self, url):
  47. track_id = self._match_id(url)
  48. webpage = self._download_webpage(url, track_id)
  49. more_info = get_element_by_class('single-more-info', webpage)
  50. data = self._download_json(f'https://{self._DOMAIN}/t/{track_id}.json', track_id, fatal=False)
  51. def get_info_field(name):
  52. return self._html_search_regex(
  53. rf'<dt[^>]*>\s*{name}\s*</dt>\s*<dd[^>]*>(.*?)</dd>',
  54. more_info, name, default=None, flags=re.DOTALL)
  55. return {
  56. 'id': track_id,
  57. 'formats': self._extract_formats(track_id),
  58. 'genre': self._html_search_regex(
  59. r'<div\b[^>]+class="single-band-genre"[^>]*>([^<]+)</div>', webpage, 'genre', default=None),
  60. 'release_year': int_or_none(get_info_field('Year of creation')),
  61. 'description': get_info_field('Description'),
  62. 'tags': try_call(lambda: get_info_field('Tag').split(', '), list),
  63. **traverse_obj(data, {
  64. 'title': ('title', {str}),
  65. 'artist': (('performer_name', 'artist'), {str}),
  66. 'album_artist': ('artist', {str}),
  67. 'composer': ('composer_name', {str}),
  68. 'thumbnail': (('picture_url_xlarge', 'picture_url'), {url_or_none}),
  69. }, get_all=False),
  70. }
  71. class Mx3IE(Mx3BaseIE):
  72. _DOMAIN = 'mx3.ch'
  73. _VALID_URL = Mx3BaseIE._VALID_URL_TMPL % re.escape(_DOMAIN)
  74. _TESTS = [{
  75. 'url': 'https://mx3.ch/t/1Cru',
  76. 'md5': '7ba09e9826b4447d4e1ce9d69e0e295f',
  77. 'info_dict': {
  78. 'id': '1Cru',
  79. 'ext': 'wav',
  80. 'artist': 'Godina',
  81. 'album_artist': 'Tortue Tortue',
  82. 'composer': 'Olivier Godinat',
  83. 'genre': 'Rock',
  84. 'thumbnail': 'https://mx3.ch/pictures/mx3/file/0101/4643/square_xlarge/1-s-envoler-1.jpg?1630272813',
  85. 'title': "S'envoler",
  86. 'release_year': 2021,
  87. 'tags': [],
  88. },
  89. }, {
  90. 'url': 'https://mx3.ch/t/1LIY',
  91. 'md5': '48293cb908342547827f963a5a2e9118',
  92. 'info_dict': {
  93. 'id': '1LIY',
  94. 'ext': 'mov',
  95. 'artist': 'Tania Kimfumu',
  96. 'album_artist': 'The Broots',
  97. 'composer': 'Emmanuel Diserens',
  98. 'genre': 'Electro',
  99. 'thumbnail': 'https://mx3.ch/pictures/mx3/file/0110/0003/video_xlarge/frame_0000.png?1686963670',
  100. 'title': 'The Broots-Larytta remix "Begging For Help"',
  101. 'release_year': 2023,
  102. 'tags': ['the broots', 'cassata records', 'larytta'],
  103. 'description': '"Begging for Help" Larytta Remix Official Video\nRealized By Kali Donkilie in 2023',
  104. },
  105. }, {
  106. 'url': 'https://mx3.ch/t/1C6E',
  107. 'md5': '1afcd578493ddb8e5008e94bb6d97e25',
  108. 'info_dict': {
  109. 'id': '1C6E',
  110. 'ext': 'wav',
  111. 'artist': 'Alien Bubblegum',
  112. 'album_artist': 'Alien Bubblegum',
  113. 'composer': 'Alien Bubblegum',
  114. 'genre': 'Punk',
  115. 'thumbnail': 'https://mx3.ch/pictures/mx3/file/0101/1551/square_xlarge/pandora-s-box-cover-with-title.png?1627054733',
  116. 'title': 'Wide Awake',
  117. 'release_year': 2021,
  118. 'tags': ['alien bubblegum', 'bubblegum', 'alien', 'pop punk', 'poppunk'],
  119. },
  120. }]
  121. class Mx3NeoIE(Mx3BaseIE):
  122. _DOMAIN = 'neo.mx3.ch'
  123. _VALID_URL = Mx3BaseIE._VALID_URL_TMPL % re.escape(_DOMAIN)
  124. _TESTS = [{
  125. 'url': 'https://neo.mx3.ch/t/1hpd',
  126. 'md5': '6d9986bbae5cac3296ec8813bf965eb2',
  127. 'info_dict': {
  128. 'id': '1hpd',
  129. 'ext': 'wav',
  130. 'artist': 'Baptiste Lopez',
  131. 'album_artist': 'Kammerorchester Basel',
  132. 'composer': 'Jannik Giger',
  133. 'genre': 'Composition, Orchestra',
  134. 'title': 'Troisième œil. Für Kammerorchester (2023)',
  135. 'thumbnail': 'https://neo.mx3.ch/pictures/neo/file/0000/0241/square_xlarge/kammerorchester-basel-group-photo-2_c_-lukasz-rajchert.jpg?1560341252',
  136. 'release_year': 2023,
  137. 'tags': [],
  138. },
  139. }]
  140. class Mx3VolksmusikIE(Mx3BaseIE):
  141. _DOMAIN = 'volksmusik.mx3.ch'
  142. _VALID_URL = Mx3BaseIE._VALID_URL_TMPL % re.escape(_DOMAIN)
  143. _TESTS = [{
  144. 'url': 'https://volksmusik.mx3.ch/t/Zx',
  145. 'md5': 'dd967a7b0c1ef898f3e072cf9c2eae3c',
  146. 'info_dict': {
  147. 'id': 'Zx',
  148. 'ext': 'mp3',
  149. 'artist': 'Ländlerkapelle GrischArt',
  150. 'album_artist': 'Ländlerkapelle GrischArt',
  151. 'composer': 'Urs Glauser',
  152. 'genre': 'Instrumental, Graubünden',
  153. 'title': 'Chämilouf',
  154. 'thumbnail': 'https://volksmusik.mx3.ch/pictures/vxm/file/0000/3815/square_xlarge/grischart1.jpg?1450530120',
  155. 'release_year': 2012,
  156. 'tags': [],
  157. },
  158. }]