You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.4 KiB

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