Skip to content

Commit de7d597

Browse files
dirkfGitHub Actions
authored and
GitHub Actions
committed
[Vbox7] Improve extraction, adding features from yt-dlp PR #9100
* changes from yt-dlp/yt-dlp#9100 (thx seproDev): - attempt HLS extraction - re-enable XFF - test `view_count`, `duration` extraction * improve commenting, error checks
1 parent 2547f3b commit de7d597

File tree

1 file changed

+53
-27
lines changed

1 file changed

+53
-27
lines changed

youtube_dl/extractor/vbox7.py

+53-27
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
from .common import InfoExtractor
88
from ..compat import compat_kwargs
99
from ..utils import (
10+
base_url,
1011
determine_ext,
1112
ExtractorError,
1213
float_or_none,
1314
merge_dicts,
1415
T,
1516
traverse_obj,
1617
txt_or_none,
18+
url_basename,
1719
url_or_none,
1820
)
1921

@@ -33,26 +35,28 @@ class Vbox7IE(InfoExtractor):
3335
'''
3436
_EMBED_REGEX = [r'<iframe[^>]+src=(?P<q>["\'])(?P<url>(?:https?:)?//vbox7\.com/emb/external\.php.+?)(?P=q)']
3537
_GEO_COUNTRIES = ['BG']
36-
_GEO_BYPASS = False
3738
_TESTS = [{
39+
# the http: URL just redirects here
3840
'url': 'https://vbox7.com/play:0946fff23c',
3941
'md5': '50ca1f78345a9c15391af47d8062d074',
4042
'info_dict': {
4143
'id': '0946fff23c',
4244
'ext': 'mp4',
4345
'title': 'Борисов: Притеснен съм за бъдещето на България',
4446
'description': 'По думите му е опасно страната ни да бъде обявена за "сигурна"',
45-
'thumbnail': r're:^https?://.*\.jpg$',
4647
'timestamp': 1470982814,
4748
'upload_date': '20160812',
4849
'uploader': 'zdraveibulgaria',
50+
'thumbnail': r're:^https?://.*\.jpg$',
51+
'view_count': int,
52+
'duration': 2640,
4953
},
5054
'expected_warnings': [
5155
'Unable to download webpage',
5256
],
5357
}, {
5458
'url': 'http://vbox7.com/play:249bb972c2',
55-
'md5': 'aaf19465e37ec0b30b918df83ec32c50',
59+
'md5': '99f65c0c9ef9b682b97313e052734c3f',
5660
'info_dict': {
5761
'id': '249bb972c2',
5862
'ext': 'mp4',
@@ -61,7 +65,11 @@ class Vbox7IE(InfoExtractor):
6165
'timestamp': 1360215023,
6266
'upload_date': '20130207',
6367
'uploader': 'svideteliat_ot_varshava',
68+
'thumbnail': 'https://i49.vbox7.com/o/249/249bb972c20.jpg',
69+
'view_count': int,
70+
'duration': 83,
6471
},
72+
'expected_warnings': ['Failed to download m3u8 information'],
6573
}, {
6674
'url': 'http://vbox7.com/emb/external.php?vid=a240d20f9c&autoplay=1',
6775
'only_matching': True,
@@ -76,6 +84,9 @@ def _extract_url(cls, webpage):
7684
if mobj:
7785
return mobj.group('url')
7886

87+
# specialisation to transform what looks like ld+json that
88+
# may contain invalid character combinations
89+
7990
# transform_source=None, fatal=True
8091
def _parse_json(self, json_string, video_id, *args, **kwargs):
8192
if '"@context"' in json_string[:30]:
@@ -103,49 +114,64 @@ def _real_extract(self, url):
103114

104115
now = time.time()
105116
response = self._download_json(
106-
'https://www.vbox7.com/aj/player/item/options?vid=%s' % (video_id,),
107-
video_id, headers={'Referer': url})
117+
'https://www.vbox7.com/aj/player/item/options', video_id,
118+
query={'vid': video_id}, headers={'Referer': url})
108119
# estimate time to which possible `ago` member is relative
109120
now = now + 0.5 * (time.time() - now)
110121

111-
if 'error' in response:
122+
if traverse_obj(response, 'error'):
112123
raise ExtractorError(
113124
'%s said: %s' % (self.IE_NAME, response['error']), expected=True)
114125

115-
video_url = traverse_obj(response, ('options', 'src', T(url_or_none)))
126+
src_url = traverse_obj(response, ('options', 'src', T(url_or_none))) or ''
116127

117-
if '/na.mp4' in video_url or '':
128+
fmt_base = url_basename(src_url).rsplit('.', 1)[0].rsplit('_', 1)[0]
129+
if fmt_base in ('na', 'vn'):
118130
self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
119131

120-
ext = determine_ext(video_url)
132+
ext = determine_ext(src_url)
121133
if ext == 'mpd':
122-
# In case MPD cannot be parsed, or anyway, get mp4 combined
123-
# formats usually provided to Safari, iOS, and old Windows
134+
# extract MPD
124135
try:
125136
formats, subtitles = self._extract_mpd_formats_and_subtitles(
126-
video_url, video_id, 'dash', fatal=False)
127-
except KeyError:
137+
src_url, video_id, 'dash', fatal=False)
138+
except KeyError: # fatal doesn't catch this
128139
self.report_warning('Failed to parse MPD manifest')
129140
formats, subtitles = [], {}
141+
elif ext != 'm3u8':
142+
formats = [{
143+
'url': src_url,
144+
}] if src_url else []
145+
subtitles = {}
130146

147+
if src_url:
148+
# possibly extract HLS, based on https://github.com/yt-dlp/yt-dlp/pull/9100
149+
fmt_base = base_url(src_url) + fmt_base
150+
# prepare for _extract_m3u8_formats_and_subtitles()
151+
# hls_formats, hls_subs = self._extract_m3u8_formats_and_subtitles(
152+
hls_formats = self._extract_m3u8_formats(
153+
'{0}.m3u8'.format(fmt_base), video_id, m3u8_id='hls', fatal=False)
154+
formats.extend(hls_formats)
155+
# self._merge_subtitles(hls_subs, target=subtitles)
156+
157+
# In case MPD/HLS cannot be parsed, or anyway, get mp4 combined
158+
# formats usually provided to Safari, iOS, and old Windows
131159
video = response['options']
132160
resolutions = (1080, 720, 480, 240, 144)
133-
highest_res = traverse_obj(video, ('highestRes', T(int))) or resolutions[0]
134-
for res in traverse_obj(video, ('resolutions', lambda _, r: int(r) > 0)) or resolutions:
135-
if res > highest_res:
136-
continue
137-
formats.append({
138-
'url': video_url.replace('.mpd', '_%d.mp4' % res),
139-
'format_id': '%dp' % res,
161+
highest_res = traverse_obj(video, (
162+
'highestRes', T(int))) or resolutions[0]
163+
resolutions = traverse_obj(video, (
164+
'resolutions', lambda _, r: highest_res >= int(r) > 0)) or resolutions
165+
mp4_formats = traverse_obj(resolutions, (
166+
Ellipsis, T(lambda res: {
167+
'url': '{0}_{1}.mp4'.format(fmt_base, res),
168+
'format_id': 'http-{0}'.format(res),
140169
'height': res,
141-
})
170+
})))
142171
# if above formats are flaky, enable the line below
143-
# self._check_formats(formats, video_id)
144-
else:
145-
formats = [{
146-
'url': video_url,
147-
}]
148-
subtitles = {}
172+
# self._check_formats(mp4_formats, video_id)
173+
formats.extend(mp4_formats)
174+
149175
self._sort_formats(formats)
150176

151177
webpage = self._download_webpage(url, video_id, fatal=False) or ''

0 commit comments

Comments
 (0)