diff options
author | Peter Rowlands <peter@pmrowla.com> | 2016-05-06 01:24:02 +0900 |
---|---|---|
committer | Peter Rowlands <peter@pmrowla.com> | 2016-05-06 01:24:02 +0900 |
commit | 833b644fffae4d4cb0807591006e34ef963d9bc0 (patch) | |
tree | e3c20a6069e9253846267ded908f6f0cd3b7944b | |
parent | 57cf9b7f0689ed7b643ce863427c3211e407e5bf (diff) |
use xpath_text
-rw-r--r-- | youtube_dl/extractor/afreecatv.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/youtube_dl/extractor/afreecatv.py b/youtube_dl/extractor/afreecatv.py index d57546e49..9f9399edc 100644 --- a/youtube_dl/extractor/afreecatv.py +++ b/youtube_dl/extractor/afreecatv.py @@ -9,6 +9,7 @@ from ..compat import ( from ..utils import ( ExtractorError, int_or_none, + xpath_text, ) @@ -41,25 +42,24 @@ class AfreecaTVIE(InfoExtractor): path='/api/video/get_video_info.php')) video_xml = self._download_xml(info_url, video_id) - track = video_xml.find('track') - if track.find('flag').text != 'SUCCEED': + if xpath_text(video_xml, './track/flag', default='FAIL') != 'SUCCEED': raise ExtractorError('Specified AfreecaTV video does not exist', expected=True) - title = track.find('title').text - uploader = track.find('nickname').text - uploader_id = track.find('bj_id').text - duration = int_or_none(track.find('duration').text) - thumbnail = track.find('titleImage').text + title = xpath_text(video_xml, './track/title', 'title') + uploader = xpath_text(video_xml, './track/nickname', 'uploader') + uploader_id = xpath_text(video_xml, './track/bj_id', 'uploader id') + duration = int_or_none(xpath_text(video_xml, './track/duration', + 'duration')) + thumbnail = xpath_text(video_xml, './track/titleImage', 'thumbnail') entries = [] - for video in track.findall('video'): - for video_file in video.findall('file'): - entries.append({ - 'id': video_file.get('key'), - 'title': title, - 'duration': int_or_none(video_file.get('duration')), - 'formats': [{'url': video_file.text}] - }) + for video_file in video_xml.findall('./track/video/file'): + entries.append({ + 'id': video_file.get('key'), + 'title': title, + 'duration': int_or_none(video_file.get('duration')), + 'formats': [{'url': video_file.text}] + }) info = { 'id': video_id, |