]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/varzesh3.py
[cleanup] Use `_html_extract_title`
[yt-dlp.git] / yt_dlp / extractor / varzesh3.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 clean_html,
7 parse_qs,
8 remove_start,
9 )
10
11
12 class Varzesh3IE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?video\.varzesh3\.com/(?:[^/]+/)+(?P<id>[^/]+)/?'
14 _TESTS = [{
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': {
18 'id': '76337',
19 'ext': 'mp4',
20 'title': '۵ واکنش برتر دروازه‌بانان؛هفته ۲۶ بوندسلیگا',
21 'description': 'فصل ۲۰۱۵-۲۰۱۴',
22 'thumbnail': r're:^https?://.*\.jpg$',
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',
27 'md5': '841b7cd3afbc76e61708d94e53a4a4e7',
28 'info_dict': {
29 'id': '112785',
30 'ext': 'mp4',
31 'title': 'دله علی؛ ستاره نوظهور لیگ برتر جزیره',
32 'description': 'فوتبال 120',
33 },
34 'expected_warnings': ['description'],
35 }]
36
37 def _real_extract(self, url):
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')
44
45 title = remove_start(self._html_extract_title(webpage), 'ویدیو ورزش 3 | ')
46
47 description = self._html_search_regex(
48 r'(?s)<div class="matn">(.+?)</div>',
49 webpage, 'description', default=None)
50 if description is None:
51 description = clean_html(self._html_search_meta('description', webpage))
52
53 thumbnail = self._og_search_thumbnail(webpage, default=None)
54 if thumbnail is None:
55 fb_sharer_url = self._search_regex(
56 r'<a[^>]+href="(https?://www\.facebook\.com/sharer/sharer\.php?[^"]+)"',
57 webpage, 'facebook sharer URL', fatal=False)
58 sharer_params = parse_qs(fb_sharer_url)
59 thumbnail = sharer_params.get('p[images][0]', [None])[0]
60
61 video_id = self._search_regex(
62 r"<link[^>]+rel='(?:canonical|shortlink)'[^>]+href='/\?p=([^']+)'",
63 webpage, display_id, default=None)
64 if video_id is None:
65 video_id = self._search_regex(
66 r'var\s+VideoId\s*=\s*(\d+);', webpage, 'video id',
67 default=display_id)
68
69 return {
70 'url': video_url,
71 'id': video_id,
72 'title': title,
73 'description': description,
74 'thumbnail': thumbnail,
75 }