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.

89 lines
3.3 KiB

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