From db40364b8767839cc1abf5ece53511167d70f792 Mon Sep 17 00:00:00 2001 From: Mohammad Teimori Pabandi Date: Thu, 26 Mar 2015 18:17:21 +0430 Subject: [PATCH 1/5] [Varzesh3] Add new extractor --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/varzesh3.py | 63 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 youtube_dl/extractor/varzesh3.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index b0df52afd..3011b784d 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -548,6 +548,7 @@ from .unistra import UnistraIE from .urort import UrortIE from .ustream import UstreamIE, UstreamChannelIE +from .varzesh3 import Varzesh3IE from .vbox7 import Vbox7IE from .veehd import VeeHDIE from .veoh import VeohIE diff --git a/youtube_dl/extractor/varzesh3.py b/youtube_dl/extractor/varzesh3.py new file mode 100644 index 000000000..85dcd8734 --- /dev/null +++ b/youtube_dl/extractor/varzesh3.py @@ -0,0 +1,63 @@ +# coding: utf-8 +from __future__ import unicode_literals +from .common import InfoExtractor +from ..utils import ( + ExtractorError, +) +import re + + +class Varzesh3IE(InfoExtractor): + _VALID_URL = r'(?P(https?://(?:www\.)?video\.varzesh3\.com)/(?P.+))' + _TESTS = [ + { + 'url': 'http://video.varzesh3.com/video/%D8%AF%D8%A7%D9%86%D9%85%D8%A7%D8%B1%DA%A9-3-2-%D8%A2%D9%85%D8%B1%DB%8C%DA%A9%D8%A7/', + 'md5': 'c4b850780df9374b078463c5cf6b3318', + 'info_dict': { + 'url': 'http://dl1.video.varzesh3.com/video/clip94/1/international/friendly/usa_2_3_danmark.mp4', + 'id': '76464', + 'ext': 'mp4', + 'title': u'دانمارک ۳-۲ آمریکا (گلهای بازی)', + 'thumbnail': 'http://video.varzesh3.com/wp-content/uploads/250315_usa_danmark_site.jpg', + 'description': u'بازی دوستانه ۲۰۱۵', + + } + }, + { + 'url': 'http://video.varzesh3.com/germany/bundesliga/5-%D9%88%D8%A7%DA%A9%D9%86%D8%B4-%D8%A8%D8%B1%D8%AA%D8%B1-%D8%AF%D8%B1%D9%88%D8%A7%D8%B2%D9%87%E2%80%8C%D8%A8%D8%A7%D9%86%D8%A7%D9%86%D8%9B%D9%87%D9%81%D8%AA%D9%87-26-%D8%A8%D9%88%D9%86%D8%AF%D8%B3/', + 'md5': '2a933874cb7dce4366075281eb49e855', + 'info_dict': { + 'url': 'http://dl1.video.varzesh3.com/video/clip94/1/video/namayeshi/saves_week26.mp4', + 'id': '76337', + 'ext': 'mp4', + 'title': u'۵ واکنش برتر دروازه‌بانان؛هفته ۲۶ بوندسلیگا', + 'thumbnail': 'http://video.varzesh3.com/wp-content/uploads/230315_saves_week26.jpg', + 'description': u'فصل ۲۰۱۵-۲۰۱۴', + } + }, + ] + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + + if not 'shortlink' in webpage: + raise ExtractorError('URL has no videos or there is a problem.') + + title = self._html_search_regex(r'meta[^>]+property="og:title"[^>]+content="([^"]+)"', webpage, 'title') + video_link = self._html_search_regex(r'source[^>]+src="([^"]+)"', webpage, 'video_link') + vid_id = self._html_search_regex(r"link[^>]+rel='canonical'[^>]+href='\/\?p=([^']+)'\/>", webpage, 'vid_id') + try: + description = self._html_search_regex(r'
(.*?)
', webpage, 'description', flags=re.DOTALL) + except: + description = title + thumbnail = self._html_search_regex(r'link[^>]+rel="image_src"[^>]+href="([^"]+)"', webpage, 'thumbnail') + + return { + 'url': video_link, + 'id': vid_id, + 'title': title, + 'ext': video_link.split(".")[-1], + 'description': description, + 'thumbnail': thumbnail, + } From a7fce980adeb12afd94e4414cc6a6b37021f6aa4 Mon Sep 17 00:00:00 2001 From: Mohammad Teimori Pabandi Date: Thu, 26 Mar 2015 19:47:34 +0430 Subject: [PATCH 2/5] removed one of tests that made problem with testing server --- youtube_dl/extractor/varzesh3.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/youtube_dl/extractor/varzesh3.py b/youtube_dl/extractor/varzesh3.py index 85dcd8734..cb3fdacff 100644 --- a/youtube_dl/extractor/varzesh3.py +++ b/youtube_dl/extractor/varzesh3.py @@ -9,21 +9,7 @@ class Varzesh3IE(InfoExtractor): _VALID_URL = r'(?P(https?://(?:www\.)?video\.varzesh3\.com)/(?P.+))' - _TESTS = [ - { - 'url': 'http://video.varzesh3.com/video/%D8%AF%D8%A7%D9%86%D9%85%D8%A7%D8%B1%DA%A9-3-2-%D8%A2%D9%85%D8%B1%DB%8C%DA%A9%D8%A7/', - 'md5': 'c4b850780df9374b078463c5cf6b3318', - 'info_dict': { - 'url': 'http://dl1.video.varzesh3.com/video/clip94/1/international/friendly/usa_2_3_danmark.mp4', - 'id': '76464', - 'ext': 'mp4', - 'title': u'دانمارک ۳-۲ آمریکا (گلهای بازی)', - 'thumbnail': 'http://video.varzesh3.com/wp-content/uploads/250315_usa_danmark_site.jpg', - 'description': u'بازی دوستانه ۲۰۱۵', - - } - }, - { + _TEST ={ 'url': 'http://video.varzesh3.com/germany/bundesliga/5-%D9%88%D8%A7%DA%A9%D9%86%D8%B4-%D8%A8%D8%B1%D8%AA%D8%B1-%D8%AF%D8%B1%D9%88%D8%A7%D8%B2%D9%87%E2%80%8C%D8%A8%D8%A7%D9%86%D8%A7%D9%86%D8%9B%D9%87%D9%81%D8%AA%D9%87-26-%D8%A8%D9%88%D9%86%D8%AF%D8%B3/', 'md5': '2a933874cb7dce4366075281eb49e855', 'info_dict': { @@ -34,8 +20,7 @@ class Varzesh3IE(InfoExtractor): 'thumbnail': 'http://video.varzesh3.com/wp-content/uploads/230315_saves_week26.jpg', 'description': u'فصل ۲۰۱۵-۲۰۱۴', } - }, - ] + } def _real_extract(self, url): video_id = self._match_id(url) From 8896b614a9257ba33346f49a135371d460bfb311 Mon Sep 17 00:00:00 2001 From: Mohammad Teimori Pabandi Date: Thu, 26 Mar 2015 20:06:50 +0430 Subject: [PATCH 3/5] removing unicode literal because it is imported :)) --- youtube_dl/extractor/varzesh3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/varzesh3.py b/youtube_dl/extractor/varzesh3.py index cb3fdacff..62bcb9118 100644 --- a/youtube_dl/extractor/varzesh3.py +++ b/youtube_dl/extractor/varzesh3.py @@ -16,7 +16,7 @@ class Varzesh3IE(InfoExtractor): 'url': 'http://dl1.video.varzesh3.com/video/clip94/1/video/namayeshi/saves_week26.mp4', 'id': '76337', 'ext': 'mp4', - 'title': u'۵ واکنش برتر دروازه‌بانان؛هفته ۲۶ بوندسلیگا', + 'title': '۵ واکنش برتر دروازه‌بانان؛هفته ۲۶ بوندسلیگا', 'thumbnail': 'http://video.varzesh3.com/wp-content/uploads/230315_saves_week26.jpg', 'description': u'فصل ۲۰۱۵-۲۰۱۴', } From 2315fb5e5fb65271519fc018bb1df5a7269f0a6a Mon Sep 17 00:00:00 2001 From: Mohammad Teimori Pabandi Date: Thu, 26 Mar 2015 23:53:57 +0430 Subject: [PATCH 4/5] unicde :( --- youtube_dl/extractor/varzesh3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/varzesh3.py b/youtube_dl/extractor/varzesh3.py index 62bcb9118..eb49586cc 100644 --- a/youtube_dl/extractor/varzesh3.py +++ b/youtube_dl/extractor/varzesh3.py @@ -18,7 +18,7 @@ class Varzesh3IE(InfoExtractor): 'ext': 'mp4', 'title': '۵ واکنش برتر دروازه‌بانان؛هفته ۲۶ بوندسلیگا', 'thumbnail': 'http://video.varzesh3.com/wp-content/uploads/230315_saves_week26.jpg', - 'description': u'فصل ۲۰۱۵-۲۰۱۴', + 'description': 'فصل ۲۰۱۵-۲۰۱۴', } } From 55cde6ef3c046dfd5f6ef84b908d38ee4375cf08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Wed, 1 Apr 2015 22:02:55 +0600 Subject: [PATCH 5/5] [varzesh3] Simplify --- youtube_dl/extractor/varzesh3.py | 43 +++++++++++++++----------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/youtube_dl/extractor/varzesh3.py b/youtube_dl/extractor/varzesh3.py index eb49586cc..9369abaf8 100644 --- a/youtube_dl/extractor/varzesh3.py +++ b/youtube_dl/extractor/varzesh3.py @@ -1,48 +1,45 @@ # coding: utf-8 from __future__ import unicode_literals + from .common import InfoExtractor -from ..utils import ( - ExtractorError, -) -import re class Varzesh3IE(InfoExtractor): - _VALID_URL = r'(?P(https?://(?:www\.)?video\.varzesh3\.com)/(?P.+))' - _TEST ={ + _VALID_URL = r'https?://(?:www\.)?video\.varzesh3\.com/(?:[^/]+/)+(?P[^/]+)/?' + _TEST = { 'url': 'http://video.varzesh3.com/germany/bundesliga/5-%D9%88%D8%A7%DA%A9%D9%86%D8%B4-%D8%A8%D8%B1%D8%AA%D8%B1-%D8%AF%D8%B1%D9%88%D8%A7%D8%B2%D9%87%E2%80%8C%D8%A8%D8%A7%D9%86%D8%A7%D9%86%D8%9B%D9%87%D9%81%D8%AA%D9%87-26-%D8%A8%D9%88%D9%86%D8%AF%D8%B3/', 'md5': '2a933874cb7dce4366075281eb49e855', 'info_dict': { - 'url': 'http://dl1.video.varzesh3.com/video/clip94/1/video/namayeshi/saves_week26.mp4', 'id': '76337', 'ext': 'mp4', 'title': '۵ واکنش برتر دروازه‌بانان؛هفته ۲۶ بوندسلیگا', - 'thumbnail': 'http://video.varzesh3.com/wp-content/uploads/230315_saves_week26.jpg', 'description': 'فصل ۲۰۱۵-۲۰۱۴', + 'thumbnail': 're:^https?://.*\.jpg$', } } def _real_extract(self, url): - video_id = self._match_id(url) - webpage = self._download_webpage(url, video_id) + display_id = self._match_id(url) - if not 'shortlink' in webpage: - raise ExtractorError('URL has no videos or there is a problem.') + webpage = self._download_webpage(url, display_id) - title = self._html_search_regex(r'meta[^>]+property="og:title"[^>]+content="([^"]+)"', webpage, 'title') - video_link = self._html_search_regex(r'source[^>]+src="([^"]+)"', webpage, 'video_link') - vid_id = self._html_search_regex(r"link[^>]+rel='canonical'[^>]+href='\/\?p=([^']+)'\/>", webpage, 'vid_id') - try: - description = self._html_search_regex(r'
(.*?)
', webpage, 'description', flags=re.DOTALL) - except: - description = title - thumbnail = self._html_search_regex(r'link[^>]+rel="image_src"[^>]+href="([^"]+)"', webpage, 'thumbnail') + video_url = self._search_regex( + r']+src="([^"]+)"', webpage, 'video url') + + title = self._og_search_title(webpage) + description = self._html_search_regex( + r'(?s)
(.+?)
', + webpage, 'description', fatal=False) + thumbnail = self._og_search_thumbnail(webpage) + + video_id = self._search_regex( + r"]+rel='(?:canonical|shortlink)'[^>]+href='/\?p=([^']+)'", + webpage, display_id, default=display_id) return { - 'url': video_link, - 'id': vid_id, + 'url': video_url, + 'id': video_id, 'title': title, - 'ext': video_link.split(".")[-1], 'description': description, 'thumbnail': thumbnail, }