Browse Source

[utils] Share JSON-LD regex

master-ytdl-org
Sergey M․ 6 years ago
parent
commit
0685d9727b
No known key found for this signature in database GPG Key ID: 2C393E0F18A9236D
2 changed files with 3 additions and 2 deletions
  1. +2
    -2
      youtube_dl/extractor/common.py
  2. +1
    -0
      youtube_dl/utils.py

+ 2
- 2
youtube_dl/extractor/common.py View File

@ -52,6 +52,7 @@ from ..utils import (
GeoUtils,
int_or_none,
js_to_json,
JSON_LD_RE,
mimetype2ext,
orderedSet,
parse_codecs,
@ -1149,8 +1150,7 @@ class InfoExtractor(object):
def _search_json_ld(self, html, video_id, expected_type=None, **kwargs):
json_ld = self._search_regex(
r'(?s)<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json_ld>.+?)</script>',
html, 'JSON-LD', group='json_ld', **kwargs)
JSON_LD_RE, html, 'JSON-LD', group='json_ld', **kwargs)
default = kwargs.get('default', NO_DEFAULT)
if not json_ld:
return default if default is not NO_DEFAULT else {}


+ 1
- 0
youtube_dl/utils.py View File

@ -184,6 +184,7 @@ DATE_FORMATS_MONTH_FIRST.extend([
])
PACKED_CODES_RE = r"}\('(.+)',(\d+),(\d+),'([^']+)'\.split\('\|'\)"
JSON_LD_RE = r'(?is)<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json_ld>.+?)</script>'
def preferredencoding():


Loading…
Cancel
Save