clyp.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. float_or_none,
  4. parse_qs,
  5. unified_timestamp,
  6. )
  7. class ClypIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?clyp\.it/(?P<id>[a-z0-9]+)'
  9. _TESTS = [{
  10. 'url': 'https://clyp.it/ojz2wfah',
  11. 'md5': '1d4961036c41247ecfdcc439c0cddcbb',
  12. 'info_dict': {
  13. 'id': 'ojz2wfah',
  14. 'ext': 'mp3',
  15. 'title': 'Krisson80 - bits wip wip',
  16. 'description': '#Krisson80BitsWipWip #chiptune\n#wip',
  17. 'duration': 263.21,
  18. 'timestamp': 1443515251,
  19. 'upload_date': '20150929',
  20. },
  21. }, {
  22. 'url': 'https://clyp.it/b04p1odi?token=b0078e077e15835845c528a44417719d',
  23. 'info_dict': {
  24. 'id': 'b04p1odi',
  25. 'ext': 'mp3',
  26. 'title': 'GJ! (Reward Edit)',
  27. 'description': 'Metal Resistance (THE ONE edition)',
  28. 'duration': 177.789,
  29. 'timestamp': 1528241278,
  30. 'upload_date': '20180605',
  31. },
  32. 'params': {
  33. 'skip_download': True,
  34. },
  35. }]
  36. def _real_extract(self, url):
  37. audio_id = self._match_id(url)
  38. qs = parse_qs(url)
  39. token = qs.get('token', [None])[0]
  40. query = {}
  41. if token:
  42. query['token'] = token
  43. metadata = self._download_json(
  44. 'https://api.clyp.it/%s' % audio_id, audio_id, query=query)
  45. formats = []
  46. for secure in ('', 'Secure'):
  47. for ext in ('Ogg', 'Mp3'):
  48. format_id = '%s%s' % (secure, ext)
  49. format_url = metadata.get('%sUrl' % format_id)
  50. if format_url:
  51. formats.append({
  52. 'url': format_url,
  53. 'format_id': format_id,
  54. 'vcodec': 'none',
  55. })
  56. title = metadata['Title']
  57. description = metadata.get('Description')
  58. duration = float_or_none(metadata.get('Duration'))
  59. timestamp = unified_timestamp(metadata.get('DateCreated'))
  60. return {
  61. 'id': audio_id,
  62. 'title': title,
  63. 'description': description,
  64. 'duration': duration,
  65. 'timestamp': timestamp,
  66. 'formats': formats,
  67. }