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