0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-10-31 23:02:40 +00:00
yt-dlp/yt_dlp/extractor/foxgay.py

59 lines
2 KiB
Python
Raw Normal View History

import itertools
2014-12-04 04:22:48 +00:00
from .common import InfoExtractor
from ..utils import (
get_element_by_id,
2017-06-08 17:22:14 +00:00
int_or_none,
remove_end,
)
2014-12-04 04:22:48 +00:00
class FoxgayIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?foxgay\.com/videos/(?:\S+-)?(?P<id>\d+)\.shtml'
2014-12-04 04:22:48 +00:00
_TEST = {
'url': 'http://foxgay.com/videos/fuck-turkish-style-2582.shtml',
'md5': '344558ccfea74d33b7adbce22e577f54',
2014-12-04 04:22:48 +00:00
'info_dict': {
'id': '2582',
'ext': 'mp4',
'title': 'Fuck Turkish-style',
'description': 'md5:6ae2d9486921891efe89231ace13ffdf',
2014-12-04 04:22:48 +00:00
'age_limit': 18,
'thumbnail': r're:https?://.*\.jpg$',
2014-12-04 04:22:48 +00:00
},
}
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
2022-04-04 08:27:35 +00:00
title = remove_end(self._html_extract_title(webpage), ' - Foxgay.com')
description = get_element_by_id('inf_tit', webpage)
2014-12-04 04:22:48 +00:00
# The default user-agent with foxgay cookies leads to pages without videos
self.cookiejar.clear('.foxgay.com')
2014-12-04 04:22:48 +00:00
# Find the URL for the iFrame which contains the actual video.
iframe_url = self._html_search_regex(
r'<iframe[^>]+src=([\'"])(?P<url>[^\'"]+)\1', webpage,
'video frame', group='url')
2014-12-04 04:22:48 +00:00
iframe = self._download_webpage(
iframe_url, video_id, headers={'User-Agent': 'curl/7.50.1'},
note='Downloading video frame')
video_data = self._parse_json(self._search_regex(
r'video_data\s*=\s*([^;]+);', iframe, 'video data'), video_id)
formats = [{
'url': source,
2017-06-08 17:22:14 +00:00
'height': int_or_none(resolution),
} for source, resolution in zip(
video_data['sources'], video_data.get('resolutions', itertools.repeat(None)))]
2014-12-04 04:22:48 +00:00
return {
'id': video_id,
'title': title,
'formats': formats,
2014-12-04 04:22:48 +00:00
'description': description,
'thumbnail': video_data.get('act_vid', {}).get('thumb'),
2014-12-04 04:22:48 +00:00
'age_limit': 18,
}