[youtube] Fix extraction.
[youtube-dl] / youtube_dl / extractor / cloudy.py
index 73c6e3d499f09ae27672444e9c5721385d70377d..85ca20eccd0c5bb2e8e39468d6ad62428d918059 100644 (file)
@@ -1,67 +1,60 @@
 # coding: utf-8
 from __future__ import unicode_literals
 
-import re
-
 from .common import InfoExtractor
 from ..utils import (
-    ExtractorError,
-    compat_parse_qs,
-    compat_urllib_parse,
+    str_to_int,
+    unified_strdate,
 )
 
 
 class CloudyIE(InfoExtractor):
-    _VALID_URL = r'''(?x)
-        https?://(?:www\.)?cloudy\.ec/
-        (?:v/|embed\.php\?id=)
-        (?P<id>[A-Za-z0-9]+)
-        '''
-    _API_URL = 'http://www.cloudy.ec/api/player.api.php?%s'
-    _TEST = {
+    _IE_DESC = 'cloudy.ec'
+    _VALID_URL = r'https?://(?:www\.)?cloudy\.ec/(?:v/|embed\.php\?.*?\bid=)(?P<id>[A-Za-z0-9]+)'
+    _TESTS = [{
         'url': 'https://www.cloudy.ec/v/af511e2527aac',
-        'md5': '5cb253ace826a42f35b4740539bedf07',
+        'md5': '29832b05028ead1b58be86bf319397ca',
         'info_dict': {
             'id': 'af511e2527aac',
-            'ext': 'flv',
+            'ext': 'mp4',
             'title': 'Funny Cats and Animals Compilation june 2013',
+            'upload_date': '20130913',
+            'view_count': int,
         }
-    }
+    }, {
+        'url': 'http://www.cloudy.ec/embed.php?autoplay=1&id=af511e2527aac',
+        'only_matching': True,
+    }]
 
     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://www.cloudy.ec/embed.php?id=%s' % video_id
-        webpage = self._download_webpage(url, video_id)
+        webpage = self._download_webpage(
+            'https://www.cloudy.ec/embed.php', video_id, query={
+                'id': video_id,
+                'playerPage': 1,
+                'autoplay': 1,
+            })
 
-        file_key = self._search_regex(
-            r'filekey\s*=\s*"([^"]+)"', webpage, 'file_key')
-        data_url = self._API_URL % compat_urllib_parse.urlencode({
-            'file': video_id,
-            'key': file_key,
-        })
-        player_data = self._download_webpage(
-            data_url, video_id, 'Downloading player data')
-        data = compat_parse_qs(player_data)
+        info = self._parse_html5_media_entries(url, webpage, video_id)[0]
 
-        if 'error' in data:
-            raise ExtractorError(
-                '%s error: %s' % (self.IE_NAME, ' '.join(data['error_msg'])),
-                expected=True)
+        webpage = self._download_webpage(
+            'https://www.cloudy.ec/v/%s' % video_id, video_id, fatal=False)
 
-        title = data.get('title', [None])[0]
-        if title:
-            title = title.replace('&asdasdas', '').strip()
+        if webpage:
+            info.update({
+                'title': self._search_regex(
+                    r'<h\d[^>]*>([^<]+)<', webpage, 'title'),
+                'upload_date': unified_strdate(self._search_regex(
+                    r'>Published at (\d{4}-\d{1,2}-\d{1,2})', webpage,
+                    'upload date', fatal=False)),
+                'view_count': str_to_int(self._search_regex(
+                    r'([\d,.]+) views<', webpage, 'view count', fatal=False)),
+            })
 
-        formats = []
-        formats.append({
-            'format_id': 'sd',
-            'url': data.get('url', [None])[0],
-        })
+        if not info.get('title'):
+            info['title'] = video_id
 
-        return {
-            'id': video_id,
-            'title': title,
-            'formats': formats,
-        }
+        info['id'] = video_id
+
+        return info