]> gitweb @ CieloNegro.org - youtube-dl.git/blobdiff - youtube_dl/extractor/moviefap.py
[moviefap] Wrap long lines
[youtube-dl.git] / youtube_dl / extractor / moviefap.py
index 6da93dbc9b71bc5dbd4233dcc8344f7a11e27523..9de052a9987f5583018839228121a707dc265b01 100644 (file)
@@ -7,6 +7,7 @@ from ..utils import (
     xpath_text,
     str_to_int
 )
+from ..compat import compat_str
 
 
 class MovieFapIE(InfoExtractor):
@@ -65,7 +66,7 @@ class MovieFapIE(InfoExtractor):
         thumbnails = []
         for i in range(first, last + 1):
             thumbnails.append({
-                'url': pattern.replace('#', str(i)),
+                'url': pattern.replace('#', compat_str(i)),
                 'width': width,
                 'height': height
             })
@@ -77,23 +78,32 @@ class MovieFapIE(InfoExtractor):
         webpage = self._download_webpage(url, video_id)
 
         # find and retrieve the XML document detailing video download URLs
-        info_url = self._html_search_regex(r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters')
+        info_url = self._html_search_regex( \
+                r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters')
         xml = self._download_xml(info_url, video_id)
 
         info = {
             'id': video_id,
-            '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'),
             'thumbnails': self.__get_thumbnail_data(xml),
             'thumbnail': xpath_text(xml, 'startThumb', 'thumbnail'),
-            '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),
-            'view_count': str_to_int(self._html_search_regex(r'<br>Views <strong>([0-9]+)</strong>', webpage, 'view_count, fatal=False')),
-            'average_rating': float(self._html_search_regex(r'Current Rating<br> <strong>(.*?)</strong>', webpage, 'average_rating', fatal=False)),
-            'comment_count': str_to_int(self._html_search_regex(r'<span id="comCount">([0-9]+)</span>', webpage, 'comment_count', 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),
+            'view_count': str_to_int(self._html_search_regex( \
+                    r'<br>Views <strong>([0-9]+)</strong>', webpage, 'view_count, fatal=False')),
+            'average_rating': float(self._html_search_regex( \
+                    r'Current Rating<br> <strong>(.*?)</strong>', webpage, 'average_rating', fatal=False)),
+            'comment_count': str_to_int(self._html_search_regex( \
+                    r'<span id="comCount">([0-9]+)</span>', webpage, 'comment_count', fatal=False)),
             'age_limit': 18,
-            'webpage_url': self._html_search_regex(r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False),
-            'categories': self._html_search_regex(r'</div>\s*(.*?)\s*<br>', webpage, 'categories', fatal=False).split(', ')
+            'webpage_url': self._html_search_regex( \
+                    r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False),
+            'categories': self._html_search_regex( \
+                    r'</div>\s*(.*?)\s*<br>', webpage, 'categories', fatal=False).split(', ')
         }
 
         # find and add the format
@@ -110,11 +120,14 @@ class MovieFapIE(InfoExtractor):
             # multiple formats available
             info['formats'] = []
 
-            # N.B. formats are already in ascending order of quality
             for item in xml.find('quality').findall('item'):
+                resolution = xpath_text(item, 'res', 'resolution', True)  # 480p etc.
                 info['formats'].append({
                     'url': xpath_text(item, 'videoLink', 'url', True),
-                    'resolution': xpath_text(item, 'res', 'resolution', True)  # 480p etc.
+                    'resolution': resolution,
+                    'height': int(re.findall(r'\d+', resolution)[0])
                 })
 
+            self._sort_formats(info['formats'])
+
         return info