stitcher.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. ExtractorError,
  7. int_or_none,
  8. str_or_none,
  9. try_get,
  10. )
  11. class StitcherIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?stitcher\.com/(?:podcast|show)/(?:[^/]+/)+e(?:pisode)?/(?:(?P<display_id>[^/#?&]+?)-)?(?P<id>\d+)(?:[/#?&]|$)'
  13. _TESTS = [{
  14. 'url': 'http://www.stitcher.com/podcast/the-talking-machines/e/40789481?autoplay=true',
  15. 'md5': 'e9635098e0da10b21a0e2b85585530f6',
  16. 'info_dict': {
  17. 'id': '40789481',
  18. 'ext': 'mp3',
  19. 'title': 'Machine Learning Mastery and Cancer Clusters',
  20. 'description': 'md5:547adb4081864be114ae3831b4c2b42f',
  21. 'duration': 1604,
  22. 'thumbnail': r're:^https?://.*\.jpg',
  23. 'upload_date': '20180126',
  24. 'timestamp': 1516989316,
  25. },
  26. }, {
  27. 'url': 'http://www.stitcher.com/podcast/panoply/vulture-tv/e/the-rare-hourlong-comedy-plus-40846275?autoplay=true',
  28. 'info_dict': {
  29. 'id': '40846275',
  30. 'display_id': 'the-rare-hourlong-comedy-plus',
  31. 'ext': 'mp3',
  32. 'title': "The CW's 'Crazy Ex-Girlfriend'",
  33. 'description': 'md5:04f1e2f98eb3f5cbb094cea0f9e19b17',
  34. 'duration': 2235,
  35. 'thumbnail': r're:^https?://.*\.jpg',
  36. },
  37. 'params': {
  38. 'skip_download': True,
  39. },
  40. 'skip': 'Page Not Found',
  41. }, {
  42. # escaped title
  43. 'url': 'http://www.stitcher.com/podcast/marketplace-on-stitcher/e/40910226?autoplay=true',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://www.stitcher.com/podcast/panoply/getting-in/e/episode-2a-how-many-extracurriculars-should-i-have-40876278?autoplay=true',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'https://www.stitcher.com/show/threedom/episode/circles-on-a-stick-200212584',
  50. 'only_matching': True,
  51. }]
  52. def _real_extract(self, url):
  53. display_id, audio_id = re.match(self._VALID_URL, url).groups()
  54. resp = self._download_json(
  55. 'https://api.prod.stitcher.com/episode/' + audio_id,
  56. display_id or audio_id)
  57. episode = try_get(resp, lambda x: x['data']['episodes'][0], dict)
  58. if not episode:
  59. raise ExtractorError(resp['errors'][0]['message'], expected=True)
  60. title = episode['title'].strip()
  61. audio_url = episode['audio_url']
  62. thumbnail = None
  63. show_id = episode.get('show_id')
  64. if show_id and episode.get('classic_id') != -1:
  65. thumbnail = 'https://stitcher-classic.imgix.net/feedimages/%s.jpg' % show_id
  66. return {
  67. 'id': audio_id,
  68. 'display_id': display_id,
  69. 'title': title,
  70. 'description': clean_html(episode.get('html_description') or episode.get('description')),
  71. 'duration': int_or_none(episode.get('duration')),
  72. 'thumbnail': thumbnail,
  73. 'url': audio_url,
  74. 'vcodec': 'none',
  75. 'timestamp': int_or_none(episode.get('date_created')),
  76. 'season_number': int_or_none(episode.get('season')),
  77. 'season_id': str_or_none(episode.get('season_id')),
  78. }