logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

playfm.py (2599B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. ExtractorError,
  8. int_or_none,
  9. parse_iso8601,
  10. )
  11. class PlayFMIE(InfoExtractor):
  12. IE_NAME = 'play.fm'
  13. _VALID_URL = r'https?://(?:www\.)?play\.fm/(?P<slug>(?:[^/]+/)+(?P<id>[^/]+))/?(?:$|[?#])'
  14. _TEST = {
  15. 'url': 'https://www.play.fm/dan-drastic/sven-tasnadi-leipzig-electronic-music-batofar-paris-fr-2014-07-12',
  16. 'md5': 'c505f8307825a245d0c7ad1850001f22',
  17. 'info_dict': {
  18. 'id': '71276',
  19. 'ext': 'mp3',
  20. 'title': 'Sven Tasnadi - LEIPZIG ELECTRONIC MUSIC @ Batofar (Paris,FR) - 2014-07-12',
  21. 'description': '',
  22. 'duration': 5627,
  23. 'timestamp': 1406033781,
  24. 'upload_date': '20140722',
  25. 'uploader': 'Dan Drastic',
  26. 'uploader_id': '71170',
  27. 'view_count': int,
  28. 'comment_count': int,
  29. },
  30. }
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. video_id = mobj.group('id')
  34. slug = mobj.group('slug')
  35. recordings = self._download_json(
  36. 'http://v2api.play.fm/recordings/slug/%s' % slug, video_id)
  37. error = recordings.get('error')
  38. if isinstance(error, dict):
  39. raise ExtractorError(
  40. '%s returned error: %s' % (self.IE_NAME, error.get('message')),
  41. expected=True)
  42. audio_url = recordings['audio']
  43. video_id = compat_str(recordings.get('id') or video_id)
  44. title = recordings['title']
  45. description = recordings.get('description')
  46. duration = int_or_none(recordings.get('recordingDuration'))
  47. timestamp = parse_iso8601(recordings.get('created_at'))
  48. uploader = recordings.get('page', {}).get('title')
  49. uploader_id = compat_str(recordings.get('page', {}).get('id'))
  50. view_count = int_or_none(recordings.get('playCount'))
  51. comment_count = int_or_none(recordings.get('commentCount'))
  52. categories = [tag['name'] for tag in recordings.get('tags', []) if tag.get('name')]
  53. return {
  54. 'id': video_id,
  55. 'url': audio_url,
  56. 'title': title,
  57. 'description': description,
  58. 'duration': duration,
  59. 'timestamp': timestamp,
  60. 'uploader': uploader,
  61. 'uploader_id': uploader_id,
  62. 'view_count': view_count,
  63. 'comment_count': comment_count,
  64. 'categories': categories,
  65. }