Skip to content

Commit

Permalink
[Vbox7IE] Sanitise ld+json containing unexpected characters
Browse files Browse the repository at this point in the history
* based on PR #29680
* added hack to force invoking `transform_source`
* fixes #26218
  • Loading branch information
dirkf committed Feb 2, 2024
1 parent bdda6b8 commit 4416f82
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions youtube_dl/extractor/vbox7.py
Expand Up @@ -5,6 +5,7 @@
import time

from .common import InfoExtractor
from ..compat import compat_kwargs
from ..utils import (
determine_ext,
ExtractorError,
Expand Down Expand Up @@ -75,6 +76,27 @@ def _extract_url(cls, webpage):
if mobj:
return mobj.group('url')

# 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)

def _real_extract(self, url):
video_id = self._match_id(url)
url = 'https://vbox7.com/play:%s' % (video_id,)
Expand Down

0 comments on commit 4416f82

Please sign in to comment.