Add support for Videomega
diff --git a/README.md b/README.md
index bbb090a8e9..b480f114ad 100644
--- a/README.md
+++ b/README.md
@@ -298,6 +298,7 @@ Use `--url`/`-u` to get a list of downloadable resource URLs extracted from the
 | Vine        | <https://vine.co/>            |✓| | |
 | Vimeo       | <https://vimeo.com/>          |✓| | |
 | Vidto       | <http://vidto.me/>            |✓| | |
+| Videomega   | <http://videomega.tv/>        |✓| | |
 | Veoh        | <http://www.veoh.com/>        |✓| | |
 | **Tumblr**  | <https://www.tumblr.com/>     |✓|✓|✓|
 | TED         | <http://www.ted.com/>         |✓| | |
diff --git a/src/you_get/common.py b/src/you_get/common.py
index fd956408ad..8b73088b69 100755
--- a/src/you_get/common.py
+++ b/src/you_get/common.py
@@ -66,6 +66,7 @@
     'tumblr'           : 'tumblr',
     'twimg'            : 'twitter',
     'twitter'          : 'twitter',
+    'videomega'        : 'videomega',
     'vidto'            : 'vidto',
     'vimeo'            : 'vimeo',
     'weibo'            : 'miaopai',
diff --git a/src/you_get/extractors/__init__.py b/src/you_get/extractors/__init__.py
index 380c573606..7b3c6a7162 100755
--- a/src/you_get/extractors/__init__.py
+++ b/src/you_get/extractors/__init__.py
@@ -58,6 +58,7 @@
 from .tumblr import *
 from .twitter import *
 from .veoh import *
+from .videomega import *
 from .vimeo import *
 from .vine import *
 from .vk import *
diff --git a/src/you_get/extractors/videomega.py b/src/you_get/extractors/videomega.py
new file mode 100644
index 0000000000..75e88cd97d
--- /dev/null
+++ b/src/you_get/extractors/videomega.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+from ..common import *
+from ..extractor import VideoExtractor
+
+import ssl
+
+class Videomega(VideoExtractor):
+    name = "Videomega"
+
+    stream_types = [
+        {'id': 'original'}
+    ]
+
+    def prepare(self, **kwargs):
+        # Hot-plug cookie handler
+        ssl_context = request.HTTPSHandler(
+            context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))
+        cookie_handler = request.HTTPCookieProcessor()
+        opener = request.build_opener(ssl_context, cookie_handler)
+        opener.addheaders = [('Referer', self.url),
+                             ('Cookie', 'noadvtday=0')]
+        request.install_opener(opener)
+
+        ref = match1(self.url, r'ref=(\w+)')
+        php_url = 'http://videomega.tv/view.php?ref=' + ref
+        content = get_content(php_url)
+
+        self.title = match1(content, r'<title>(.*)</title>')
+        js = match1(content, r'(eval.*)')
+        t = match1(js, r'\$\("\d+"\)\.\d+\("\d+","([^"]+)"\)')
+        t = re.sub(r'(\w)', r'{\1}', t)
+        t = t.translate({87 + i: str(i) for i in range(10, 36)})
+        s = match1(js, r"'([^']+)'\.split").split('|')
+        self.streams['original'] = {
+            'url': t.format(*s)
+        }
+
+    def extract(self, **kwargs):
+        for i in self.streams:
+            s = self.streams[i]
+            _, s['container'], s['size'] = url_info(s['url'])
+            s['src'] = [s['url']]
+
+site = Videomega()
+download = site.download_by_url
+download_playlist = site.download_by_url

![such-av s](https://cloud.githubusercontent.com/assets/342945/12064381/0e709074-afc2-11e5-96de-d604d64a6008.jpg)

Example links:
- http://videomega.tv/?ref=9r9sx4xGOGGOGx4xs9r9
- http://videomega.tv/?ref=UKRPMV8QG00GQ8VMPRKU
- http://videomega.tv/?ref=E1OMPDO446644ODPMO1E
- <del>(NSFW!) http://videomega.tv/?ref=Q379OGDTS66STDGO973Q</del>

<!-- Reviewable:start -->

[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/soimort/you-get/850)

<!-- Reviewable:end -->
