]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/xnxx.py
[EmbedThumbnail] Do not remove id3v1 tags
[yt-dlp.git] / yt_dlp / extractor / xnxx.py
CommitLineData
dcdb292f 1# coding: utf-8
bdebf51c
JMF
2from __future__ import unicode_literals
3
b4a190fe
S
4import re
5
570fa151 6from .common import InfoExtractor
b4a190fe
S
7from ..utils import (
8 determine_ext,
9 int_or_none,
10 NO_DEFAULT,
11 str_to_int,
12)
570fa151
PH
13
14
15class XNXXIE(InfoExtractor):
ab2579bb 16 _VALID_URL = r'https?://(?:video|www)\.xnxx3?\.com/video-?(?P<id>[0-9a-z]+)/'
73843ae8 17 _TESTS = [{
97674f04 18 'url': 'http://www.xnxx.com/video-55awb78/skyrim_test_video',
b4a190fe 19 'md5': '7583e96c15c0f21e9da3453d9920fbba',
bdebf51c 20 'info_dict': {
97674f04 21 'id': '55awb78',
b4a190fe 22 'ext': 'mp4',
97674f04 23 'title': 'Skyrim Test Video',
b4a190fe
S
24 'thumbnail': r're:^https?://.*\.jpg',
25 'duration': 469,
26 'view_count': int,
bdebf51c 27 'age_limit': 18,
73843ae8 28 },
29 }, {
30 'url': 'http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_',
31 'only_matching': True,
adf1921d
S
32 }, {
33 'url': 'http://www.xnxx.com/video-55awb78/',
34 'only_matching': True,
ab2579bb
D
35 }, {
36 'url': 'http://www.xnxx3.com/video-55awb78/',
37 'only_matching': True,
73843ae8 38 }]
570fa151
PH
39
40 def _real_extract(self, url):
1cc79574 41 video_id = self._match_id(url)
b4a190fe 42
570fa151
PH
43 webpage = self._download_webpage(url, video_id)
44
b4a190fe
S
45 def get(meta, default=NO_DEFAULT, fatal=True):
46 return self._search_regex(
47 r'set%s\s*\(\s*(["\'])(?P<value>(?:(?!\1).)+)\1' % meta,
48 webpage, meta, default=default, fatal=fatal, group='value')
49
50 title = self._og_search_title(
51 webpage, default=None) or get('VideoTitle')
570fa151 52
b4a190fe
S
53 formats = []
54 for mobj in re.finditer(
55 r'setVideo(?:Url(?P<id>Low|High)|HLS)\s*\(\s*(?P<q>["\'])(?P<url>(?:https?:)?//.+?)(?P=q)', webpage):
56 format_url = mobj.group('url')
57 if determine_ext(format_url) == 'm3u8':
58 formats.extend(self._extract_m3u8_formats(
59 format_url, video_id, 'mp4', entry_protocol='m3u8_native',
f983b875 60 quality=1, m3u8_id='hls', fatal=False))
b4a190fe
S
61 else:
62 format_id = mobj.group('id')
63 if format_id:
64 format_id = format_id.lower()
65 formats.append({
66 'url': format_url,
67 'format_id': format_id,
68 'quality': -1 if format_id == 'low' else 0,
69 })
70 self._sort_formats(formats)
570fa151 71
b4a190fe
S
72 thumbnail = self._og_search_thumbnail(webpage, default=None) or get(
73 'ThumbUrl', fatal=False) or get('ThumbUrl169', fatal=False)
74 duration = int_or_none(self._og_search_property('duration', webpage))
75 view_count = str_to_int(self._search_regex(
76 r'id=["\']nb-views-number[^>]+>([\d,.]+)', webpage, 'view count',
77 default=None))
570fa151 78
bdebf51c 79 return {
570fa151 80 'id': video_id,
b4a190fe
S
81 'title': title,
82 'thumbnail': thumbnail,
83 'duration': duration,
84 'view_count': view_count,
8e590a11 85 'age_limit': 18,
b4a190fe 86 'formats': formats,
bdebf51c 87 }