[moviefap] Replace calls to find() with util.xpath_text().

This commit is contained in:
George Brighton 2015-06-27 20:52:12 +01:00
parent 62b742ece3
commit 43b925ce74

View File

@ -3,7 +3,10 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import str_to_int from ..utils import (
xpath_text,
str_to_int
)
class MovieFapIE(InfoExtractor): class MovieFapIE(InfoExtractor):
@ -82,7 +85,7 @@ class MovieFapIE(InfoExtractor):
'title': self._html_search_regex(r'<div id="view_title"><h1>(.*?)</h1>', webpage, 'title'), 'title': self._html_search_regex(r'<div id="view_title"><h1>(.*?)</h1>', webpage, 'title'),
'display_id': re.compile(self._VALID_URL).match(url).group('name'), 'display_id': re.compile(self._VALID_URL).match(url).group('name'),
'thumbnails': self.__get_thumbnail_data(xml), 'thumbnails': self.__get_thumbnail_data(xml),
'thumbnail': xml.find('startThumb').text, 'thumbnail': xpath_text(xml, 'startThumb', 'thumbnail'),
'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description', fatal=False), 'description': self._html_search_regex(r'name="description" value="(.*?)"', webpage, 'description', fatal=False),
'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False), 'uploader_id': self._html_search_regex(r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False),
'view_count': str_to_int(self._html_search_regex(r'<br>Views <strong>([0-9]+)</strong>', webpage, 'view_count, fatal=False')), 'view_count': str_to_int(self._html_search_regex(r'<br>Views <strong>([0-9]+)</strong>', webpage, 'view_count, fatal=False')),
@ -102,7 +105,7 @@ class MovieFapIE(InfoExtractor):
# work out the video URL(s) # work out the video URL(s)
if xml.find('videoLink') is not None: if xml.find('videoLink') is not None:
# single format available # single format available
info['url'] = xml.find('videoLink').text info['url'] = xpath_text(xml, 'videoLink', 'url', True)
else: else:
# multiple formats available # multiple formats available
info['formats'] = [] info['formats'] = []
@ -110,8 +113,8 @@ class MovieFapIE(InfoExtractor):
# N.B. formats are already in ascending order of quality # N.B. formats are already in ascending order of quality
for item in xml.find('quality').findall('item'): for item in xml.find('quality').findall('item'):
info['formats'].append({ info['formats'].append({
'url': item.find('videoLink').text, 'url': xpath_text(item, 'videoLink', 'url', True),
'resolution': item.find('res').text # 480p etc. 'resolution': xpath_text(item, 'res', 'resolution', True) # 480p etc.
}) })
return info return info