tbs.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import re
  2. import urllib.parse
  3. from .turner import TurnerBaseIE
  4. from ..utils import (
  5. float_or_none,
  6. int_or_none,
  7. strip_or_none,
  8. )
  9. class TBSIE(TurnerBaseIE):
  10. _VALID_URL = r'https?://(?:www\.)?(?P<site>tbs|tntdrama)\.com(?P<path>/(?:movies|watchtnt|watchtbs|shows/[^/]+/(?:clips|season-\d+/episode-\d+))/(?P<id>[^/?#]+))'
  11. _TESTS = [{
  12. 'url': 'http://www.tntdrama.com/shows/the-alienist/clips/monster',
  13. 'info_dict': {
  14. 'id': '8d384cde33b89f3a43ce5329de42903ed5099887',
  15. 'ext': 'mp4',
  16. 'title': 'Monster',
  17. 'description': 'Get a first look at the theatrical trailer for TNT’s highly anticipated new psychological thriller The Alienist, which premieres January 22 on TNT.',
  18. 'timestamp': 1508175329,
  19. 'upload_date': '20171016',
  20. },
  21. 'params': {
  22. # m3u8 download
  23. 'skip_download': True,
  24. },
  25. }, {
  26. 'url': 'http://www.tbs.com/shows/search-party/season-1/episode-1/explicit-the-mysterious-disappearance-of-the-girl-no-one-knew',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'http://www.tntdrama.com/movies/star-wars-a-new-hope',
  30. 'only_matching': True,
  31. }]
  32. def _real_extract(self, url):
  33. site, path, display_id = self._match_valid_url(url).groups()
  34. webpage = self._download_webpage(url, display_id)
  35. drupal_settings = self._parse_json(self._search_regex(
  36. r'<script[^>]+?data-drupal-selector="drupal-settings-json"[^>]*?>({.+?})</script>',
  37. webpage, 'drupal setting'), display_id)
  38. is_live = 'watchtnt' in path or 'watchtbs' in path
  39. video_data = next(v for v in drupal_settings['turner_playlist'] if is_live or v.get('url') == path)
  40. media_id = video_data['mediaID']
  41. title = video_data['title']
  42. tokenizer_query = urllib.parse.parse_qs(urllib.parse.urlparse(
  43. drupal_settings['ngtv_token_url']).query)
  44. info = self._extract_ngtv_info(
  45. media_id, tokenizer_query, {
  46. 'url': url,
  47. 'site_name': site[:3].upper(),
  48. 'auth_required': video_data.get('authRequired') == '1' or is_live,
  49. 'is_live': is_live,
  50. })
  51. thumbnails = []
  52. for image_id, image in video_data.get('images', {}).items():
  53. image_url = image.get('url')
  54. if not image_url or image.get('type') != 'video':
  55. continue
  56. i = {
  57. 'id': image_id,
  58. 'url': image_url,
  59. }
  60. mobj = re.search(r'(\d+)x(\d+)', image_url)
  61. if mobj:
  62. i.update({
  63. 'width': int(mobj.group(1)),
  64. 'height': int(mobj.group(2)),
  65. })
  66. thumbnails.append(i)
  67. info.update({
  68. 'id': media_id,
  69. 'title': title,
  70. 'description': strip_or_none(video_data.get('descriptionNoTags') or video_data.get('shortDescriptionNoTags')),
  71. 'duration': float_or_none(video_data.get('duration')) or info.get('duration'),
  72. 'timestamp': int_or_none(video_data.get('created')),
  73. 'season_number': int_or_none(video_data.get('season')),
  74. 'episode_number': int_or_none(video_data.get('episode')),
  75. 'thumbnails': thumbnails,
  76. 'is_live': is_live,
  77. })
  78. return info