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