aenetworks.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. smuggle_url,
  6. update_url_query,
  7. unescapeHTML,
  8. extract_attributes,
  9. get_element_by_attribute,
  10. )
  11. from ..compat import (
  12. compat_urlparse,
  13. )
  14. class AENetworksBaseIE(InfoExtractor):
  15. def theplatform_url_result(self, theplatform_url, video_id, query):
  16. return {
  17. '_type': 'url_transparent',
  18. 'id': video_id,
  19. 'url': smuggle_url(
  20. update_url_query(theplatform_url, query),
  21. {
  22. 'sig': {
  23. 'key': 'crazyjava',
  24. 'secret': 's3cr3t'
  25. },
  26. 'force_smil_url': True
  27. }),
  28. 'ie_key': 'ThePlatform',
  29. }
  30. class AENetworksIE(AENetworksBaseIE):
  31. IE_NAME = 'aenetworks'
  32. IE_DESC = 'A+E Networks: A&E, Lifetime, History.com, FYI Network'
  33. _VALID_URL = r'https?://(?:www\.)?(?:(?:history|aetv|mylifetime)\.com|fyi\.tv)/shows/(?P<id>[^/]+(?:/[^/]+){0,2})'
  34. _TESTS = [{
  35. 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1',
  36. 'md5': '8ff93eb073449f151d6b90c0ae1ef0c7',
  37. 'info_dict': {
  38. 'id': '22253814',
  39. 'ext': 'mp4',
  40. 'title': 'Winter Is Coming',
  41. 'description': 'md5:641f424b7a19d8e24f26dea22cf59d74',
  42. 'timestamp': 1338306241,
  43. 'upload_date': '20120529',
  44. 'uploader': 'AENE-NEW',
  45. },
  46. 'add_ie': ['ThePlatform'],
  47. }, {
  48. 'url': 'http://www.history.com/shows/ancient-aliens/season-1',
  49. 'info_dict': {
  50. 'id': '71889446852',
  51. },
  52. 'playlist_mincount': 5,
  53. }, {
  54. 'url': 'http://www.mylifetime.com/shows/atlanta-plastic',
  55. 'info_dict': {
  56. 'id': 'SERIES4317',
  57. 'title': 'Atlanta Plastic',
  58. },
  59. 'playlist_mincount': 2,
  60. }, {
  61. 'url': 'http://www.aetv.com/shows/duck-dynasty/season-9/episode-1',
  62. 'only_matching': True
  63. }, {
  64. 'url': 'http://www.fyi.tv/shows/tiny-house-nation/season-1/episode-8',
  65. 'only_matching': True
  66. }, {
  67. 'url': 'http://www.mylifetime.com/shows/project-runway-junior/season-1/episode-6',
  68. 'only_matching': True
  69. }]
  70. def _real_extract(self, url):
  71. display_id = self._match_id(url)
  72. webpage = self._download_webpage(url, display_id)
  73. url_parts = display_id.split('/')
  74. url_parts_len = len(url_parts)
  75. if url_parts_len == 1:
  76. entries = []
  77. for season_url_path in re.findall(r'(?s)<li[^>]+data-href="(/shows/%s/season-\d+)"' % url_parts[0], webpage):
  78. entries.append(self.url_result(
  79. compat_urlparse.urljoin(url, season_url_path), 'AENetworks'))
  80. return self.playlist_result(
  81. entries, self._html_search_meta('aetn:SeriesId', webpage),
  82. self._html_search_meta('aetn:SeriesTitle', webpage))
  83. elif url_parts_len == 2:
  84. entries = []
  85. for episode_item in re.findall(r'(?s)<div[^>]+class="[^"]*episode-item[^"]*"[^>]*>', webpage):
  86. episode_attributes = extract_attributes(episode_item)
  87. episode_url = compat_urlparse.urljoin(
  88. url, episode_attributes['data-canonical'])
  89. entries.append(self.url_result(
  90. episode_url, 'AENetworks',
  91. episode_attributes['data-videoid']))
  92. return self.playlist_result(
  93. entries, self._html_search_meta('aetn:SeasonId', webpage))
  94. else:
  95. video_id = self._html_search_meta('aetn:VideoID', webpage)
  96. media_url = self._search_regex(
  97. r"media_url\s*=\s*'([^']+)'", webpage, 'video url')
  98. info = self._search_json_ld(webpage, video_id, fatal=False)
  99. info.update(self.theplatform_url_result(
  100. media_url, video_id, {
  101. 'mbr': 'true',
  102. 'assetTypes': 'medium_video_s3'
  103. }))
  104. return info
  105. class HistoryTopicIE(AENetworksBaseIE):
  106. IE_NAME = 'history:topic'
  107. IE_DESC = 'History.com Topic'
  108. _VALID_URL = r'https?://(?:www\.)?history\.com/topics/(?:[^/]+/)?(?P<topic_id>[^/]+)/videos(?:/(?P<display_id>[^/?#]+))?'
  109. _TESTS = [{
  110. 'url': 'http://www.history.com/topics/valentines-day/history-of-valentines-day/videos/bet-you-didnt-know-valentines-day?m=528e394da93ae&s=undefined&f=1&free=false',
  111. 'info_dict': {
  112. 'id': '40700995724',
  113. 'ext': 'mp4',
  114. 'title': "Bet You Didn't Know: Valentine's Day",
  115. 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
  116. 'timestamp': 1375819729,
  117. 'upload_date': '20130806',
  118. 'uploader': 'AENE-NEW',
  119. },
  120. 'params': {
  121. # m3u8 download
  122. 'skip_download': True,
  123. },
  124. 'add_ie': ['ThePlatform'],
  125. }, {
  126. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/videos',
  127. 'info_dict':
  128. {
  129. 'id': 'world-war-i-history',
  130. 'title': 'World War I History',
  131. },
  132. 'playlist_mincount': 24,
  133. }, {
  134. 'url': 'http://www.history.com/topics/world-war-i-history/videos',
  135. 'only_matching': True,
  136. }]
  137. def _real_extract(self, url):
  138. topic_id, display_id = re.match(self._VALID_URL, url).groups()
  139. if display_id:
  140. webpage = self._download_webpage(url, display_id)
  141. release_url, video_id = re.search(r"_videoPlayer.play\('([^']+)'\s*,\s*'[^']+'\s*,\s*'(\d+)'\)", webpage).groups()
  142. release_url = unescapeHTML(release_url)
  143. return self.theplatform_url_result(
  144. release_url, video_id, {
  145. 'mbr': 'true',
  146. 'switch': 'hls'
  147. })
  148. else:
  149. webpage = self._download_webpage(url, topic_id)
  150. entries = []
  151. for episode_item in re.findall(r'<a.+?data-release-url="[^"]+"[^>]*>', webpage):
  152. video_attributes = extract_attributes(episode_item)
  153. entries.append(self.theplatform_url_result(
  154. video_attributes['data-release-url'], video_attributes['data-id'], {
  155. 'mbr': 'true',
  156. 'switch': 'hls'
  157. }))
  158. return self.playlist_result(entries, topic_id, get_element_by_attribute('class', 'show-title', webpage))