trutv.py 2.4 KB

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