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.

88 lines
3.0 KiB

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