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