]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/varzesh3.py
[generic] Extract subtitles from video.js (#3156)
[yt-dlp.git] / yt_dlp / extractor / varzesh3.py
CommitLineData
db40364b
MTP
1# coding: utf-8
2from __future__ import unicode_literals
55cde6ef 3
db40364b 4from .common import InfoExtractor
ee94e7e6
YCH
5from ..utils import (
6 clean_html,
4dfbf869 7 parse_qs,
ee94e7e6
YCH
8 remove_start,
9)
db40364b
MTP
10
11
12class Varzesh3IE(InfoExtractor):
55cde6ef 13 _VALID_URL = r'https?://(?:www\.)?video\.varzesh3\.com/(?:[^/]+/)+(?P<id>[^/]+)/?'
ee94e7e6 14 _TESTS = [{
db40364b
MTP
15 '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/',
16 'md5': '2a933874cb7dce4366075281eb49e855',
17 'info_dict': {
db40364b
MTP
18 'id': '76337',
19 'ext': 'mp4',
8896b614 20 'title': '۵ واکنش برتر دروازه‌بانان؛هفته ۲۶ بوندسلیگا',
2315fb5e 21 'description': 'فصل ۲۰۱۵-۲۰۱۴',
ec85ded8 22 'thumbnail': r're:^https?://.*\.jpg$',
ee94e7e6
YCH
23 },
24 'skip': 'HTTP 404 Error',
25 }, {
26 'url': 'http://video.varzesh3.com/video/112785/%D8%AF%D9%84%D9%87-%D8%B9%D9%84%DB%8C%D8%9B-%D8%B3%D8%AA%D8%A7%D8%B1%D9%87-%D9%86%D9%88%D8%B8%D9%87%D9%88%D8%B1-%D9%84%DB%8C%DA%AF-%D8%A8%D8%B1%D8%AA%D8%B1-%D8%AC%D8%B2%DB%8C%D8%B1%D9%87',
00b426d6 27 'md5': '841b7cd3afbc76e61708d94e53a4a4e7',
ee94e7e6
YCH
28 'info_dict': {
29 'id': '112785',
30 'ext': 'mp4',
31 'title': 'دله علی؛ ستاره نوظهور لیگ برتر جزیره',
32 'description': 'فوتبال 120',
33 },
34 'expected_warnings': ['description'],
35 }]
db40364b
MTP
36
37 def _real_extract(self, url):
55cde6ef
S
38 display_id = self._match_id(url)
39
40 webpage = self._download_webpage(url, display_id)
41
42 video_url = self._search_regex(
43 r'<source[^>]+src="([^"]+)"', webpage, 'video url')
db40364b 44
ee94e7e6
YCH
45 title = remove_start(self._html_search_regex(
46 r'<title>([^<]+)</title>', webpage, 'title'), 'ویدیو ورزش 3 | ')
47
55cde6ef
S
48 description = self._html_search_regex(
49 r'(?s)<div class="matn">(.+?)</div>',
ee94e7e6
YCH
50 webpage, 'description', default=None)
51 if description is None:
52 description = clean_html(self._html_search_meta('description', webpage))
53
54 thumbnail = self._og_search_thumbnail(webpage, default=None)
55 if thumbnail is None:
56 fb_sharer_url = self._search_regex(
57 r'<a[^>]+href="(https?://www\.facebook\.com/sharer/sharer\.php?[^"]+)"',
58 webpage, 'facebook sharer URL', fatal=False)
4dfbf869 59 sharer_params = parse_qs(fb_sharer_url)
ee94e7e6 60 thumbnail = sharer_params.get('p[images][0]', [None])[0]
db40364b 61
55cde6ef
S
62 video_id = self._search_regex(
63 r"<link[^>]+rel='(?:canonical|shortlink)'[^>]+href='/\?p=([^']+)'",
ee94e7e6
YCH
64 webpage, display_id, default=None)
65 if video_id is None:
66 video_id = self._search_regex(
ec85ded8 67 r'var\s+VideoId\s*=\s*(\d+);', webpage, 'video id',
ee94e7e6 68 default=display_id)
db40364b
MTP
69
70 return {
55cde6ef
S
71 'url': video_url,
72 'id': video_id,
db40364b 73 'title': title,
db40364b
MTP
74 'description': description,
75 'thumbnail': thumbnail,
76 }