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