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.

69 lines
2.3 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class PodomaticIE(InfoExtractor):
  7. IE_NAME = 'podomatic'
  8. _VALID_URL = r'^(?P<proto>https?)://(?P<channel>[^.]+)\.podomatic\.com/entry/(?P<id>[^?]+)'
  9. _TESTS = [
  10. {
  11. 'url': 'http://scienceteachingtips.podomatic.com/entry/2009-01-02T16_03_35-08_00',
  12. 'md5': '84bb855fcf3429e6bf72460e1eed782d',
  13. 'info_dict': {
  14. 'id': '2009-01-02T16_03_35-08_00',
  15. 'ext': 'mp3',
  16. 'uploader': 'Science Teaching Tips',
  17. 'uploader_id': 'scienceteachingtips',
  18. 'title': '64. When the Moon Hits Your Eye',
  19. 'duration': 446,
  20. }
  21. },
  22. {
  23. 'url': 'http://ostbahnhof.podomatic.com/entry/2013-11-15T16_31_21-08_00',
  24. 'md5': 'd2cf443931b6148e27638650e2638297',
  25. 'info_dict': {
  26. 'id': '2013-11-15T16_31_21-08_00',
  27. 'ext': 'mp3',
  28. 'uploader': 'Ostbahnhof / Techno Mix',
  29. 'uploader_id': 'ostbahnhof',
  30. 'title': 'Einunddreizig',
  31. 'duration': 3799,
  32. }
  33. },
  34. ]
  35. def _real_extract(self, url):
  36. mobj = re.match(self._VALID_URL, url)
  37. video_id = mobj.group('id')
  38. channel = mobj.group('channel')
  39. json_url = (('%s://%s.podomatic.com/entry/embed_params/%s' +
  40. '?permalink=true&rtmp=0') %
  41. (mobj.group('proto'), channel, video_id))
  42. data_json = self._download_webpage(
  43. json_url, video_id, 'Downloading video info')
  44. data = json.loads(data_json)
  45. video_url = data['downloadLink']
  46. if not video_url:
  47. video_url = '%s/%s' % (data['streamer'].replace('rtmp', 'http'), data['mediaLocation'])
  48. uploader = data['podcast']
  49. title = data['title']
  50. thumbnail = data['imageLocation']
  51. duration = int_or_none(data.get('length'), 1000)
  52. return {
  53. 'id': video_id,
  54. 'url': video_url,
  55. 'title': title,
  56. 'uploader': uploader,
  57. 'uploader_id': channel,
  58. 'thumbnail': thumbnail,
  59. 'duration': duration,
  60. }