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