Fix imports and general cleanup
[youtube-dl] / youtube_dl / extractor / videomega.py
index 1b6b658398874c175e9253ff9e9ac31c0be1b6d7..7a78f0d264a47fc85c53cd815242e629ee38ed30 100644 (file)
@@ -1,11 +1,11 @@
 # coding: utf-8
 from __future__ import unicode_literals
 
-import re
-
 from .common import InfoExtractor
-from ..utils import (
+from ..compat import (
     compat_urllib_parse,
+)
+from ..utils import (
     remove_start,
 )
 
@@ -27,29 +27,25 @@ class VideoMegaIE(InfoExtractor):
     }
 
     def _real_extract(self, url):
-        mobj = re.match(self._VALID_URL, url)
-        video_id = mobj.group('id')
-
+        video_id = self._match_id(url)
         url = 'http://videomega.tv/iframe.php?ref={0:}'.format(video_id)
         webpage = self._download_webpage(url, video_id)
 
         escaped_data = self._search_regex(
-            'unescape\("([^"]+)"\)', webpage, 'escaped data')
+            r'unescape\("([^"]+)"\)', webpage, 'escaped data')
         playlist = compat_urllib_parse.unquote(escaped_data)
 
         thumbnail = self._search_regex(
             r'image:\s*"([^"]+)"', playlist, 'thumbnail', fatal=False)
         url = self._search_regex(r'file:\s*"([^"]+)"', playlist, 'URL')
-        title = self._html_search_regex(
-            r'<title>(.*?)</title>', webpage, 'title')
-        if title:
-            title = remove_start(title, 'VideoMega.tv - ')
+        title = remove_start(self._html_search_regex(
+            r'<title>(.*?)</title>', webpage, 'title'), 'VideoMega.tv - ')
 
-        formats = []
-        formats.append({
+        formats = [{
             'format_id': 'sd',
             'url': url,
-        })
+        }]
+        self._sort_formats(formats)
 
         return {
             'id': video_id,