podomatic.py 2.5 KB

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