about summary refs log tree commit diff
path: root/youtube_dl/extractor/wistia.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2013-12-06 09:15:04 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2013-12-06 09:15:04 +0100
commitef4fd848573b601502ba9142d5ce521294024356 (patch)
tree8dbccaff38949257f646fc5371dd9c72f2595b68 /youtube_dl/extractor/wistia.py
parent72135030d1235f608a2b5e0ec007ca8e6e19e3b4 (diff)
downloadyoutube-dl-ef4fd848573b601502ba9142d5ce521294024356.tar.gz
youtube-dl-ef4fd848573b601502ba9142d5ce521294024356.tar.xz
youtube-dl-ef4fd848573b601502ba9142d5ce521294024356.zip
[wistia] Add extractor
Diffstat (limited to 'youtube_dl/extractor/wistia.py')
-rw-r--r--youtube_dl/extractor/wistia.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/youtube_dl/extractor/wistia.py b/youtube_dl/extractor/wistia.py
new file mode 100644
index 000000000..e1748c261
--- /dev/null
+++ b/youtube_dl/extractor/wistia.py
@@ -0,0 +1,55 @@
+import json
+import re
+
+from .common import InfoExtractor
+
+
+class WistiaIE(InfoExtractor):
+    _VALID_URL = r'^https?://(?:fast\.)?wistia\.net/embed/iframe/(?P<id>[a-z0-9]+)'
+
+    _TEST = {
+        u"url": u"http://fast.wistia.net/embed/iframe/sh7fpupwlt",
+        u"file": u"sh7fpupwlt.mov",
+        u"md5": u"cafeb56ec0c53c18c97405eecb3133df",
+        u"info_dict": {
+            u"title": u"cfh_resourceful_zdkh_final_1"
+        },
+    }
+
+    def _real_extract(self, url):
+        mobj = re.match(self._VALID_URL, url)
+        video_id = mobj.group('id')
+
+        webpage = self._download_webpage(url, video_id)
+        data_json = self._html_search_regex(
+            r'Wistia.iframeInit\((.*?), {}\);', webpage, u'video data')
+
+        data = json.loads(data_json)
+
+        formats = []
+        thumbnails = []
+        for atype, a in data['assets'].items():
+            if atype == 'still':
+                thumbnails.append({
+                    'url': a['url'],
+                    'resolution': '%dx%d' % (a['width'], a['height']),
+                })
+                continue
+            if atype == 'preview':
+                continue
+            formats.append({
+                'format_id': atype,
+                'url': a['url'],
+                'width': a['width'],
+                'height': a['height'],
+                'filesize': a['size'],
+                'ext': a['ext'],
+            })
+        formats.sort(key=lambda a: a['filesize'])
+
+        return {
+            'id': video_id,
+            'title': data['name'],
+            'formats': formats,
+            'thumbnails': thumbnails,
+        }