mirror of
https://github.com/l1ving/youtube-dl
synced 2020-11-18 19:53:54 -08:00
use regex instead
This commit is contained in:
parent
6af62a164c
commit
d4651f3926
@ -9,9 +9,7 @@ from ..utils import (
|
|||||||
int_or_none,
|
int_or_none,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
)
|
)
|
||||||
from urllib.parse import urlparse
|
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
import lxml.html
|
|
||||||
|
|
||||||
|
|
||||||
class AolIE(InfoExtractor):
|
class AolIE(InfoExtractor):
|
||||||
@ -69,27 +67,15 @@ class AolIE(InfoExtractor):
|
|||||||
return urlopen(url).read()
|
return urlopen(url).read()
|
||||||
|
|
||||||
def _download_and_extract_video_id_from_page(self, url):
|
def _download_and_extract_video_id_from_page(self, url):
|
||||||
page_bytes = self._download_page(url)
|
video_id_regex = r'<script [^>]*src="[^"]*vid=(?P<vid>[^?/]*)'
|
||||||
tree = lxml.html.fromstring(page_bytes)
|
page_bytes = self._download_page(url).decode()
|
||||||
src_xpath = tree.xpath("//script[contains(@src, "
|
mobj = re.search(video_id_regex, page_bytes)
|
||||||
"'delivery.vidible.tv')]")
|
return mobj.group('vid')
|
||||||
src_tag = src_xpath[0].attrib.get('src')
|
|
||||||
parsed_vid_url = urlparse(src_tag)
|
|
||||||
vid_url_path = parsed_vid_url.path
|
|
||||||
vid_url_params = vid_url_path.split('/')
|
|
||||||
return self._find_vid_param(vid_url_params)
|
|
||||||
|
|
||||||
def _find_vid_param(self, vid_url_params: [str]):
|
|
||||||
for param in vid_url_params:
|
|
||||||
if param.startswith('vid='):
|
|
||||||
return param.split('=')[1]
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
# video_id = self._match_id(url)
|
|
||||||
print(f'getting video_id')
|
|
||||||
video_id = self._download_and_extract_video_id_from_page(url)
|
video_id = self._download_and_extract_video_id_from_page(url)
|
||||||
print(f'video_id: {video_id}')
|
if video_id is None:
|
||||||
|
raise ExtractorError('Could not find video_id')
|
||||||
|
|
||||||
response = self._download_json(
|
response = self._download_json(
|
||||||
'https://feedapi.b2c.on.aol.com/v1.0/app/videos/aolon/%s/details' % video_id,
|
'https://feedapi.b2c.on.aol.com/v1.0/app/videos/aolon/%s/details' % video_id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user