logo

youtube-dl

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

whyp.py (1788B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. merge_dicts,
  7. str_or_none,
  8. T,
  9. traverse_obj,
  10. url_or_none,
  11. )
  12. class WhypIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?whyp\.it/tracks/(?P<id>\d+)'
  14. _TESTS = [{
  15. 'url': 'https://www.whyp.it/tracks/18337/home-page-example-track-b4kq7',
  16. 'md5': 'c1187b42ebf8605284e3dc92aeb33d16',
  17. 'info_dict': {
  18. 'url': 'https://cdn.whyp.it/50eb17cc-e9ff-4e18-b89b-dc9206a95cb1.mp3',
  19. 'id': '18337',
  20. 'title': 'Home Page Example Track',
  21. 'description': r're:(?s).+\bexample track\b',
  22. 'ext': 'mp3',
  23. 'duration': 52.82,
  24. 'uploader': 'Brad',
  25. 'uploader_id': '1',
  26. 'thumbnail': 'https://cdn.whyp.it/a537bb36-3373-4c61-96c8-27fc1b2f427a.jpg',
  27. },
  28. }, {
  29. 'url': 'https://www.whyp.it/tracks/18337',
  30. 'only_matching': True,
  31. }]
  32. def _real_extract(self, url):
  33. unique_id = self._match_id(url)
  34. webpage = self._download_webpage(url, unique_id)
  35. data = self._search_nuxt_data(webpage, unique_id)['rawTrack']
  36. return merge_dicts({
  37. 'url': data['audio_url'],
  38. 'id': unique_id,
  39. }, traverse_obj(data, {
  40. 'title': 'title',
  41. 'description': 'description',
  42. 'duration': ('duration', T(float_or_none)),
  43. 'uploader': ('user', 'username'),
  44. 'uploader_id': ('user', 'id', T(str_or_none)),
  45. 'thumbnail': ('artwork_url', T(url_or_none)),
  46. }), {
  47. 'ext': 'mp3',
  48. 'vcodec': 'none',
  49. 'http_headers': {'Referer': 'https://whyp.it/'},
  50. }, rev=True)