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