2016-10-02 05:39:18 -06:00
|
|
|
|
# coding: utf-8
|
2014-02-04 15:02:53 -07:00
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
2016-08-16 12:02:59 -06:00
|
|
|
|
import re
|
2024-01-27 08:57:25 -07:00
|
|
|
|
import time
|
2016-08-16 12:02:59 -06:00
|
|
|
|
|
2013-06-23 14:25:46 -06:00
|
|
|
|
from .common import InfoExtractor
|
2024-01-27 11:17:09 -07:00
|
|
|
|
from ..compat import compat_kwargs
|
2024-01-27 08:57:25 -07:00
|
|
|
|
from ..utils import (
|
2024-02-18 13:55:01 -07:00
|
|
|
|
base_url,
|
2024-01-27 08:57:25 -07:00
|
|
|
|
determine_ext,
|
|
|
|
|
ExtractorError,
|
|
|
|
|
float_or_none,
|
|
|
|
|
merge_dicts,
|
|
|
|
|
T,
|
|
|
|
|
traverse_obj,
|
|
|
|
|
txt_or_none,
|
2024-02-18 13:55:01 -07:00
|
|
|
|
url_basename,
|
2024-01-27 08:57:25 -07:00
|
|
|
|
url_or_none,
|
|
|
|
|
)
|
2013-06-23 14:25:46 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Vbox7IE(InfoExtractor):
|
2016-12-20 07:51:11 -07:00
|
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
|
https?://
|
|
|
|
|
(?:[^/]+\.)?vbox7\.com/
|
|
|
|
|
(?:
|
|
|
|
|
play:|
|
|
|
|
|
(?:
|
|
|
|
|
emb/external\.php|
|
|
|
|
|
player/ext\.swf
|
|
|
|
|
)\?.*?\bvid=
|
|
|
|
|
)
|
|
|
|
|
(?P<id>[\da-fA-F]+)
|
|
|
|
|
'''
|
2024-01-27 08:57:25 -07:00
|
|
|
|
_EMBED_REGEX = [r'<iframe[^>]+src=(?P<q>["\'])(?P<url>(?:https?:)?//vbox7\.com/emb/external\.php.+?)(?P=q)']
|
2017-02-18 13:53:23 -07:00
|
|
|
|
_GEO_COUNTRIES = ['BG']
|
2016-08-13 02:47:20 -06:00
|
|
|
|
_TESTS = [{
|
2024-02-18 13:55:01 -07:00
|
|
|
|
# the http: URL just redirects here
|
2024-01-27 08:57:25 -07:00
|
|
|
|
'url': 'https://vbox7.com/play:0946fff23c',
|
|
|
|
|
'md5': '50ca1f78345a9c15391af47d8062d074',
|
2016-08-13 02:47:20 -06:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '0946fff23c',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Борисов: Притеснен съм за бъдещето на България',
|
2016-12-20 07:51:11 -07:00
|
|
|
|
'description': 'По думите му е опасно страната ни да бъде обявена за "сигурна"',
|
|
|
|
|
'timestamp': 1470982814,
|
|
|
|
|
'upload_date': '20160812',
|
|
|
|
|
'uploader': 'zdraveibulgaria',
|
2024-02-18 13:55:01 -07:00
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
|
|
|
|
'view_count': int,
|
|
|
|
|
'duration': 2640,
|
2016-12-20 07:51:11 -07:00
|
|
|
|
},
|
2024-01-27 08:57:25 -07:00
|
|
|
|
'expected_warnings': [
|
|
|
|
|
'Unable to download webpage',
|
|
|
|
|
],
|
2016-08-13 02:47:20 -06:00
|
|
|
|
}, {
|
2014-02-04 15:02:53 -07:00
|
|
|
|
'url': 'http://vbox7.com/play:249bb972c2',
|
2024-02-18 13:55:01 -07:00
|
|
|
|
'md5': '99f65c0c9ef9b682b97313e052734c3f',
|
2014-02-04 15:02:53 -07:00
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '249bb972c2',
|
2014-09-27 02:53:02 -06:00
|
|
|
|
'ext': 'mp4',
|
2014-02-04 15:02:53 -07:00
|
|
|
|
'title': 'Смях! Чудо - чист за секунди - Скрита камера',
|
2024-01-27 08:57:25 -07:00
|
|
|
|
'description': 'Смях! Чудо - чист за секунди - Скрита камера',
|
|
|
|
|
'timestamp': 1360215023,
|
|
|
|
|
'upload_date': '20130207',
|
|
|
|
|
'uploader': 'svideteliat_ot_varshava',
|
2024-02-18 13:55:01 -07:00
|
|
|
|
'thumbnail': 'https://i49.vbox7.com/o/249/249bb972c20.jpg',
|
|
|
|
|
'view_count': int,
|
|
|
|
|
'duration': 83,
|
2014-02-04 15:02:53 -07:00
|
|
|
|
},
|
2024-02-18 13:55:01 -07:00
|
|
|
|
'expected_warnings': ['Failed to download m3u8 information'],
|
2016-08-16 11:42:02 -06:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://vbox7.com/emb/external.php?vid=a240d20f9c&autoplay=1',
|
|
|
|
|
'only_matching': True,
|
2016-12-20 07:51:11 -07:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://i49.vbox7.com/player/ext.swf?vid=0946fff23c&autoplay=1',
|
|
|
|
|
'only_matching': True,
|
2016-08-13 02:47:20 -06:00
|
|
|
|
}]
|
2013-06-23 14:25:46 -06:00
|
|
|
|
|
2024-01-27 08:57:25 -07:00
|
|
|
|
@classmethod
|
|
|
|
|
def _extract_url(cls, webpage):
|
|
|
|
|
mobj = re.search(cls._EMBED_REGEX[0], webpage)
|
2016-08-16 12:02:59 -06:00
|
|
|
|
if mobj:
|
|
|
|
|
return mobj.group('url')
|
|
|
|
|
|
2024-02-18 13:55:01 -07:00
|
|
|
|
# specialisation to transform what looks like ld+json that
|
|
|
|
|
# may contain invalid character combinations
|
|
|
|
|
|
2024-01-27 11:17:09 -07:00
|
|
|
|
# transform_source=None, fatal=True
|
|
|
|
|
def _parse_json(self, json_string, video_id, *args, **kwargs):
|
|
|
|
|
if '"@context"' in json_string[:30]:
|
|
|
|
|
# this is ld+json, or that's the way to bet
|
|
|
|
|
transform_source = args[0] if len(args) > 0 else kwargs.get('transform_source')
|
|
|
|
|
if not transform_source:
|
|
|
|
|
|
|
|
|
|
def fix_chars(src):
|
|
|
|
|
# fix malformed ld+json: replace raw CRLFs with escaped LFs
|
|
|
|
|
return re.sub(
|
|
|
|
|
r'"[^"]+"', lambda m: re.sub(r'\r?\n', r'\\n', m.group(0)), src)
|
|
|
|
|
|
|
|
|
|
if len(args) > 0:
|
|
|
|
|
args = (fix_chars,) + args[1:]
|
|
|
|
|
else:
|
|
|
|
|
kwargs['transform_source'] = fix_chars
|
|
|
|
|
kwargs = compat_kwargs(kwargs)
|
|
|
|
|
|
|
|
|
|
return super(Vbox7IE, self)._parse_json(
|
|
|
|
|
json_string, video_id, *args, **kwargs)
|
|
|
|
|
|
2014-02-04 15:02:53 -07:00
|
|
|
|
def _real_extract(self, url):
|
2014-12-13 04:24:42 -07:00
|
|
|
|
video_id = self._match_id(url)
|
2024-01-27 08:57:25 -07:00
|
|
|
|
url = 'https://vbox7.com/play:%s' % (video_id,)
|
2013-06-23 14:25:46 -06:00
|
|
|
|
|
2024-01-27 08:57:25 -07:00
|
|
|
|
now = time.time()
|
2016-12-20 07:51:11 -07:00
|
|
|
|
response = self._download_json(
|
2024-02-18 13:55:01 -07:00
|
|
|
|
'https://www.vbox7.com/aj/player/item/options', video_id,
|
|
|
|
|
query={'vid': video_id}, headers={'Referer': url})
|
2024-01-27 08:57:25 -07:00
|
|
|
|
# estimate time to which possible `ago` member is relative
|
|
|
|
|
now = now + 0.5 * (time.time() - now)
|
2016-08-13 02:47:20 -06:00
|
|
|
|
|
2024-02-18 13:55:01 -07:00
|
|
|
|
if traverse_obj(response, 'error'):
|
2016-12-20 07:51:11 -07:00
|
|
|
|
raise ExtractorError(
|
|
|
|
|
'%s said: %s' % (self.IE_NAME, response['error']), expected=True)
|
2016-08-13 02:47:20 -06:00
|
|
|
|
|
2024-02-18 13:55:01 -07:00
|
|
|
|
src_url = traverse_obj(response, ('options', 'src', T(url_or_none))) or ''
|
2016-08-13 02:47:20 -06:00
|
|
|
|
|
2024-02-18 13:55:01 -07:00
|
|
|
|
fmt_base = url_basename(src_url).rsplit('.', 1)[0].rsplit('_', 1)[0]
|
|
|
|
|
if fmt_base in ('na', 'vn'):
|
2017-02-18 13:53:23 -07:00
|
|
|
|
self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
|
2013-06-23 14:25:46 -06:00
|
|
|
|
|
2024-02-18 13:55:01 -07:00
|
|
|
|
ext = determine_ext(src_url)
|
2024-01-27 08:57:25 -07:00
|
|
|
|
if ext == 'mpd':
|
2024-02-18 13:55:01 -07:00
|
|
|
|
# extract MPD
|
2024-01-27 08:57:25 -07:00
|
|
|
|
try:
|
|
|
|
|
formats, subtitles = self._extract_mpd_formats_and_subtitles(
|
2024-02-18 13:55:01 -07:00
|
|
|
|
src_url, video_id, 'dash', fatal=False)
|
|
|
|
|
except KeyError: # fatal doesn't catch this
|
2024-01-27 08:57:25 -07:00
|
|
|
|
self.report_warning('Failed to parse MPD manifest')
|
|
|
|
|
formats, subtitles = [], {}
|
2024-02-18 13:55:01 -07:00
|
|
|
|
elif ext != 'm3u8':
|
|
|
|
|
formats = [{
|
|
|
|
|
'url': src_url,
|
|
|
|
|
}] if src_url else []
|
|
|
|
|
subtitles = {}
|
2024-01-27 08:57:25 -07:00
|
|
|
|
|
2024-02-18 13:55:01 -07:00
|
|
|
|
if src_url:
|
|
|
|
|
# possibly extract HLS, based on https://github.com/yt-dlp/yt-dlp/pull/9100
|
|
|
|
|
fmt_base = base_url(src_url) + fmt_base
|
|
|
|
|
# prepare for _extract_m3u8_formats_and_subtitles()
|
|
|
|
|
# hls_formats, hls_subs = self._extract_m3u8_formats_and_subtitles(
|
|
|
|
|
hls_formats = self._extract_m3u8_formats(
|
|
|
|
|
'{0}.m3u8'.format(fmt_base), video_id, m3u8_id='hls', fatal=False)
|
|
|
|
|
formats.extend(hls_formats)
|
|
|
|
|
# self._merge_subtitles(hls_subs, target=subtitles)
|
|
|
|
|
|
|
|
|
|
# In case MPD/HLS cannot be parsed, or anyway, get mp4 combined
|
|
|
|
|
# formats usually provided to Safari, iOS, and old Windows
|
2024-01-27 08:57:25 -07:00
|
|
|
|
video = response['options']
|
|
|
|
|
resolutions = (1080, 720, 480, 240, 144)
|
2024-02-18 13:55:01 -07:00
|
|
|
|
highest_res = traverse_obj(video, (
|
|
|
|
|
'highestRes', T(int))) or resolutions[0]
|
|
|
|
|
resolutions = traverse_obj(video, (
|
|
|
|
|
'resolutions', lambda _, r: highest_res >= int(r) > 0)) or resolutions
|
|
|
|
|
mp4_formats = traverse_obj(resolutions, (
|
|
|
|
|
Ellipsis, T(lambda res: {
|
|
|
|
|
'url': '{0}_{1}.mp4'.format(fmt_base, res),
|
|
|
|
|
'format_id': 'http-{0}'.format(res),
|
2024-01-27 08:57:25 -07:00
|
|
|
|
'height': res,
|
2024-02-18 13:55:01 -07:00
|
|
|
|
})))
|
2024-01-27 08:57:25 -07:00
|
|
|
|
# if above formats are flaky, enable the line below
|
2024-02-18 13:55:01 -07:00
|
|
|
|
# self._check_formats(mp4_formats, video_id)
|
|
|
|
|
formats.extend(mp4_formats)
|
|
|
|
|
|
2024-01-27 08:57:25 -07:00
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id, fatal=False) or ''
|
|
|
|
|
|
|
|
|
|
info = self._search_json_ld(
|
|
|
|
|
webpage.replace('"/*@context"', '"@context"'), video_id,
|
|
|
|
|
fatal=False) if webpage else {}
|
|
|
|
|
|
|
|
|
|
if not info.get('title'):
|
|
|
|
|
info['title'] = traverse_obj(response, (
|
|
|
|
|
'options', 'title', T(txt_or_none))) or self._og_search_title(webpage)
|
|
|
|
|
|
|
|
|
|
def if_missing(k):
|
|
|
|
|
return lambda x: None if k in info else x
|
|
|
|
|
|
|
|
|
|
info = merge_dicts(info, {
|
2014-02-04 15:02:53 -07:00
|
|
|
|
'id': video_id,
|
2024-01-27 08:57:25 -07:00
|
|
|
|
'formats': formats,
|
|
|
|
|
'subtitles': subtitles or None,
|
|
|
|
|
}, info, traverse_obj(response, ('options', {
|
|
|
|
|
'uploader': ('uploader', T(txt_or_none)),
|
|
|
|
|
'timestamp': ('ago', T(if_missing('timestamp')), T(lambda t: int(round((now - t) / 60.0)) * 60)),
|
|
|
|
|
'duration': ('duration', T(if_missing('duration')), T(float_or_none)),
|
|
|
|
|
})))
|
|
|
|
|
if 'thumbnail' not in info:
|
|
|
|
|
info['thumbnail'] = self._proto_relative_url(
|
2016-12-20 07:51:11 -07:00
|
|
|
|
info.get('thumbnail') or self._og_search_thumbnail(webpage),
|
2024-01-27 08:57:25 -07:00
|
|
|
|
'https:'),
|
|
|
|
|
|
2016-12-20 07:51:11 -07:00
|
|
|
|
return info
|