1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-20 09:12:14 +00:00

Apply suggestions from code review

Co-authored-by: dirkf <fieldhouse@gmx.net>
This commit is contained in:
Kangcheng Xu 2022-10-29 01:54:55 -04:00 committed by tabjy
parent 1e522505be
commit 8414d8d8f5
3 changed files with 51 additions and 35 deletions

View file

@ -28,14 +28,14 @@ class BdsmxTubeIE(VXXXIE):
def _download_info_object(self, video_id): def _download_info_object(self, video_id):
return self._download_json( return self._download_json(
'https://bdsmx.tube/api/json/video/86400/0/{}/{}.json'.format( 'https://bdsmx.tube/api/json/video/86400/0/{0}/{1}.json'.format(
int(video_id) // 1000 * 1000, int(video_id) // 1000 * 1000,
video_id, video_id,
), video_id, headers={'Referer': 'https://bdsmx.tube'})['video'] ), video_id, headers={'Referer': 'https://bdsmx.tube'})['video']
def _download_format_object(self, video_id): def _download_format_object(self, video_id):
return self._download_json( return self._download_json(
'https://bdsmx.tube/api/videofile.php?video_id={}'.format(video_id), 'https://bdsmx.tube/api/videofile.php?video_id={0}'.format(video_id),
video_id, video_id,
headers={'Referer': 'https://bdsmx.tube'} headers={'Referer': 'https://bdsmx.tube'}
) )

View file

@ -1522,7 +1522,14 @@ from .vvvvid import (
VVVVIDIE, VVVVIDIE,
VVVVIDShowIE, VVVVIDShowIE,
) )
from .vxxx import VXXXIE from .vxxx import (
BdsmxTubeIE,
BlackPornTubeIE,
InPornIE,
MrGayIE,
VXXXIE,
XMilfIE,
)
from .vyborymos import VyboryMosIE from .vyborymos import VyboryMosIE
from .vzaar import VzaarIE from .vzaar import VzaarIE
from .wakanim import WakanimIE from .wakanim import WakanimIE

View file

@ -5,7 +5,10 @@ import base64
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import unified_timestamp, parse_duration from ..utils import (
parse_duration,
unified_timestamp,
)
class VXXXIE(InfoExtractor): class VXXXIE(InfoExtractor):
@ -31,67 +34,73 @@ class VXXXIE(InfoExtractor):
def _download_info_object(self, video_id): def _download_info_object(self, video_id):
return self._download_json( return self._download_json(
'https://vxxx.com/api/json/video/86400/0/{}/{}.json'.format( self._INFO_OBJECT_URL_TMPL.format(
self._BASE_URL,
int(video_id) // 1000 * 1000, int(video_id) // 1000 * 1000,
video_id, video_id,
), video_id, headers={'Referer': 'https://vxxx.com'})['video'] ), video_id, headers={'Referer': self._BASE_URL})['video']
def _download_format_object(self, video_id): def _download_format_object(self, video_id):
return self._download_json( return self._download_json(
'https://vxxx.com/api/videofile.php?video_id={}'.format(video_id), self._FORMAT_OBJECT_URL_TMPL.format(self._BASE_URL, video_id),
video_id, video_id,
headers={'Referer': 'https://vxxx.com'} headers={'Referer': self._BASE_URL}
) )
def _get_video_host(self): @classmethod
return 'vxxx.com' def _get_video_host(cls):
# or use the proper Python URL parsing functions
return cls._BASE_URL.split('//')[-1]
def _decode_base164(self, e): def _decode_base164(self, e):
""" """
Some non-standard encoding called "base164" in the JavaScript code. It's Some non-standard encoding called "base164" in the JavaScript code. It's
similar to the regular base64 with a slightly different alphabet: similar to the regular base64 with a slightly different alphabet:
- "АВСЕМ" are Cyrillic letters instead of uppercase English letters - "АВСЕМ" are Cyrillic letters instead of uppercase Latin letters
- "." is used instead of "+"; "," is used instead of "/" - "." is used instead of "+"; "," is used instead of "/"
- "~" is used for padding instead of "=" - "~" is used for padding instead of "="
""" """
return base64.b64decode(e # using the kwarg to memoise the result
.replace("А", "A") def get_trans_tbl(from_, to, tbl={}):
.replace("В", "B") k = (from_, to)
.replace("С", "C") if not tbl.get(k):
.replace("Е", "E") tbl[k] = string.maketrans(from_, to)
.replace("М", "M") return tbl[k]
.replace(".", "+")
.replace(",", "/") # maybe for the 2nd arg:
.replace("~", "=") # import unicodedata and
# ''.join((unicodedata.lookup('CYRILLIC CAPITAL LETTER ' + x) for x in ('A', 'BE', 'ES', 'IE', 'EM'))) + '+/='
trans_tbl = get_trans_tbl('АBCEM.,~', 'ABCEM+/=')
return base64.b64decode(e.translate(trans_tbl)
).decode() ).decode()
def _extract_info(self, url): def _extract_info(self, url):
matches = re.match(self._VALID_URL, url) video_id = self._match_id(url)
video_id = matches.group('id')
info_object = self._download_info_object(video_id) info_object = self._download_info_object(video_id)
title = info_object['title']
stats = info_object.get('statistics') or {}
info = { info = {
'id': video_id, 'id': video_id,
'title': info_object['title'], 'title': title,
'display_id': info_object['dir'], 'display_id': info_object.get('dir'),
'thumbnail': info_object['thumb'], 'thumbnail': url_or_none(info_object.get('thumb')),
'description': info_object['description'], 'description': strip_or_none(info_object('description')) or None,
'timestamp': unified_timestamp(info_object['post_date']), 'timestamp': unified_timestamp(info_object.get('post_date')),
'duration': parse_duration(info_object['duration']), 'duration': parse_duration(info_object.get('duration')),
'view_count': int(info_object['statistics']['viewed']), 'view_count': int_or_none(stats.get('viewed')),
'like_count': int(info_object['statistics']['likes']), 'like_count': int_or_none(stats.get('likes')),
'dislike_count': int(info_object['statistics']['dislikes']), 'dislike_count': int_or_none(stats.get('dislikes')),
'average_rating': float(info_object['statistics']['rating']), 'average_rating': float_or_none(stats.get('rating')),
'categories': [category['title'] for category in info_object['categories'].values()], 'categories': [category['title'] for category in (info_object.get('categories') or {}).values() if category.get('title')],
'age_limit': 18, 'age_limit': 18,
'formats': None
} }
format_object = self._download_format_object(video_id) format_object = self._download_format_object(video_id)
m3u8_formats = self._extract_m3u8_formats( m3u8_formats = self._extract_m3u8_formats(
"https://{}{}&f=video.m3u8".format( 'https://{0}{1}&f=video.m3u8'.format(
self._get_video_host(), self._get_video_host(),
self._decode_base164(format_object[0]['video_url']) self._decode_base164(format_object[0]['video_url'])
), ),