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.

57 lines
1.7 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. float_or_none,
  5. parse_iso8601,
  6. )
  7. class ClypIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?clyp\.it/(?P<id>[a-z0-9]+)'
  9. _TEST = {
  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. def _real_extract(self, url):
  23. audio_id = self._match_id(url)
  24. metadata = self._download_json(
  25. 'https://api.clyp.it/%s' % audio_id, audio_id)
  26. formats = []
  27. for secure in ('', 'Secure'):
  28. for ext in ('Ogg', 'Mp3'):
  29. format_id = '%s%s' % (secure, ext)
  30. format_url = metadata.get('%sUrl' % format_id)
  31. if format_url:
  32. formats.append({
  33. 'url': format_url,
  34. 'format_id': format_id,
  35. 'vcodec': 'none',
  36. })
  37. self._sort_formats(formats)
  38. title = metadata['Title']
  39. description = metadata.get('Description')
  40. duration = float_or_none(metadata.get('Duration'))
  41. timestamp = parse_iso8601(metadata.get('DateCreated'))
  42. return {
  43. 'id': audio_id,
  44. 'title': title,
  45. 'description': description,
  46. 'duration': duration,
  47. 'timestamp': timestamp,
  48. 'formats': formats,
  49. }