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.

115 lines
4.5 KiB

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