logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

podomatic.py (2640B)


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