unscripted.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from .common import InfoExtractor
  2. from ..utils import parse_duration, traverse_obj
  3. class UnscriptedNewsVideoIE(InfoExtractor):
  4. _VALID_URL = r'https?://www\.unscripted\.news/videos/(?P<id>[\w-]+)'
  5. _TESTS = [{
  6. 'url': 'https://www.unscripted.news/videos/a-day-at-the-farmers-protest',
  7. 'info_dict': {
  8. 'id': '60c0a55cd1e99b1079918a57',
  9. 'display_id': 'a-day-at-the-farmers-protest',
  10. 'ext': 'mp4',
  11. 'title': 'A Day at the Farmers\' Protest',
  12. 'description': 'md5:4b3df22747a03e8f14f746dd72190384',
  13. 'thumbnail': 'https://s3.unscripted.news/anj2/60c0a55cd1e99b1079918a57/5f199a65-c803-4a5c-8fce-2077359c3b72.jpg',
  14. 'duration': 2251.0,
  15. 'series': 'Ground Reports',
  16. }
  17. }, {
  18. 'url': 'https://www.unscripted.news/videos/you-get-the-politicians-you-deserve-ft-shashi-tharoor',
  19. 'info_dict': {
  20. 'id': '5fb3afbf18ac817d341a74d8',
  21. 'display_id': 'you-get-the-politicians-you-deserve-ft-shashi-tharoor',
  22. 'ext': 'mp4',
  23. 'cast': ['Avalok Langer', 'Ashwin Mehta'],
  24. 'thumbnail': 'https://s3.unscripted.news/anj2/5fb3afbf18ac817d341a74d8/82bd7942-4f20-4cd8-98ae-83f9e814f998.jpg',
  25. 'description': 'md5:1e91b069238a705ca3a40f87e6f1182c',
  26. 'duration': 1046.0,
  27. 'series': 'Dumb Questions Only',
  28. 'title': 'You Get The Politicians You Deserve! ft. Shashi Tharoor',
  29. }
  30. }]
  31. def _real_extract(self, url):
  32. display_id = self._match_id(url)
  33. webpage = self._download_webpage(url, display_id)
  34. nextjs_data = self._search_nextjs_data(webpage, display_id)['props']['pageProps']['dataLocal']
  35. # TODO: get subtitle from srt key
  36. formats, subtitles = self._extract_m3u8_formats_and_subtitles(nextjs_data['alt_content'], display_id)
  37. return {
  38. 'id': nextjs_data['_id'],
  39. 'display_id': display_id,
  40. 'title': nextjs_data.get('title') or self._og_search_title(webpage),
  41. 'description': nextjs_data.get('sh_heading') or self._og_search_description(webpage),
  42. 'formats': formats,
  43. 'subtitles': subtitles,
  44. 'thumbnail': self._og_search_thumbnail(webpage),
  45. 'duration': parse_duration(nextjs_data.get('duration')),
  46. 'series': traverse_obj(nextjs_data, ('show', 'topic')),
  47. 'cast': traverse_obj(nextjs_data, ('cast_crew', ..., 'displayname')),
  48. }