logo

youtube-dl

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

viewlift.py (9992B)


  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_HTTPError
  6. from ..utils import (
  7. ExtractorError,
  8. int_or_none,
  9. parse_age_limit,
  10. )
  11. class ViewLiftBaseIE(InfoExtractor):
  12. _API_BASE = 'https://prod-api.viewlift.com/'
  13. _DOMAINS_REGEX = r'(?:(?:main\.)?snagfilms|snagxtreme|funnyforfree|kiddovid|winnersview|(?:monumental|lax)sportsnetwork|vayafilm|failarmy|ftfnext|lnppass\.legapallacanestro|moviespree|app\.myoutdoortv|neoufitness|pflmma|theidentitytb)\.com|(?:hoichoi|app\.horseandcountry|kronon|marquee|supercrosslive)\.tv'
  14. _SITE_MAP = {
  15. 'ftfnext': 'lax',
  16. 'funnyforfree': 'snagfilms',
  17. 'hoichoi': 'hoichoitv',
  18. 'kiddovid': 'snagfilms',
  19. 'laxsportsnetwork': 'lax',
  20. 'legapallacanestro': 'lnp',
  21. 'marquee': 'marquee-tv',
  22. 'monumentalsportsnetwork': 'monumental-network',
  23. 'moviespree': 'bingeflix',
  24. 'pflmma': 'pfl',
  25. 'snagxtreme': 'snagfilms',
  26. 'theidentitytb': 'tampabay',
  27. 'vayafilm': 'snagfilms',
  28. }
  29. _TOKENS = {}
  30. def _call_api(self, site, path, video_id, query):
  31. token = self._TOKENS.get(site)
  32. if not token:
  33. token_query = {'site': site}
  34. email, password = self._get_login_info(netrc_machine=site)
  35. if email:
  36. resp = self._download_json(
  37. self._API_BASE + 'identity/signin', video_id,
  38. 'Logging in', query=token_query, data=json.dumps({
  39. 'email': email,
  40. 'password': password,
  41. }).encode())
  42. else:
  43. resp = self._download_json(
  44. self._API_BASE + 'identity/anonymous-token', video_id,
  45. 'Downloading authorization token', query=token_query)
  46. self._TOKENS[site] = token = resp['authorizationToken']
  47. return self._download_json(
  48. self._API_BASE + path, video_id,
  49. headers={'Authorization': token}, query=query)
  50. class ViewLiftEmbedIE(ViewLiftBaseIE):
  51. IE_NAME = 'viewlift:embed'
  52. _VALID_URL = r'https?://(?:(?:www|embed)\.)?(?P<domain>%s)/embed/player\?.*\bfilmId=(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})' % ViewLiftBaseIE._DOMAINS_REGEX
  53. _TESTS = [{
  54. 'url': 'http://embed.snagfilms.com/embed/player?filmId=74849a00-85a9-11e1-9660-123139220831&w=500',
  55. 'md5': '2924e9215c6eff7a55ed35b72276bd93',
  56. 'info_dict': {
  57. 'id': '74849a00-85a9-11e1-9660-123139220831',
  58. 'ext': 'mp4',
  59. 'title': '#whilewewatch',
  60. 'description': 'md5:b542bef32a6f657dadd0df06e26fb0c8',
  61. 'timestamp': 1334350096,
  62. 'upload_date': '20120413',
  63. }
  64. }, {
  65. # invalid labels, 360p is better that 480p
  66. 'url': 'http://www.snagfilms.com/embed/player?filmId=17ca0950-a74a-11e0-a92a-0026bb61d036',
  67. 'md5': '882fca19b9eb27ef865efeeaed376a48',
  68. 'info_dict': {
  69. 'id': '17ca0950-a74a-11e0-a92a-0026bb61d036',
  70. 'ext': 'mp4',
  71. 'title': 'Life in Limbo',
  72. },
  73. 'skip': 'The video does not exist',
  74. }, {
  75. 'url': 'http://www.snagfilms.com/embed/player?filmId=0000014c-de2f-d5d6-abcf-ffef58af0017',
  76. 'only_matching': True,
  77. }]
  78. @staticmethod
  79. def _extract_url(webpage):
  80. mobj = re.search(
  81. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:embed\.)?(?:%s)/embed/player.+?)\1' % ViewLiftBaseIE._DOMAINS_REGEX,
  82. webpage)
  83. if mobj:
  84. return mobj.group('url')
  85. def _real_extract(self, url):
  86. domain, film_id = re.match(self._VALID_URL, url).groups()
  87. site = domain.split('.')[-2]
  88. if site in self._SITE_MAP:
  89. site = self._SITE_MAP[site]
  90. try:
  91. content_data = self._call_api(
  92. site, 'entitlement/video/status', film_id, {
  93. 'id': film_id
  94. })['video']
  95. except ExtractorError as e:
  96. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
  97. error_message = self._parse_json(e.cause.read().decode(), film_id).get('errorMessage')
  98. if error_message == 'User does not have a valid subscription or has not purchased this content.':
  99. self.raise_login_required()
  100. raise ExtractorError(error_message, expected=True)
  101. raise
  102. gist = content_data['gist']
  103. title = gist['title']
  104. video_assets = content_data['streamingInfo']['videoAssets']
  105. formats = []
  106. mpeg_video_assets = video_assets.get('mpeg') or []
  107. for video_asset in mpeg_video_assets:
  108. video_asset_url = video_asset.get('url')
  109. if not video_asset:
  110. continue
  111. bitrate = int_or_none(video_asset.get('bitrate'))
  112. height = int_or_none(self._search_regex(
  113. r'^_?(\d+)[pP]$', video_asset.get('renditionValue'),
  114. 'height', default=None))
  115. formats.append({
  116. 'url': video_asset_url,
  117. 'format_id': 'http%s' % ('-%d' % bitrate if bitrate else ''),
  118. 'tbr': bitrate,
  119. 'height': height,
  120. 'vcodec': video_asset.get('codec'),
  121. })
  122. hls_url = video_assets.get('hls')
  123. if hls_url:
  124. formats.extend(self._extract_m3u8_formats(
  125. hls_url, film_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  126. self._sort_formats(formats, ('height', 'tbr', 'format_id'))
  127. info = {
  128. 'id': film_id,
  129. 'title': title,
  130. 'description': gist.get('description'),
  131. 'thumbnail': gist.get('videoImageUrl'),
  132. 'duration': int_or_none(gist.get('runtime')),
  133. 'age_limit': parse_age_limit(content_data.get('parentalRating')),
  134. 'timestamp': int_or_none(gist.get('publishDate'), 1000),
  135. 'formats': formats,
  136. }
  137. for k in ('categories', 'tags'):
  138. info[k] = [v['title'] for v in content_data.get(k, []) if v.get('title')]
  139. return info
  140. class ViewLiftIE(ViewLiftBaseIE):
  141. IE_NAME = 'viewlift'
  142. _VALID_URL = r'https?://(?:www\.)?(?P<domain>%s)(?P<path>(?:/(?:films/title|show|(?:news/)?videos?|watch))?/(?P<id>[^?#]+))' % ViewLiftBaseIE._DOMAINS_REGEX
  143. _TESTS = [{
  144. 'url': 'http://www.snagfilms.com/films/title/lost_for_life',
  145. 'md5': '19844f897b35af219773fd63bdec2942',
  146. 'info_dict': {
  147. 'id': '0000014c-de2f-d5d6-abcf-ffef58af0017',
  148. 'display_id': 'lost_for_life',
  149. 'ext': 'mp4',
  150. 'title': 'Lost for Life',
  151. 'description': 'md5:ea10b5a50405ae1f7b5269a6ec594102',
  152. 'thumbnail': r're:^https?://.*\.jpg',
  153. 'duration': 4489,
  154. 'categories': 'mincount:3',
  155. 'age_limit': 14,
  156. 'upload_date': '20150421',
  157. 'timestamp': 1429656820,
  158. }
  159. }, {
  160. 'url': 'http://www.snagfilms.com/show/the_world_cut_project/india',
  161. 'md5': 'e6292e5b837642bbda82d7f8bf3fbdfd',
  162. 'info_dict': {
  163. 'id': '00000145-d75c-d96e-a9c7-ff5c67b20000',
  164. 'display_id': 'the_world_cut_project/india',
  165. 'ext': 'mp4',
  166. 'title': 'India',
  167. 'description': 'md5:5c168c5a8f4719c146aad2e0dfac6f5f',
  168. 'thumbnail': r're:^https?://.*\.jpg',
  169. 'duration': 979,
  170. 'timestamp': 1399478279,
  171. 'upload_date': '20140507',
  172. }
  173. }, {
  174. 'url': 'http://main.snagfilms.com/augie_alone/s_2_ep_12_love',
  175. 'info_dict': {
  176. 'id': '00000148-7b53-de26-a9fb-fbf306f70020',
  177. 'display_id': 'augie_alone/s_2_ep_12_love',
  178. 'ext': 'mp4',
  179. 'title': 'S. 2 Ep. 12 - Love',
  180. 'description': 'Augie finds love.',
  181. 'thumbnail': r're:^https?://.*\.jpg',
  182. 'duration': 107,
  183. 'upload_date': '20141012',
  184. 'timestamp': 1413129540,
  185. 'age_limit': 17,
  186. },
  187. 'params': {
  188. 'skip_download': True,
  189. },
  190. }, {
  191. 'url': 'http://main.snagfilms.com/films/title/the_freebie',
  192. 'only_matching': True,
  193. }, {
  194. # Film is not playable in your area.
  195. 'url': 'http://www.snagfilms.com/films/title/inside_mecca',
  196. 'only_matching': True,
  197. }, {
  198. # Film is not available.
  199. 'url': 'http://www.snagfilms.com/show/augie_alone/flirting',
  200. 'only_matching': True,
  201. }, {
  202. 'url': 'http://www.winnersview.com/videos/the-good-son',
  203. 'only_matching': True,
  204. }, {
  205. # Was once Kaltura embed
  206. 'url': 'https://www.monumentalsportsnetwork.com/videos/john-carlson-postgame-2-25-15',
  207. 'only_matching': True,
  208. }, {
  209. 'url': 'https://www.marquee.tv/watch/sadlerswells-sacredmonsters',
  210. 'only_matching': True,
  211. }]
  212. @classmethod
  213. def suitable(cls, url):
  214. return False if ViewLiftEmbedIE.suitable(url) else super(ViewLiftIE, cls).suitable(url)
  215. def _real_extract(self, url):
  216. domain, path, display_id = re.match(self._VALID_URL, url).groups()
  217. site = domain.split('.')[-2]
  218. if site in self._SITE_MAP:
  219. site = self._SITE_MAP[site]
  220. modules = self._call_api(
  221. site, 'content/pages', display_id, {
  222. 'includeContent': 'true',
  223. 'moduleOffset': 1,
  224. 'path': path,
  225. 'site': site,
  226. })['modules']
  227. film_id = next(m['contentData'][0]['gist']['id'] for m in modules if m.get('moduleType') == 'VideoDetailModule')
  228. return {
  229. '_type': 'url_transparent',
  230. 'url': 'http://%s/embed/player?filmId=%s' % (domain, film_id),
  231. 'id': film_id,
  232. 'display_id': display_id,
  233. 'ie_key': 'ViewLiftEmbed',
  234. }