ndtv.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import urllib.parse
  2. from .common import InfoExtractor
  3. from ..utils import parse_duration, remove_end, unified_strdate, urljoin
  4. class NDTVIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:[^/]+\.)?ndtv\.com/(?:[^/]+/)*videos?/?(?:[^/]+/)*[^/?^&]+-(?P<id>\d+)'
  6. _TESTS = [
  7. {
  8. 'url': 'https://khabar.ndtv.com/video/show/prime-time/prime-time-ill-system-and-poor-education-468818',
  9. 'md5': '78efcf3880ef3fd9b83d405ca94a38eb',
  10. 'info_dict': {
  11. 'id': '468818',
  12. 'ext': 'mp4',
  13. 'title': "प्राइम टाइम: सिस्टम बीमार, स्कूल बदहाल",
  14. 'description': 'md5:f410512f1b49672e5695dea16ef2731d',
  15. 'upload_date': '20170928',
  16. 'duration': 2218,
  17. 'thumbnail': r're:https?://.*\.jpg',
  18. }
  19. },
  20. {
  21. # __filename is url
  22. 'url': 'http://movies.ndtv.com/videos/cracker-free-diwali-wishes-from-karan-johar-kriti-sanon-other-stars-470304',
  23. 'md5': 'f1d709352305b44443515ac56b45aa46',
  24. 'info_dict': {
  25. 'id': '470304',
  26. 'ext': 'mp4',
  27. 'title': "Cracker-Free Diwali Wishes From Karan Johar, Kriti Sanon & Other Stars",
  28. 'description': 'md5:f115bba1adf2f6433fa7c1ade5feb465',
  29. 'upload_date': '20171019',
  30. 'duration': 137,
  31. 'thumbnail': r're:https?://.*\.jpg',
  32. }
  33. },
  34. {
  35. 'url': 'https://www.ndtv.com/video/news/news/delhi-s-air-quality-status-report-after-diwali-is-very-poor-470372',
  36. 'only_matching': True
  37. },
  38. {
  39. 'url': 'https://auto.ndtv.com/videos/the-cnb-daily-october-13-2017-469935',
  40. 'only_matching': True
  41. },
  42. {
  43. 'url': 'https://sports.ndtv.com/cricket/videos/2nd-t20i-rock-thrown-at-australia-cricket-team-bus-after-win-over-india-469764',
  44. 'only_matching': True
  45. },
  46. {
  47. 'url': 'http://gadgets.ndtv.com/videos/uncharted-the-lost-legacy-review-465568',
  48. 'only_matching': True
  49. },
  50. {
  51. 'url': 'http://profit.ndtv.com/videos/news/video-indian-economy-on-very-solid-track-international-monetary-fund-chief-470040',
  52. 'only_matching': True
  53. },
  54. {
  55. 'url': 'http://food.ndtv.com/video-basil-seeds-coconut-porridge-419083',
  56. 'only_matching': True
  57. },
  58. {
  59. 'url': 'https://doctor.ndtv.com/videos/top-health-stories-of-the-week-467396',
  60. 'only_matching': True
  61. },
  62. {
  63. 'url': 'https://swirlster.ndtv.com/video/how-to-make-friends-at-work-469324',
  64. 'only_matching': True
  65. }
  66. ]
  67. def _real_extract(self, url):
  68. video_id = self._match_id(url)
  69. webpage = self._download_webpage(url, video_id)
  70. # '__title' does not contain extra words such as sub-site name, "Video" etc.
  71. title = urllib.parse.unquote_plus(
  72. self._search_regex(r"__title\s*=\s*'([^']+)'", webpage, 'title', default=None)
  73. or self._og_search_title(webpage))
  74. filename = self._search_regex(
  75. r"(?:__)?filename\s*[:=]\s*'([^']+)'", webpage, 'video filename')
  76. # in "movies" sub-site pages, filename is URL
  77. video_url = urljoin('https://ndtvod.bc-ssl.cdn.bitgravity.com/23372/ndtv/', filename.lstrip('/'))
  78. # "doctor" sub-site has MM:SS format
  79. duration = parse_duration(self._search_regex(
  80. r"(?:__)?duration\s*[:=]\s*'([^']+)'", webpage, 'duration', fatal=False))
  81. # "sports", "doctor", "swirlster" sub-sites don't have 'publish-date'
  82. upload_date = unified_strdate(self._html_search_meta(
  83. 'publish-date', webpage, 'upload date', default=None) or self._html_search_meta(
  84. 'uploadDate', webpage, 'upload date', default=None) or self._search_regex(
  85. r'datePublished"\s*:\s*"([^"]+)"', webpage, 'upload date', fatal=False))
  86. description = remove_end(self._og_search_description(webpage), ' (Read more)')
  87. return {
  88. 'id': video_id,
  89. 'url': video_url,
  90. 'title': title,
  91. 'description': description,
  92. 'thumbnail': self._og_search_thumbnail(webpage),
  93. 'duration': duration,
  94. 'upload_date': upload_date,
  95. }