]> gitweb @ CieloNegro.org - youtube-dl.git/commitdiff
[clyp] Add extractor
authorCian Ruane <CianLR@users.noreply.github.com>
Fri, 16 Oct 2015 00:23:09 +0000 (01:23 +0100)
committerSergey M․ <dstftw@gmail.com>
Wed, 28 Oct 2015 14:37:19 +0000 (20:37 +0600)
Update __init__.py

[clyp.it] Extract ID idiomatically and make duration and description optional

youtube_dl/extractor/__init__.py
youtube_dl/extractor/clyp.py [new file with mode: 0644]

index 6318ac4a26d0c0d5afd024a0fae9ff190838b054..f98e6487e467f63c5476bd7682723e8f6770773b 100644 (file)
@@ -90,6 +90,7 @@ from .cliphunter import CliphunterIE
 from .clipsyndicate import ClipsyndicateIE
 from .cloudy import CloudyIE
 from .clubic import ClubicIE
+from .clyp import ClypIE
 from .cmt import CMTIE
 from .cnet import CNETIE
 from .cnn import (
diff --git a/youtube_dl/extractor/clyp.py b/youtube_dl/extractor/clyp.py
new file mode 100644 (file)
index 0000000..906729b
--- /dev/null
@@ -0,0 +1,57 @@
+# coding: utf-8
+
+from __future__ import unicode_literals
+
+import re
+
+from .common import InfoExtractor
+
+
+class ClypIE(InfoExtractor):
+    _VALID_URL = r'https?://(?:www\.)?clyp\.it/(?P<id>[a-z0-9]+)'
+
+    _TESTS = [{
+        'url': 'https://clyp.it/ojz2wfah',
+        'md5': '1d4961036c41247ecfdcc439c0cddcbb',
+        'info_dict': {
+            'id': 'ojz2wfah',
+            'ext': 'mp3',
+            'title': 'Krisson80 - bits wip wip',
+            'description': '#Krisson80BitsWipWip #chiptune\n#wip',
+        },
+    }, {
+        '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']
+
+        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
+            }]
+
+        return {
+            'id': audio_id,
+            'title': title,
+            'formats': formats,
+            'description': description,
+            'duration': duration
+        }