about summary refs log tree commit diff
path: root/youtube_dl/extractor/aparat.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2013-12-20 17:05:28 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2013-12-20 17:05:39 +0100
commitaa94a6d3159af8333b56d16f3ed0bc3a164a882a (patch)
tree34c838d89031442e68d941bd7f25e93098ea1ec0 /youtube_dl/extractor/aparat.py
parent768df745385a283f4df3a38ee4734feec518ec87 (diff)
downloadyoutube-dl-aa94a6d3159af8333b56d16f3ed0bc3a164a882a.tar.gz
youtube-dl-aa94a6d3159af8333b56d16f3ed0bc3a164a882a.tar.xz
youtube-dl-aa94a6d3159af8333b56d16f3ed0bc3a164a882a.zip
[aparat] Add support (Fixes #2012)
Diffstat (limited to 'youtube_dl/extractor/aparat.py')
-rw-r--r--youtube_dl/extractor/aparat.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/youtube_dl/extractor/aparat.py b/youtube_dl/extractor/aparat.py
new file mode 100644
index 000000000..7e93bc4df
--- /dev/null
+++ b/youtube_dl/extractor/aparat.py
@@ -0,0 +1,56 @@
+#coding: utf-8
+
+import re
+
+from .common import InfoExtractor
+from ..utils import (
+    ExtractorError,
+    HEADRequest,
+)
+
+
+class AparatIE(InfoExtractor):
+    _VALID_URL = r'^https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)'
+
+    _TEST = {
+        u'url': u'http://www.aparat.com/v/wP8On',
+        u'file': u'wP8On.mp4',
+        u'md5': u'6714e0af7e0d875c5a39c4dc4ab46ad1',
+        u'info_dict': {
+            u"title": u"تیم گلکسی 11 - زومیت",
+        },
+        #u'skip': u'Extremely unreliable',
+    }
+
+    def _real_extract(self, url):
+        m = re.match(self._VALID_URL, url)
+        video_id = m.group('id')
+
+        # Note: There is an easier-to-parse configuration at
+        # http://www.aparat.com/video/video/config/videohash/%video_id
+        # but the URL in there does not work
+        embed_url = (u'http://www.aparat.com/video/video/embed/videohash/' +
+                     video_id + u'/vt/frame')
+        webpage = self._download_webpage(embed_url, video_id)
+
+        video_urls = re.findall(r'fileList\[[0-9]+\]\s*=\s*"([^"]+)"', webpage)
+        for i, video_url in enumerate(video_urls):
+            req = HEADRequest(video_url)
+            res = self._request_webpage(
+                req, video_id, note=u'Testing video URL %d' % i, errnote=False)
+            if res:
+                break
+        else:
+            raise ExtractorError(u'No working video URLs found')
+
+        title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, u'title')
+        thumbnail = self._search_regex(
+            r'\s+image:\s*"([^"]+)"', webpage, u'thumbnail', fatal=False)
+
+        return {
+            'id': video_id,
+            'title': title,
+            'url': video_url,
+            'ext': 'mp4',
+            'thumbnail': thumbnail,
+        }