audiodraft.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from .common import InfoExtractor
  2. from ..utils import int_or_none
  3. class AudiodraftBaseIE(InfoExtractor):
  4. def _audiodraft_extract_from_id(self, player_entry_id):
  5. data_json = self._download_json(
  6. 'https://www.audiodraft.com/scripts/general/player/getPlayerInfoNew.php', player_entry_id,
  7. headers={
  8. 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
  9. 'X-Requested-With': 'XMLHttpRequest',
  10. }, data=f'id={player_entry_id}'.encode())
  11. return {
  12. 'id': str(data_json['entry_id']),
  13. 'title': data_json.get('entry_title'),
  14. 'url': data_json['path'],
  15. 'vcodec': 'none',
  16. 'ext': 'mp3',
  17. 'uploader': data_json.get('designer_name'),
  18. 'uploader_id': data_json.get('designer_id'),
  19. 'webpage_url': data_json.get('entry_url'),
  20. 'like_count': int_or_none(data_json.get('entry_likes')),
  21. 'average_rating': int_or_none(data_json.get('entry_rating')),
  22. }
  23. class AudiodraftCustomIE(AudiodraftBaseIE):
  24. IE_NAME = 'Audiodraft:custom'
  25. _VALID_URL = r'https?://(?:[-\w]+)\.audiodraft\.com/entry/(?P<id>\d+)'
  26. _TESTS = [{
  27. 'url': 'http://nokiatune.audiodraft.com/entry/5874',
  28. 'info_dict': {
  29. 'id': '9485',
  30. 'ext': 'mp3',
  31. 'title': 'Hula Hula Calls',
  32. 'uploader': 'unclemaki',
  33. 'uploader_id': '13512',
  34. 'average_rating': 5,
  35. 'like_count': int,
  36. },
  37. }, {
  38. 'url': 'http://vikinggrace.audiodraft.com/entry/501',
  39. 'info_dict': {
  40. 'id': '22241',
  41. 'ext': 'mp3',
  42. 'title': 'MVG Happy',
  43. 'uploader': 'frog',
  44. 'uploader_id': '19142',
  45. 'average_rating': 5,
  46. 'like_count': int,
  47. },
  48. }, {
  49. 'url': 'http://timferriss.audiodraft.com/entry/765',
  50. 'info_dict': {
  51. 'id': '19710',
  52. 'ext': 'mp3',
  53. 'title': 'ferris03',
  54. 'uploader': 'malex',
  55. 'uploader_id': '17335',
  56. 'average_rating': 5,
  57. 'like_count': int,
  58. },
  59. }]
  60. def _real_extract(self, url):
  61. video_id = self._match_id(url)
  62. webpage = self._download_webpage(url, video_id)
  63. player_entry_id = self._search_regex(
  64. r'playAudio\(\'(player_entry_\d+)\'\);', webpage, video_id, 'play entry id')
  65. return self._audiodraft_extract_from_id(player_entry_id)
  66. class AudiodraftGenericIE(AudiodraftBaseIE):
  67. IE_NAME = 'Audiodraft:generic'
  68. _VALID_URL = r'https?://www\.audiodraft\.com/contests/[^/#]+#entries&eid=(?P<id>\d+)'
  69. _TESTS = [{
  70. 'url': 'https://www.audiodraft.com/contests/570-Score-A-Video-Surprise-Us#entries&eid=30138',
  71. 'info_dict': {
  72. 'id': '30138',
  73. 'ext': 'mp3',
  74. 'title': 'DROP in sound_V2',
  75. 'uploader': 'TiagoSilva',
  76. 'uploader_id': '19452',
  77. 'average_rating': 4,
  78. 'like_count': int,
  79. },
  80. }]
  81. def _real_extract(self, url):
  82. video_id = self._match_id(url)
  83. return self._audiodraft_extract_from_id(f'player_entry_{video_id}')