Prefer helper funcs, control flow w/ return values
Native regex and json parse have been replaced by library versions with more comprehensive error handling. There was flow control via try/catch before that was based on an error being thrown only in test. This has been replaced by an if/else based on return value.
This commit is contained in:
parent
28fd6fade5
commit
71b7f6133b
@ -2,12 +2,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from .ooyala import OoyalaIE
|
from .ooyala import OoyalaIE
|
||||||
from youtube_dl.utils import (
|
|
||||||
ExtractorError,
|
|
||||||
)
|
|
||||||
|
|
||||||
import json
|
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
@ -56,22 +51,28 @@ class TastyTradeIE(InfoExtractor):
|
|||||||
|
|
||||||
info = {'id': None, 'title': None, 'description': None}
|
info = {'id': None, 'title': None, 'description': None}
|
||||||
|
|
||||||
try:
|
json_ld_info = self._search_json_ld(
|
||||||
info = self._search_json_ld(webpage, display_id, fatal=False)
|
webpage, display_id, default=None, fatal=False)
|
||||||
except ExtractorError as ex:
|
|
||||||
json_string_match = re.search(
|
|
||||||
r'var episodeData = \$.parseJSON\("(?P<episode_json>.*)"\)', webpage, 0)
|
|
||||||
|
|
||||||
if (json_string_match):
|
if (json_ld_info):
|
||||||
escaped_json_string = json_string_match.group('episode_json')
|
info = json_ld_info
|
||||||
|
else:
|
||||||
|
escaped_json_string = self._search_regex(
|
||||||
|
r'var episodeData = \$.parseJSON\("(?P<episode_json>.*)"\)',
|
||||||
|
webpage,
|
||||||
|
'episode json',
|
||||||
|
fatal=False,
|
||||||
|
group='episode_json'
|
||||||
|
)
|
||||||
|
|
||||||
|
if (escaped_json_string):
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
unescaped_json_string = bytes(
|
unescaped_json_string = bytes(
|
||||||
escaped_json_string, "utf-8").decode('unicode_escape')
|
escaped_json_string, "utf-8").decode('unicode_escape')
|
||||||
else:
|
else:
|
||||||
unescaped_json_string = escaped_json_string.decode(
|
unescaped_json_string = escaped_json_string.decode(
|
||||||
'string_escape')
|
'string_escape')
|
||||||
metadata = json.loads(unescaped_json_string)
|
metadata = self._parse_json(unescaped_json_string, ooyala_code)
|
||||||
info = {
|
info = {
|
||||||
'id': metadata.get('mediaId'),
|
'id': metadata.get('mediaId'),
|
||||||
'title': metadata.get('title'),
|
'title': metadata.get('title'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user