]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/foxgay.py
f4f29c65d13893af7be49c5fde2dbe787895edf5
[yt-dlp.git] / yt_dlp / extractor / foxgay.py
1 import itertools
2
3 from .common import InfoExtractor
4 from ..utils import (
5 get_element_by_id,
6 int_or_none,
7 remove_end,
8 )
9
10
11 class FoxgayIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?foxgay\.com/videos/(?:\S+-)?(?P<id>\d+)\.shtml'
13 _TEST = {
14 'url': 'http://foxgay.com/videos/fuck-turkish-style-2582.shtml',
15 'md5': '344558ccfea74d33b7adbce22e577f54',
16 'info_dict': {
17 'id': '2582',
18 'ext': 'mp4',
19 'title': 'Fuck Turkish-style',
20 'description': 'md5:6ae2d9486921891efe89231ace13ffdf',
21 'age_limit': 18,
22 'thumbnail': r're:https?://.*\.jpg$',
23 },
24 }
25
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
28 webpage = self._download_webpage(url, video_id)
29
30 title = remove_end(self._html_extract_title(webpage), ' - Foxgay.com')
31 description = get_element_by_id('inf_tit', webpage)
32
33 # The default user-agent with foxgay cookies leads to pages without videos
34 self.cookiejar.clear('.foxgay.com')
35 # Find the URL for the iFrame which contains the actual video.
36 iframe_url = self._html_search_regex(
37 r'<iframe[^>]+src=([\'"])(?P<url>[^\'"]+)\1', webpage,
38 'video frame', group='url')
39 iframe = self._download_webpage(
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,
47 'height': int_or_none(resolution),
48 } for source, resolution in zip(
49 video_data['sources'], video_data.get('resolutions', itertools.repeat(None)))]
50
51 return {
52 'id': video_id,
53 'title': title,
54 'formats': formats,
55 'description': description,
56 'thumbnail': video_data.get('act_vid', {}).get('thumb'),
57 'age_limit': 18,
58 }