1
0
Fork 0
mirror of https://gitlab.com/dstftw/youtube-dl.git synced 2020-11-16 09:42:26 +00:00

use xpath_text

This commit is contained in:
Peter Rowlands 2016-05-06 01:24:02 +09:00
parent 57cf9b7f06
commit 833b644fff

View file

@ -9,6 +9,7 @@ from ..compat import (
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
int_or_none, int_or_none,
xpath_text,
) )
@ -41,19 +42,18 @@ class AfreecaTVIE(InfoExtractor):
path='/api/video/get_video_info.php')) path='/api/video/get_video_info.php'))
video_xml = self._download_xml(info_url, video_id) video_xml = self._download_xml(info_url, video_id)
track = video_xml.find('track') if xpath_text(video_xml, './track/flag', default='FAIL') != 'SUCCEED':
if track.find('flag').text != 'SUCCEED':
raise ExtractorError('Specified AfreecaTV video does not exist', raise ExtractorError('Specified AfreecaTV video does not exist',
expected=True) expected=True)
title = track.find('title').text title = xpath_text(video_xml, './track/title', 'title')
uploader = track.find('nickname').text uploader = xpath_text(video_xml, './track/nickname', 'uploader')
uploader_id = track.find('bj_id').text uploader_id = xpath_text(video_xml, './track/bj_id', 'uploader id')
duration = int_or_none(track.find('duration').text) duration = int_or_none(xpath_text(video_xml, './track/duration',
thumbnail = track.find('titleImage').text 'duration'))
thumbnail = xpath_text(video_xml, './track/titleImage', 'thumbnail')
entries = [] entries = []
for video in track.findall('video'): for video_file in video_xml.findall('./track/video/file'):
for video_file in video.findall('file'):
entries.append({ entries.append({
'id': video_file.get('key'), 'id': video_file.get('key'),
'title': title, 'title': title,