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.

199 lines
7.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .turner import TurnerBaseIE
  5. from ..utils import (
  6. determine_ext,
  7. ExtractorError,
  8. int_or_none,
  9. mimetype2ext,
  10. parse_duration,
  11. parse_iso8601,
  12. qualities,
  13. )
  14. class TeamcocoIE(TurnerBaseIE):
  15. _VALID_URL = r'https?://(?:\w+\.)?teamcoco\.com/(?P<id>([^/]+/)*[^/?#]+)'
  16. _TESTS = [
  17. {
  18. 'url': 'http://teamcoco.com/video/mary-kay-remote',
  19. 'md5': '55d532f81992f5c92046ad02fec34d7d',
  20. 'info_dict': {
  21. 'id': '80187',
  22. 'ext': 'mp4',
  23. 'title': 'Conan Becomes A Mary Kay Beauty Consultant',
  24. 'description': 'Mary Kay is perhaps the most trusted name in female beauty, so of course Conan is a natural choice to sell their products.',
  25. 'duration': 495.0,
  26. 'upload_date': '20140402',
  27. 'timestamp': 1396407600,
  28. }
  29. }, {
  30. 'url': 'http://teamcoco.com/video/louis-ck-interview-george-w-bush',
  31. 'md5': 'cde9ba0fa3506f5f017ce11ead928f9a',
  32. 'info_dict': {
  33. 'id': '19705',
  34. 'ext': 'mp4',
  35. 'description': 'Louis C.K. got starstruck by George W. Bush, so what? Part one.',
  36. 'title': 'Louis C.K. Interview Pt. 1 11/3/11',
  37. 'duration': 288,
  38. 'upload_date': '20111104',
  39. 'timestamp': 1320405840,
  40. }
  41. }, {
  42. 'url': 'http://teamcoco.com/video/timothy-olyphant-drinking-whiskey',
  43. 'info_dict': {
  44. 'id': '88748',
  45. 'ext': 'mp4',
  46. 'title': 'Timothy Olyphant Raises A Toast To “Justified”',
  47. 'description': 'md5:15501f23f020e793aeca761205e42c24',
  48. 'upload_date': '20150415',
  49. 'timestamp': 1429088400,
  50. },
  51. 'params': {
  52. 'skip_download': True, # m3u8 downloads
  53. }
  54. }, {
  55. 'url': 'http://teamcoco.com/video/full-episode-mon-6-1-joel-mchale-jake-tapper-and-musical-guest-courtney-barnett?playlist=x;eyJ0eXBlIjoidGFnIiwiaWQiOjl9',
  56. 'info_dict': {
  57. 'id': '89341',
  58. 'ext': 'mp4',
  59. 'title': 'Full Episode - Mon. 6/1 - Joel McHale, Jake Tapper, And Musical Guest Courtney Barnett',
  60. 'description': 'Guests: Joel McHale, Jake Tapper, And Musical Guest Courtney Barnett',
  61. },
  62. 'params': {
  63. 'skip_download': True, # m3u8 downloads
  64. },
  65. 'skip': 'This video is no longer available.',
  66. }, {
  67. 'url': 'http://teamcoco.com/video/the-conan-audiencey-awards-for-04/25/18',
  68. 'only_matching': True,
  69. }, {
  70. 'url': 'http://teamcoco.com/italy/conan-jordan-schlansky-hit-the-streets-of-florence',
  71. 'only_matching': True,
  72. }, {
  73. 'url': 'http://teamcoco.com/haiti/conan-s-haitian-history-lesson',
  74. 'only_matching': True,
  75. }, {
  76. 'url': 'http://teamcoco.com/israel/conan-hits-the-streets-beaches-of-tel-aviv',
  77. 'only_matching': True,
  78. }, {
  79. 'url': 'https://conan25.teamcoco.com/video/ice-cube-kevin-hart-conan-share-lyft',
  80. 'only_matching': True,
  81. }
  82. ]
  83. def _graphql_call(self, query_template, object_type, object_id):
  84. find_object = 'find' + object_type
  85. return self._download_json(
  86. 'https://teamcoco.com/graphql', object_id, data=json.dumps({
  87. 'query': query_template % (find_object, object_id)
  88. }).encode(), headers={
  89. 'Content-Type': 'application/json',
  90. })['data'][find_object]
  91. def _real_extract(self, url):
  92. display_id = self._match_id(url)
  93. response = self._graphql_call('''{
  94. %s(slug: "%s") {
  95. ... on RecordSlug {
  96. record {
  97. id
  98. title
  99. teaser
  100. publishOn
  101. thumb {
  102. preview
  103. }
  104. file {
  105. url
  106. }
  107. tags {
  108. name
  109. }
  110. duration
  111. turnerMediaId
  112. turnerMediaAuthToken
  113. }
  114. }
  115. ... on NotFoundSlug {
  116. status
  117. }
  118. }
  119. }''', 'Slug', display_id)
  120. if response.get('status'):
  121. raise ExtractorError('This video is no longer available.', expected=True)
  122. record = response['record']
  123. video_id = record['id']
  124. info = {
  125. 'id': video_id,
  126. 'display_id': display_id,
  127. 'title': record['title'],
  128. 'thumbnail': record.get('thumb', {}).get('preview'),
  129. 'description': record.get('teaser'),
  130. 'duration': parse_duration(record.get('duration')),
  131. 'timestamp': parse_iso8601(record.get('publishOn')),
  132. }
  133. media_id = record.get('turnerMediaId')
  134. if media_id:
  135. self._initialize_geo_bypass({
  136. 'countries': ['US'],
  137. })
  138. info.update(self._extract_ngtv_info(media_id, {
  139. 'accessToken': record['turnerMediaAuthToken'],
  140. 'accessTokenType': 'jws',
  141. }))
  142. else:
  143. d = self._download_json(
  144. 'https://teamcoco.com/_truman/d/' + video_id,
  145. video_id, fatal=False) or {}
  146. video_sources = d.get('meta') or {}
  147. if not video_sources:
  148. video_sources = self._graphql_call('''{
  149. %s(id: "%s") {
  150. src
  151. }
  152. }''', 'RecordVideoSource', video_id) or {}
  153. formats = []
  154. get_quality = qualities(['low', 'sd', 'hd', 'uhd'])
  155. for format_id, src in video_sources.get('src', {}).items():
  156. if not isinstance(src, dict):
  157. continue
  158. src_url = src.get('src')
  159. if not src_url:
  160. continue
  161. ext = determine_ext(src_url, mimetype2ext(src.get('type')))
  162. if format_id == 'hls' or ext == 'm3u8':
  163. # compat_urllib_parse.urljoin does not work here
  164. if src_url.startswith('/'):
  165. src_url = 'http://ht.cdn.turner.com/tbs/big/teamcoco' + src_url
  166. formats.extend(self._extract_m3u8_formats(
  167. src_url, video_id, 'mp4', m3u8_id=format_id, fatal=False))
  168. else:
  169. if src_url.startswith('/mp4:protected/'):
  170. # TODO Correct extraction for these files
  171. continue
  172. tbr = int_or_none(self._search_regex(
  173. r'(\d+)k\.mp4', src_url, 'tbr', default=None))
  174. formats.append({
  175. 'url': src_url,
  176. 'ext': ext,
  177. 'tbr': tbr,
  178. 'format_id': format_id,
  179. 'quality': get_quality(format_id),
  180. })
  181. if not formats:
  182. formats = self._extract_m3u8_formats(
  183. record['file']['url'], video_id, 'mp4', fatal=False)
  184. self._sort_formats(formats)
  185. info['formats'] = formats
  186. return info