From 185a7e25e7c18b0dff17bdb9ae828616a5ac17d4 Mon Sep 17 00:00:00 2001 From: Mohammad Teimori Pabandi Date: Fri, 3 Apr 2015 20:55:39 +0430 Subject: [PATCH 1/3] [RadioJavan] Add new extractor --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/radiojavan.py | 71 ++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 youtube_dl/extractor/radiojavan.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 3011b784d..df4a7419a 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -391,6 +391,7 @@ from .pyvideo import PyvideoIE from .quickvid import QuickVidIE from .r7 import R7IE from .radiode import RadioDeIE +from .radiojavan import RadioJavanIE from .radiobremen import RadioBremenIE from .radiofrance import RadioFranceIE from .rai import RaiIE diff --git a/youtube_dl/extractor/radiojavan.py b/youtube_dl/extractor/radiojavan.py new file mode 100644 index 000000000..de90f9270 --- /dev/null +++ b/youtube_dl/extractor/radiojavan.py @@ -0,0 +1,71 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor +from ..utils import( + parse_duration, + str_to_int +) + +class RadioJavanIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?radiojavan\.com/videos/video/(?P[^/]+)/?' + _TEST = { + 'url': 'http://www.radiojavan.com/videos/video/chaartaar-ashoobam', + 'md5': 'e85208ffa3ca8b83534fca9fe19af95b', + 'info_dict': { + 'id': 'chaartaar-ashoobam', + 'ext': 'mp4', + 'title': 'Chaartaar - Ashoobam', + 'description': 'Chaartaar - Ashoobam', + 'thumbnail': 're:^https?://.*\.jpe?g$', + } + } + + def _real_extract(self, url): + display_id = self._match_id(url) + webpage = self._download_webpage(url, display_id) + urls = list() + prefix = 'https://media.rdjavan.com/media/music_video/' + + video_url_480 = self._search_regex( + r'RJ\.video480p = \'([^\']+)\'', webpage, '480 video url', fatal= False) + video_url_720 = self._search_regex( + r'RJ\.video720p = \'([^\']+)\'', webpage, '720 video url', fatal= False) + video_url_1080 = self._search_regex( + r'RJ\.video1080p = \'([^\']+)\'', webpage, '1080 video url', fatal= False) + + if video_url_480: + urls.append({'url': prefix + video_url_480, 'format': '480p'}) + if video_url_720: + urls.append({'url': prefix + video_url_720, 'format': '720p'}) + if video_url_1080: + urls.append({'url': prefix + video_url_1080, 'format': '1080p'}) + + title = self._og_search_title(webpage) + thumbnail = self._og_search_thumbnail(webpage) + formats = [{ + 'url': url['url'], + 'format': url['format'] + } for url in urls] + + likes = self._search_regex( + r'([\d,]+)\s*likes', webpage, 'Likes Count', fatal=False ) + likes = likes.replace(',', '') + dislikes = self._search_regex( + r'([\d,]+)\s*dislikes', webpage, 'Dislikes Count', fatal=False ) + dislikes = dislikes.replace(',', '') + + plays = self._search_regex( + r'views_publish[">\s]*]+class="views">Plays: ([\d,]+)', webpage, 'Play Count', fatal=False ) + plays = plays.replace(',', '') + + return { + 'formats': formats, + 'id': display_id, + 'title': title, + 'description': title, # no description provided in RadioJavan + 'thumbnail': thumbnail, + 'like_count': str_to_int(likes), + 'dislike_count': str_to_int(dislikes), + 'viewCount': str_to_int(plays) + } \ No newline at end of file From 7cf97daf77f6419f2b965a199a3fb1e63b8771b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sat, 4 Apr 2015 16:45:41 +0600 Subject: [PATCH 2/3] [radiojavan] Simplify and extract upload date --- youtube_dl/extractor/radiojavan.py | 75 ++++++++++++++---------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/youtube_dl/extractor/radiojavan.py b/youtube_dl/extractor/radiojavan.py index de90f9270..73ab78d6d 100644 --- a/youtube_dl/extractor/radiojavan.py +++ b/youtube_dl/extractor/radiojavan.py @@ -1,12 +1,14 @@ -# coding: utf-8 from __future__ import unicode_literals +import re + from .common import InfoExtractor from ..utils import( - parse_duration, - str_to_int + unified_strdate, + str_to_int, ) + class RadioJavanIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?radiojavan\.com/videos/video/(?P[^/]+)/?' _TEST = { @@ -16,56 +18,49 @@ class RadioJavanIE(InfoExtractor): 'id': 'chaartaar-ashoobam', 'ext': 'mp4', 'title': 'Chaartaar - Ashoobam', - 'description': 'Chaartaar - Ashoobam', 'thumbnail': 're:^https?://.*\.jpe?g$', + 'upload_date': '20150215', + 'view_count': int, + 'like_count': int, + 'dislike_count': int, } } def _real_extract(self, url): - display_id = self._match_id(url) - webpage = self._download_webpage(url, display_id) - urls = list() - prefix = 'https://media.rdjavan.com/media/music_video/' + video_id = self._match_id(url) - video_url_480 = self._search_regex( - r'RJ\.video480p = \'([^\']+)\'', webpage, '480 video url', fatal= False) - video_url_720 = self._search_regex( - r'RJ\.video720p = \'([^\']+)\'', webpage, '720 video url', fatal= False) - video_url_1080 = self._search_regex( - r'RJ\.video1080p = \'([^\']+)\'', webpage, '1080 video url', fatal= False) + webpage = self._download_webpage(url, video_id) - if video_url_480: - urls.append({'url': prefix + video_url_480, 'format': '480p'}) - if video_url_720: - urls.append({'url': prefix + video_url_720, 'format': '720p'}) - if video_url_1080: - urls.append({'url': prefix + video_url_1080, 'format': '1080p'}) + formats = [{ + 'url': 'https://media.rdjavan.com/media/music_video/%s' % video_path, + 'format_id': '%sp' % height, + 'height': height, + } for height, video_path in re.findall(r"RJ\.video(\d+)p\s*=\s*'/?([^']+)'", webpage)] title = self._og_search_title(webpage) thumbnail = self._og_search_thumbnail(webpage) - formats = [{ - 'url': url['url'], - 'format': url['format'] - } for url in urls] - likes = self._search_regex( - r'([\d,]+)\s*likes', webpage, 'Likes Count', fatal=False ) - likes = likes.replace(',', '') - dislikes = self._search_regex( - r'([\d,]+)\s*dislikes', webpage, 'Dislikes Count', fatal=False ) - dislikes = dislikes.replace(',', '') + upload_date = unified_strdate(self._search_regex( + r'class="date_added">Date added: ([^<]+)<', + webpage, 'upload date', fatal=False)) - plays = self._search_regex( - r'views_publish[">\s]*]+class="views">Plays: ([\d,]+)', webpage, 'Play Count', fatal=False ) - plays = plays.replace(',', '') + view_count = str_to_int(self._search_regex( + r'class="views">Plays: ([\d,]+)', + webpage, 'view count', fatal=False)) + like_count = str_to_int(self._search_regex( + r'class="rating">([\d,]+) likes', + webpage, 'like count', fatal=False)) + dislike_count = str_to_int(self._search_regex( + r'class="rating">([\d,]+) dislikes', + webpage, 'dislike count', fatal=False)) return { - 'formats': formats, - 'id': display_id, + 'id': video_id, 'title': title, - 'description': title, # no description provided in RadioJavan 'thumbnail': thumbnail, - 'like_count': str_to_int(likes), - 'dislike_count': str_to_int(dislikes), - 'viewCount': str_to_int(plays) - } \ No newline at end of file + 'upload_date': upload_date, + 'view_count': view_count, + 'like_count': like_count, + 'dislike_count': dislike_count, + 'formats': formats, + } From 6e617ed0b6b5bb932f928f63c2bda36f5317468d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sat, 4 Apr 2015 16:47:09 +0600 Subject: [PATCH 3/3] Credit @mtp1376 for varzesh3 and radiojavan --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 48769320a..cf238176b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -120,3 +120,4 @@ Jeff Buchbinder Amish Bhadeshia Joram Schrijver Will W. +Mohammad Teimori Pabandi