From 093717a750b22310b7ec573da109930e9c9e76bd Mon Sep 17 00:00:00 2001 From: rawcoder Date: Wed, 18 Oct 2017 17:38:00 +0530 Subject: [PATCH 1/4] [NDTV] Added support for sub-sites (gadgets,khabar,profit) --- youtube_dl/extractor/ndtv.py | 81 ++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 17 deletions(-) diff --git a/youtube_dl/extractor/ndtv.py b/youtube_dl/extractor/ndtv.py index 255f60878..683b39501 100644 --- a/youtube_dl/extractor/ndtv.py +++ b/youtube_dl/extractor/ndtv.py @@ -1,6 +1,10 @@ +# coding: utf-8 from __future__ import unicode_literals from .common import InfoExtractor +from ..compat import ( + compat_urllib_parse_unquote_plus +) from ..utils import ( int_or_none, remove_end, @@ -9,34 +13,77 @@ from ..utils import ( class NDTVIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?ndtv\.com/video/(?:[^/]+/)+[^/?^&]+-(?P\d+)' + _VALID_URL = r'https?://(?:(?:www|gadgets|khabar|profit)\.)?ndtv\.com/videos?/(?:[^/]+/)*[^/?^&]+-(?P\d+)' - _TEST = { - 'url': 'http://www.ndtv.com/video/news/news/ndtv-exclusive-don-t-need-character-certificate-from-rahul-gandhi-says-arvind-kejriwal-300710', - 'md5': '39f992dbe5fb531c395d8bbedb1e5e88', - 'info_dict': { - 'id': '300710', - 'ext': 'mp4', - 'title': "NDTV exclusive: Don't need character certificate from Rahul Gandhi, says Arvind Kejriwal", - 'description': 'md5:ab2d4b4a6056c5cb4caa6d729deabf02', - 'upload_date': '20131208', - 'duration': 1327, - 'thumbnail': r're:https?://.*\.jpg', + _TESTS = [ + { + 'url': 'http://www.ndtv.com/video/news/news/ndtv-exclusive-don-t-need-character-certificate-from-rahul-gandhi-says-arvind-kejriwal-300710', + 'md5': '39f992dbe5fb531c395d8bbedb1e5e88', + 'info_dict': { + 'id': '300710', + 'ext': 'mp4', + 'title': "NDTV exclusive: Don't need character certificate from Rahul Gandhi, says Arvind Kejriwal", + 'description': 'md5:ab2d4b4a6056c5cb4caa6d729deabf02', + 'upload_date': '20131208', + 'duration': 1327, + 'thumbnail': r're:https?://.*\.jpg', + }, }, - } + { + 'url': 'http://gadgets.ndtv.com/videos/uncharted-the-lost-legacy-review-465568', + 'md5': '1169bb2c0b288d65da4f4832a32e4489', + 'info_dict': { + 'id': '465568', + 'ext': 'mp4', + 'title': "Uncharted: The Lost Legacy Review", + 'description': 'md5:f8299743bc50c4cbd0dd307a3830fcb0', + 'upload_date': '20170816', + 'duration': 168, + 'thumbnail': r're:https?://.*\.jpg', + } + }, + { + 'url': 'https://khabar.ndtv.com/video/show/prime-time/prime-time-ill-system-and-poor-education-468818', + 'md5': '78efcf3880ef3fd9b83d405ca94a38eb', + 'info_dict': { + 'id': '468818', + 'ext': 'mp4', + 'title': "प्राइम टाइम: सिस्टम बीमार, स्कूल बदहाल", + 'description': 'md5:f410512f1b49672e5695dea16ef2731d', + 'upload_date': '20170928', + 'duration': 2218, + 'thumbnail': r're:https?://.*\.jpg', + } + }, + { + 'url': 'http://profit.ndtv.com/videos/news/video-indian-economy-on-very-solid-track-international-monetary-fund-chief-470040', + 'md5': '16f192bb61ae8721770ca82554a125e6', + 'info_dict': { + 'id': '470040', + 'ext': 'mp4', + 'title': "Indian Economy On 'Very Solid Track': International Monetary Fund Chief", + 'description': 'md5:e84e6b93a9ece5573df6344626fb6df7', + 'upload_date': '20171015', + 'duration': 137, + 'thumbnail': r're:https?://.*\.jpg', + } + } + ] def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) - title = remove_end(self._og_search_title(webpage), ' - NDTV') + title = compat_urllib_parse_unquote_plus( + self._search_regex(r"__title\s*=\s*'([^']+)'", webpage, 'title') or + self._og_search_title(webpage)) filename = self._search_regex( - r"__filename='([^']+)'", webpage, 'video filename') - video_url = 'http://bitcast-b.bitgravity.com/ndtvod/23372/ndtv/%s' % filename + r"__filename\s*=\s*'([^']+)'", webpage, 'video filename') + video_url = 'https://ndtvod.bc-ssl.cdn.bitgravity.com/23372/ndtv/%s' % filename duration = int_or_none(self._search_regex( - r"__duration='([^']+)'", webpage, 'duration', fatal=False)) + r"__duration\s*=\s*'([^']+)'", webpage, 'duration', fatal=False)) upload_date = unified_strdate(self._html_search_meta( 'publish-date', webpage, 'upload date', fatal=False)) From 49a53a389f1d87bd75e9821b2075f13579f02fb1 Mon Sep 17 00:00:00 2001 From: rawcoder Date: Thu, 19 Oct 2017 01:11:21 +0530 Subject: [PATCH 2/4] [NDTV] Removed duplicate test cases --- youtube_dl/extractor/ndtv.py | 68 +++++++----------------------------- 1 file changed, 13 insertions(+), 55 deletions(-) diff --git a/youtube_dl/extractor/ndtv.py b/youtube_dl/extractor/ndtv.py index 683b39501..1f624221a 100644 --- a/youtube_dl/extractor/ndtv.py +++ b/youtube_dl/extractor/ndtv.py @@ -15,68 +15,26 @@ from ..utils import ( class NDTVIE(InfoExtractor): _VALID_URL = r'https?://(?:(?:www|gadgets|khabar|profit)\.)?ndtv\.com/videos?/(?:[^/]+/)*[^/?^&]+-(?P\d+)' - _TESTS = [ - { - 'url': 'http://www.ndtv.com/video/news/news/ndtv-exclusive-don-t-need-character-certificate-from-rahul-gandhi-says-arvind-kejriwal-300710', - 'md5': '39f992dbe5fb531c395d8bbedb1e5e88', - 'info_dict': { - 'id': '300710', - 'ext': 'mp4', - 'title': "NDTV exclusive: Don't need character certificate from Rahul Gandhi, says Arvind Kejriwal", - 'description': 'md5:ab2d4b4a6056c5cb4caa6d729deabf02', - 'upload_date': '20131208', - 'duration': 1327, - 'thumbnail': r're:https?://.*\.jpg', - }, - }, - { - 'url': 'http://gadgets.ndtv.com/videos/uncharted-the-lost-legacy-review-465568', - 'md5': '1169bb2c0b288d65da4f4832a32e4489', - 'info_dict': { - 'id': '465568', - 'ext': 'mp4', - 'title': "Uncharted: The Lost Legacy Review", - 'description': 'md5:f8299743bc50c4cbd0dd307a3830fcb0', - 'upload_date': '20170816', - 'duration': 168, - 'thumbnail': r're:https?://.*\.jpg', - } - }, - { - 'url': 'https://khabar.ndtv.com/video/show/prime-time/prime-time-ill-system-and-poor-education-468818', - 'md5': '78efcf3880ef3fd9b83d405ca94a38eb', - 'info_dict': { - 'id': '468818', - 'ext': 'mp4', - 'title': "प्राइम टाइम: सिस्टम बीमार, स्कूल बदहाल", - 'description': 'md5:f410512f1b49672e5695dea16ef2731d', - 'upload_date': '20170928', - 'duration': 2218, - 'thumbnail': r're:https?://.*\.jpg', - } - }, - { - 'url': 'http://profit.ndtv.com/videos/news/video-indian-economy-on-very-solid-track-international-monetary-fund-chief-470040', - 'md5': '16f192bb61ae8721770ca82554a125e6', - 'info_dict': { - 'id': '470040', - 'ext': 'mp4', - 'title': "Indian Economy On 'Very Solid Track': International Monetary Fund Chief", - 'description': 'md5:e84e6b93a9ece5573df6344626fb6df7', - 'upload_date': '20171015', - 'duration': 137, - 'thumbnail': r're:https?://.*\.jpg', - } + _TEST = { + 'url': 'http://www.ndtv.com/video/news/news/ndtv-exclusive-don-t-need-character-certificate-from-rahul-gandhi-says-arvind-kejriwal-300710', + 'md5': '39f992dbe5fb531c395d8bbedb1e5e88', + 'info_dict': { + 'id': '300710', + 'ext': 'mp4', + 'title': "NDTV exclusive: Don't need character certificate from Rahul Gandhi, says Arvind Kejriwal", + 'description': 'md5:ab2d4b4a6056c5cb4caa6d729deabf02', + 'upload_date': '20131208', + 'duration': 1327, + 'thumbnail': r're:https?://.*\.jpg', } - ] + } def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) title = compat_urllib_parse_unquote_plus( - self._search_regex(r"__title\s*=\s*'([^']+)'", webpage, 'title') or - self._og_search_title(webpage)) + self._search_regex(r"__title\s*=\s*'([^']+)'", webpage, 'title')) filename = self._search_regex( r"__filename\s*=\s*'([^']+)'", webpage, 'video filename') From ada98a4dbcad8d9369b7243288e2a0c19b4595f9 Mon Sep 17 00:00:00 2001 From: rawcoder Date: Fri, 20 Oct 2017 18:06:50 +0530 Subject: [PATCH 3/4] [NDTV] Added support for more sub-sites (food,sports,auto,doctor,movies,swirlster) --- youtube_dl/extractor/ndtv.py | 96 ++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 20 deletions(-) diff --git a/youtube_dl/extractor/ndtv.py b/youtube_dl/extractor/ndtv.py index 1f624221a..2d6a1602c 100644 --- a/youtube_dl/extractor/ndtv.py +++ b/youtube_dl/extractor/ndtv.py @@ -6,45 +6,101 @@ from ..compat import ( compat_urllib_parse_unquote_plus ) from ..utils import ( - int_or_none, remove_end, unified_strdate, + parse_duration ) class NDTVIE(InfoExtractor): - _VALID_URL = r'https?://(?:(?:www|gadgets|khabar|profit)\.)?ndtv\.com/videos?/(?:[^/]+/)*[^/?^&]+-(?P\d+)' + _VALID_URL = r'https?://(?:[^/]+\.)?ndtv\.com/(?:[^/]+/)*videos?/?(?:[^/]+/)*[^/?^&]+-(?P\d+)' - _TEST = { - 'url': 'http://www.ndtv.com/video/news/news/ndtv-exclusive-don-t-need-character-certificate-from-rahul-gandhi-says-arvind-kejriwal-300710', - 'md5': '39f992dbe5fb531c395d8bbedb1e5e88', - 'info_dict': { - 'id': '300710', - 'ext': 'mp4', - 'title': "NDTV exclusive: Don't need character certificate from Rahul Gandhi, says Arvind Kejriwal", - 'description': 'md5:ab2d4b4a6056c5cb4caa6d729deabf02', - 'upload_date': '20131208', - 'duration': 1327, - 'thumbnail': r're:https?://.*\.jpg', + _TESTS = [ + { + 'url': 'https://khabar.ndtv.com/video/show/prime-time/prime-time-ill-system-and-poor-education-468818', + 'md5': '78efcf3880ef3fd9b83d405ca94a38eb', + 'info_dict': { + 'id': '468818', + 'ext': 'mp4', + 'title': "प्राइम टाइम: सिस्टम बीमार, स्कूल बदहाल", + 'description': 'md5:f410512f1b49672e5695dea16ef2731d', + 'upload_date': '20170928', + 'duration': 2218, + 'thumbnail': r're:https?://.*\.jpg', + } + }, + { + # __filename is url + 'url': 'http://movies.ndtv.com/videos/cracker-free-diwali-wishes-from-karan-johar-kriti-sanon-other-stars-470304', + 'md5': 'f1d709352305b44443515ac56b45aa46', + 'info_dict': { + 'id': '470304', + 'ext': 'mp4', + 'title': "Cracker-Free Diwali Wishes From Karan Johar, Kriti Sanon & Other Stars", + 'description': 'md5:f115bba1adf2f6433fa7c1ade5feb465', + 'upload_date': '20171019', + 'duration': 137, + 'thumbnail': r're:https?://.*\.jpg', + } + }, + { + 'url': 'https://www.ndtv.com/video/news/news/delhi-s-air-quality-status-report-after-diwali-is-very-poor-470372', + 'only_matching': True + }, + { + 'url': 'https://auto.ndtv.com/videos/the-cnb-daily-october-13-2017-469935', + 'only_matching': True + }, + { + 'url': 'https://sports.ndtv.com/cricket/videos/2nd-t20i-rock-thrown-at-australia-cricket-team-bus-after-win-over-india-469764', + 'only_matching': True + }, + { + 'url': 'http://gadgets.ndtv.com/videos/uncharted-the-lost-legacy-review-465568', + 'only_matching': True + }, + { + 'url': 'http://profit.ndtv.com/videos/news/video-indian-economy-on-very-solid-track-international-monetary-fund-chief-470040', + 'only_matching': True + }, + { + 'url': 'http://food.ndtv.com/video-basil-seeds-coconut-porridge-419083', + 'only_matching': True + }, + { + 'url': 'https://doctor.ndtv.com/videos/top-health-stories-of-the-week-467396', + 'only_matching': True + }, + { + 'url': 'https://swirlster.ndtv.com/video/how-to-make-friends-at-work-469324', + 'only_matching': True } - } + ] def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) + # '__title' does not contain extra words such as sub-site name, "Video" etc. title = compat_urllib_parse_unquote_plus( - self._search_regex(r"__title\s*=\s*'([^']+)'", webpage, 'title')) + self._search_regex(r"__title\s*=\s*'([^']+)'", webpage, 'title', default=None) or + self._og_search_title(webpage)) filename = self._search_regex( - r"__filename\s*=\s*'([^']+)'", webpage, 'video filename') - video_url = 'https://ndtvod.bc-ssl.cdn.bitgravity.com/23372/ndtv/%s' % filename + r"(?:__)?filename\s*[:=]\s*'([^']+)'", webpage, 'video filename') + # in "movies" sub-site pages, filename is URL + video_url = 'https://ndtvod.bc-ssl.cdn.bitgravity.com/23372/ndtv/%s' % filename \ + if not (filename.startswith('http://') or filename.startswith('https://')) else filename - duration = int_or_none(self._search_regex( - r"__duration\s*=\s*'([^']+)'", webpage, 'duration', fatal=False)) + # "doctor" sub-site has MM:SS format + duration = parse_duration(self._search_regex( + r"(?:__)?duration\s*[:=]\s*'([^']+)'", webpage, 'duration', fatal=False)) + # "sports", "doctor", "swirlster" sub-sites don't have 'publish-date' upload_date = unified_strdate(self._html_search_meta( - 'publish-date', webpage, 'upload date', fatal=False)) + 'publish-date', webpage, 'upload date', default=None) or self._html_search_meta( + 'uploadDate', webpage, 'upload date', default=None) or self._search_regex( + r'datePublished"\s*:\s*"([^"]+)"', webpage, 'upload date', fatal=False)) description = remove_end(self._og_search_description(webpage), ' (Read more)') From 7175906966f3e2e64e837d4639a449649a9ed726 Mon Sep 17 00:00:00 2001 From: rawcoder Date: Sat, 21 Oct 2017 16:11:35 +0530 Subject: [PATCH 4/4] [NDTV]: Use `urljoin` for creating URL --- youtube_dl/extractor/ndtv.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/ndtv.py b/youtube_dl/extractor/ndtv.py index 2d6a1602c..ddec89f2c 100644 --- a/youtube_dl/extractor/ndtv.py +++ b/youtube_dl/extractor/ndtv.py @@ -6,9 +6,10 @@ from ..compat import ( compat_urllib_parse_unquote_plus ) from ..utils import ( + parse_duration, remove_end, unified_strdate, - parse_duration + urljoin ) @@ -89,8 +90,7 @@ class NDTVIE(InfoExtractor): filename = self._search_regex( r"(?:__)?filename\s*[:=]\s*'([^']+)'", webpage, 'video filename') # in "movies" sub-site pages, filename is URL - video_url = 'https://ndtvod.bc-ssl.cdn.bitgravity.com/23372/ndtv/%s' % filename \ - if not (filename.startswith('http://') or filename.startswith('https://')) else filename + video_url = urljoin('https://ndtvod.bc-ssl.cdn.bitgravity.com/23372/ndtv/', filename.lstrip('/')) # "doctor" sub-site has MM:SS format duration = parse_duration(self._search_regex(