summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-05-05 18:54:17 +0200
committerGravatar mkaay <mkaay@mkaay.de> 2010-05-05 18:54:17 +0200
commit05321c6e6108b86a5a004a2e28b1e3be9a7ad225 (patch)
treeb57e91b2a09fe10b9945574e4628ceab64715c62 /module
parentadded missing file (diff)
downloadpyload-05321c6e6108b86a5a004a2e28b1e3be9a7ad225.tar.xz
megavideo.com plugin
Diffstat (limited to 'module')
-rw-r--r--module/plugins/hoster/MegavideoCom.py112
-rw-r--r--module/unescape.py4
2 files changed, 115 insertions, 1 deletions
diff --git a/module/plugins/hoster/MegavideoCom.py b/module/plugins/hoster/MegavideoCom.py
new file mode 100644
index 000000000..9e6df3cc9
--- /dev/null
+++ b/module/plugins/hoster/MegavideoCom.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import re
+from time import time
+from module.plugins.Plugin import Plugin
+from module.unescape import unescape
+
+class MegavideoCom(Plugin):
+ def __init__(self, parent):
+ Plugin.__init__(self, parent)
+ props = {}
+ props['name'] = "MegavideoCom"
+ props['type'] = "hoster"
+ props['pattern'] = r"http://(www\.)?megavideo.com/\?v=.*"
+ props['version'] = "0.1"
+ props['description'] = """Megavideo.com Download Plugin"""
+ props['author_name'] = ("jeix","mkaay")
+ props['author_mail'] = ("jeix@hasnomail.de","mkaay@mkaay.de")
+ self.props = props
+ self.parent = parent
+ self.html = None
+
+ def download_html(self):
+ url = self.parent.url
+ self.html = self.req.load(url)
+
+ def get_file_url(self):
+ """ returns the absolute downloadable filepath
+ """
+ if self.html == None:
+ self.download_html()
+
+ # get id
+ id = re.search("previewplayer/\\?v=(.*?)&width", self.html).group(1)
+
+ # check for hd link and return if there
+ if "flashvars.hd = \"1\";" in self.html:
+ content = self.req.load("http://www.megavideo.com/xml/videolink.php?v=%s" % id)
+ return unescape(re.search("hd_url=\"(.*?)\"", content).group(1))
+
+ # else get normal link
+ s = re.search("flashvars.s = \"(\\d+)\";", self.html).group(1)
+ un = re.search("flashvars.un = \"(.*?)\";", self.html).group(1)
+ k1 = re.search("flashvars.k1 = \"(\\d+)\";", self.html).group(1)
+ k2 = re.search("flashvars.k2 = \"(\\d+)\";", self.html).group(1)
+ return "http://www%s.megavideo.com/files/%s/" % (s, self.__decrypt(un, int(k1), int(k2)))
+
+ def __decrypt(self, input, k1, k2):
+ req1 = []
+ req3 = 0
+ for c in input:
+ c = int(c, 16)
+ tmp = "".join([str((c >> y) & 1) for y in range(4 -1, -1, -1)])
+ req1.extend([int(x) for x in tmp])
+
+ req6 = []
+ req3 = 0
+ while req3 < 384:
+ k1 = (k1 * 11 + 77213) % 81371
+ k2 = (k2 * 17 + 92717) % 192811
+ req6.append((k1 + k2) % 128)
+ req3 += 1
+
+ req3 = 256
+ while req3 >= 0:
+ req5 = req6[req3]
+ req4 = req3 % 128
+ req8 = req1[req5]
+ req1[req5] = req1[req4]
+ req1[req4] = req8
+ req3 -= 1
+
+ req3 = 0
+ while req3 < 128:
+ req1[req3] = req1[req3] ^ (req6[req3+256] & 1)
+ req3 += 1
+
+ out = ""
+ req3 = 0
+ while req3 < len(req1):
+ tmp = req1[req3] * 8
+ tmp += req1[req3+1] * 4
+ tmp += req1[req3+2] * 2
+ tmp += req1[req3+3]
+
+ out += "%X" % tmp
+
+ req3 += 4
+
+ return out.lower()
+
+ def get_file_name(self):
+ if self.html == None:
+ self.download_html()
+
+ name = re.search("flashvars.title = \"(.*?)\";", self.html).group(1)
+ name = "%s.flv" % unescape(name.encode("ascii", "ignore")).decode("utf-8").encode("ascii", "ignore").replace("+", " ")
+ return name
+
+ def file_exists(self):
+ """ returns True or False
+ """
+ if self.html == None:
+ self.download_html()
+
+ if re.search(r"Dieses Video ist nicht verfügbar.", self.html) != None or \
+ re.search(r"This video is unavailable.", self.html) != None:
+ return False
+ else:
+ return True
+
diff --git a/module/unescape.py b/module/unescape.py
index 59f35f36b..41a23be5b 100644
--- a/module/unescape.py
+++ b/module/unescape.py
@@ -1,4 +1,5 @@
from htmlentitydefs import name2codepoint as n2cp
+from urllib import unquote
import re
def substitute_entity(match):
@@ -14,7 +15,8 @@ def substitute_entity(match):
def unescape(string):
entity_re = re.compile("&(#?)(\d{1,5}|\w{1,8});")
- return entity_re.subn(substitute_entity, string)[0]
+ return entity_re.subn(substitute_entity, unquote(string))[0]
+
"""
import re