summary refs log tree commit diff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2015-10-28 21:42:01 +0600
committerSergey M․ <dstftw@gmail.com>2015-10-28 21:42:01 +0600
commit03c2c162f9eaac6b474a1be9e985621f5b7b8c10 (patch)
treed8a43e549285587eebcfcd14a7f40e9f7415ccd5
parent52c3a6e49d2cbc1932992d816d28bbed629daadc (diff)
downloadyoutube-dl-03c2c162f9eaac6b474a1be9e985621f5b7b8c10.tar.gz
youtube-dl-03c2c162f9eaac6b474a1be9e985621f5b7b8c10.tar.xz
youtube-dl-03c2c162f9eaac6b474a1be9e985621f5b7b8c10.zip
[clyp] Improve and cleanup (Closes #7194)
-rw-r--r--youtube_dl/extractor/clyp.py62
1 files changed, 31 insertions, 31 deletions
diff --git a/youtube_dl/extractor/clyp.py b/youtube_dl/extractor/clyp.py
index 906729b30..57e643799 100644
--- a/youtube_dl/extractor/clyp.py
+++ b/youtube_dl/extractor/clyp.py
@@ -1,16 +1,15 @@
-# coding: utf-8
-
 from __future__ import unicode_literals
 
-import re
-
 from .common import InfoExtractor
+from ..utils import (
+    float_or_none,
+    parse_iso8601,
+)
 
 
 class ClypIE(InfoExtractor):
     _VALID_URL = r'https?://(?:www\.)?clyp\.it/(?P<id>[a-z0-9]+)'
-
-    _TESTS = [{
+    _TEST = {
         'url': 'https://clyp.it/ojz2wfah',
         'md5': '1d4961036c41247ecfdcc439c0cddcbb',
         'info_dict': {
@@ -18,40 +17,41 @@ class ClypIE(InfoExtractor):
             'ext': 'mp3',
             'title': 'Krisson80 - bits wip wip',
             'description': '#Krisson80BitsWipWip #chiptune\n#wip',
+            'duration': 263.21,
+            'timestamp': 1443515251,
+            'upload_date': '20150929',
         },
-    }, {
-        'url': 'https://clyp.it/ojz2wfah',
-        'only_matching': True,
-    }]
+    }
 
     def _real_extract(self, url):
         audio_id = self._match_id(url)
-        api_url = 'https://api.clyp.it/' + audio_id
-        metadata = self._download_json(api_url, audio_id)
 
-        title = metadata['Title']
+        metadata = self._download_json(
+            'https://api.clyp.it/%s' % audio_id, audio_id)
+
+        formats = []
+        for secure in ('', 'Secure'):
+            for ext in ('Ogg', 'Mp3'):
+                format_id = '%s%s' % (secure, ext)
+                format_url = metadata.get('%sUrl' % format_id)
+                if format_url:
+                    formats.append({
+                        'url': format_url,
+                        'format_id': format_id,
+                        'vcodec': 'none',
+                    })
+        self._sort_formats(formats)
 
-        description = None
-        if metadata['Description']: description = metadata['Description']
-
-        duration = None
-        if metadata['Duration']: duration = int(metadata['Duration'])
-        
-        formats = [
-            {
-            'url': metadata['OggUrl'],
-            'format_id': 'ogg',
-            'preference': -2
-            },{
-            'url': metadata['Mp3Url'],
-            'format_id': 'mp3',
-            'preference': -1
-            }]
+        title = metadata['Title']
+        description = metadata.get('Description')
+        duration = float_or_none(metadata.get('Duration'))
+        timestamp = parse_iso8601(metadata.get('DateCreated'))
 
         return {
             'id': audio_id,
             'title': title,
-            'formats': formats,
             'description': description,
-            'duration': duration
+            'duration': duration,
+            'timestamp': timestamp,
+            'formats': formats,
         }