about summary refs log tree commit diff
path: root/youtube_dl/extractor/clyp.py
diff options
context:
space:
mode:
authorCian Ruane <CianLR@users.noreply.github.com>2015-10-16 01:23:09 +0100
committerSergey M․ <dstftw@gmail.com>2015-10-28 20:37:19 +0600
commit4e16c1f80b009001aaea6f8baca5dfbfa9b58c11 (patch)
treeb8acbba21ad3938009ad93484f7bc395a5e967fa /youtube_dl/extractor/clyp.py
parent7ccb2b84ddb65f41d01037b5b62301886be9d22c (diff)
downloadyoutube-dl-4e16c1f80b009001aaea6f8baca5dfbfa9b58c11.tar.gz
youtube-dl-4e16c1f80b009001aaea6f8baca5dfbfa9b58c11.tar.xz
youtube-dl-4e16c1f80b009001aaea6f8baca5dfbfa9b58c11.zip
[clyp] Add extractor
Update __init__.py

[clyp.it] Extract ID idiomatically and make duration and description optional
Diffstat (limited to 'youtube_dl/extractor/clyp.py')
-rw-r--r--youtube_dl/extractor/clyp.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/youtube_dl/extractor/clyp.py b/youtube_dl/extractor/clyp.py
new file mode 100644
index 000000000..906729b30
--- /dev/null
+++ b/youtube_dl/extractor/clyp.py
@@ -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
+        }