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.

75 lines
2.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .turner import TurnerBaseIE
  5. from ..utils import (
  6. int_or_none,
  7. parse_iso8601,
  8. )
  9. class TruTVIE(TurnerBaseIE):
  10. _VALID_URL = r'https?://(?:www\.)?trutv\.com/(?:shows|full-episodes)/(?P<series_slug>[0-9A-Za-z-]+)/(?:videos/(?P<clip_slug>[0-9A-Za-z-]+)|(?P<id>\d+))'
  11. _TEST = {
  12. 'url': 'https://www.trutv.com/shows/the-carbonaro-effect/videos/sunlight-activated-flower.html',
  13. 'info_dict': {
  14. 'id': 'f16c03beec1e84cd7d1a51f11d8fcc29124cc7f1',
  15. 'ext': 'mp4',
  16. 'title': 'Sunlight-Activated Flower',
  17. 'description': "A customer is stunned when he sees Michael's sunlight-activated flower.",
  18. },
  19. 'params': {
  20. # m3u8 download
  21. 'skip_download': True,
  22. },
  23. }
  24. def _real_extract(self, url):
  25. series_slug, clip_slug, video_id = re.match(self._VALID_URL, url).groups()
  26. if video_id:
  27. path = 'episode'
  28. display_id = video_id
  29. else:
  30. path = 'series/clip'
  31. display_id = clip_slug
  32. data = self._download_json(
  33. 'https://api.trutv.com/v2/web/%s/%s/%s' % (path, series_slug, display_id),
  34. display_id)
  35. video_data = data['episode'] if video_id else data['info']
  36. media_id = video_data['mediaId']
  37. title = video_data['title'].strip()
  38. info = self._extract_ngtv_info(
  39. media_id, {}, {
  40. 'url': url,
  41. 'site_name': 'truTV',
  42. 'auth_required': video_data.get('isAuthRequired'),
  43. })
  44. thumbnails = []
  45. for image in video_data.get('images', []):
  46. image_url = image.get('srcUrl')
  47. if not image_url:
  48. continue
  49. thumbnails.append({
  50. 'url': image_url,
  51. 'width': int_or_none(image.get('width')),
  52. 'height': int_or_none(image.get('height')),
  53. })
  54. info.update({
  55. 'id': media_id,
  56. 'display_id': display_id,
  57. 'title': title,
  58. 'description': video_data.get('description'),
  59. 'thumbnails': thumbnails,
  60. 'timestamp': parse_iso8601(video_data.get('publicationDate')),
  61. 'series': video_data.get('showTitle'),
  62. 'season_number': int_or_none(video_data.get('seasonNum')),
  63. 'episode_number': int_or_none(video_data.get('episodeNum')),
  64. })
  65. return info