vocaroo.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from .common import InfoExtractor
  2. from ..networking import HEADRequest
  3. from ..utils import float_or_none
  4. class VocarooIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?(?:vocaroo\.com|voca\.ro)/(?:embed/)?(?P<id>\w+)'
  6. _EMBED_REGEX = [r'<iframe[^>]+src=(["\'])(?P<url>(?:https?://)?(?:www\.)?vocaroo\.com/embed/.+?)\1']
  7. _TESTS = [
  8. {
  9. 'url': 'https://vocaroo.com/1de8yA3LNe77',
  10. 'md5': 'c557841d5e50261777a6585648adf439',
  11. 'info_dict': {
  12. 'id': '1de8yA3LNe77',
  13. 'ext': 'mp3',
  14. 'title': 'Vocaroo video #1de8yA3LNe77',
  15. 'timestamp': 1675059800.370,
  16. 'upload_date': '20230130',
  17. },
  18. },
  19. {
  20. 'url': 'https://vocaroo.com/embed/12WqtjLnpj6g?autoplay=0',
  21. 'only_matching': True,
  22. },
  23. {
  24. 'url': 'https://voca.ro/12D52rgpzkB0',
  25. 'only_matching': True,
  26. },
  27. ]
  28. _WEBPAGE_TESTS = [
  29. {
  30. 'url': 'https://qbnu.github.io/cool.html',
  31. 'md5': 'f322e529275dd8a47994919eeac404a5',
  32. 'info_dict': {
  33. 'id': '19cgWmKO6AmC',
  34. 'ext': 'mp3',
  35. 'title': 'Vocaroo video #19cgWmKO6AmC',
  36. 'timestamp': 1675093841.408,
  37. 'upload_date': '20230130',
  38. },
  39. },
  40. ]
  41. def _real_extract(self, url):
  42. audio_id = self._match_id(url)
  43. if len(audio_id) == 10 or (len(audio_id) == 12 and audio_id[0] == '1'):
  44. media_subdomain = 'media1'
  45. else:
  46. media_subdomain = 'media'
  47. url = f'https://{media_subdomain}.vocaroo.com/mp3/{audio_id}'
  48. http_headers = {'Referer': 'https://vocaroo.com/'}
  49. resp = self._request_webpage(HEADRequest(url), audio_id, headers=http_headers)
  50. return {
  51. 'id': audio_id,
  52. 'title': '',
  53. 'url': url,
  54. 'ext': 'mp3',
  55. 'timestamp': float_or_none(resp.headers.get('x-bz-upload-timestamp'), scale=1000),
  56. 'vcodec': 'none',
  57. 'http_headers': http_headers,
  58. }