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.

86 lines
3.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse,
  7. compat_urllib_request,
  8. ExtractorError,
  9. float_or_none,
  10. int_or_none,
  11. str_to_int,
  12. )
  13. class PlayFMIE(InfoExtractor):
  14. IE_NAME = 'play.fm'
  15. _VALID_URL = r'https?://(?:www\.)?play\.fm/[^?#]*(?P<upload_date>[0-9]{8})(?P<id>[0-9]{6})(?:$|[?#])'
  16. _TEST = {
  17. 'url': 'http://www.play.fm/recording/leipzigelectronicmusicbatofarparis_fr20140712137220',
  18. 'md5': 'c505f8307825a245d0c7ad1850001f22',
  19. 'info_dict': {
  20. 'id': '137220',
  21. 'ext': 'mp3',
  22. 'title': 'LEIPZIG ELECTRONIC MUSIC @ Batofar (Paris,FR) - 2014-07-12',
  23. 'uploader': 'Sven Tasnadi',
  24. 'uploader_id': 'sventasnadi',
  25. 'duration': 5627.428,
  26. 'upload_date': '20140712',
  27. 'view_count': int,
  28. 'comment_count': int,
  29. 'thumbnail': 're:^https?://.*\.jpg$',
  30. },
  31. }
  32. def _real_extract(self, url):
  33. mobj = re.match(self._VALID_URL, url)
  34. video_id = mobj.group('id')
  35. upload_date = mobj.group('upload_date')
  36. rec_data = compat_urllib_parse.urlencode({'rec_id': video_id})
  37. req = compat_urllib_request.Request(
  38. 'http://www.play.fm/flexRead/recording', data=rec_data)
  39. req.add_header('Content-Type', 'application/x-www-form-urlencoded')
  40. rec_doc = self._download_xml(req, video_id)
  41. error_node = rec_doc.find('./error')
  42. if error_node is not None:
  43. raise ExtractorError('An error occured: %s (code %s)' % (
  44. error_node.text, rec_doc.find('./status').text))
  45. recording = rec_doc.find('./recording')
  46. title = recording.find('./title').text
  47. view_count = str_to_int(recording.find('./stats/playcount').text)
  48. comment_count = str_to_int(recording.find('./stats/comments').text)
  49. duration = float_or_none(recording.find('./duration').text, scale=1000)
  50. thumbnail = recording.find('./image').text
  51. artist = recording.find('./artists/artist')
  52. uploader = artist.find('./name').text
  53. uploader_id = artist.find('./slug').text
  54. video_url = '%s//%s/%s/%s/offset/0/sh/%s/rec/%s/jingle/%s/loc/%s' % (
  55. 'http:', recording.find('./url').text,
  56. recording.find('./_class').text, recording.find('./file_id').text,
  57. rec_doc.find('./uuid').text, video_id,
  58. rec_doc.find('./jingle/file_id').text,
  59. 'http%3A%2F%2Fwww.play.fm%2Fplayer',
  60. )
  61. return {
  62. 'id': video_id,
  63. 'url': video_url,
  64. 'ext': 'mp3',
  65. 'filesize': int_or_none(recording.find('./size').text),
  66. 'title': title,
  67. 'upload_date': upload_date,
  68. 'view_count': view_count,
  69. 'comment_count': comment_count,
  70. 'duration': duration,
  71. 'thumbnail': thumbnail,
  72. 'uploader': uploader,
  73. 'uploader_id': uploader_id,
  74. }