]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/foxgay.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / foxgay.py
CommitLineData
e78a5428
YCH
1import itertools
2
b92c5486 3from .common import InfoExtractor
e78a5428
YCH
4from ..utils import (
5 get_element_by_id,
cc69a3de 6 int_or_none,
e78a5428
YCH
7 remove_end,
8)
b92c5486
ZF
9
10
11class FoxgayIE(InfoExtractor):
5886b38d 12 _VALID_URL = r'https?://(?:www\.)?foxgay\.com/videos/(?:\S+-)?(?P<id>\d+)\.shtml'
b92c5486
ZF
13 _TEST = {
14 'url': 'http://foxgay.com/videos/fuck-turkish-style-2582.shtml',
e78a5428 15 'md5': '344558ccfea74d33b7adbce22e577f54',
b92c5486
ZF
16 'info_dict': {
17 'id': '2582',
18 'ext': 'mp4',
e78a5428
YCH
19 'title': 'Fuck Turkish-style',
20 'description': 'md5:6ae2d9486921891efe89231ace13ffdf',
b92c5486 21 'age_limit': 18,
ec85ded8 22 'thumbnail': r're:https?://.*\.jpg$',
b92c5486
ZF
23 },
24 }
25
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
b92c5486 28 webpage = self._download_webpage(url, video_id)
191cc41b 29
04f3fd2c 30 title = remove_end(self._html_extract_title(webpage), ' - Foxgay.com')
e78a5428 31 description = get_element_by_id('inf_tit', webpage)
b92c5486 32
e78a5428 33 # The default user-agent with foxgay cookies leads to pages without videos
9809740b 34 self.cookiejar.clear('.foxgay.com')
b92c5486 35 # Find the URL for the iFrame which contains the actual video.
e78a5428
YCH
36 iframe_url = self._html_search_regex(
37 r'<iframe[^>]+src=([\'"])(?P<url>[^\'"]+)\1', webpage,
38 'video frame', group='url')
b92c5486 39 iframe = self._download_webpage(
e78a5428
YCH
40 iframe_url, video_id, headers={'User-Agent': 'curl/7.50.1'},
41 note='Downloading video frame')
42 video_data = self._parse_json(self._search_regex(
43 r'video_data\s*=\s*([^;]+);', iframe, 'video data'), video_id)
44
45 formats = [{
46 'url': source,
cc69a3de 47 'height': int_or_none(resolution),
e78a5428
YCH
48 } for source, resolution in zip(
49 video_data['sources'], video_data.get('resolutions', itertools.repeat(None)))]
50
b92c5486
ZF
51 return {
52 'id': video_id,
53 'title': title,
e78a5428 54 'formats': formats,
b92c5486 55 'description': description,
e78a5428 56 'thumbnail': video_data.get('act_vid', {}).get('thumb'),
b92c5486
ZF
57 'age_limit': 18,
58 }