summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar spoob <spoob@gmx.de> 2009-05-23 15:03:43 +0200
committerGravatar spoob <spoob@gmx.de> 2009-05-23 15:03:43 +0200
commitc2b11f2425eac63a4140a71ede91db22ae749c7c (patch)
tree0a242f46cd8b91435e2ffb208b4b857ba21d3e8b
parenttypo (diff)
downloadpyload-c2b11f2425eac63a4140a71ede91db22ae749c7c.tar.xz
youtube plugin added, nicer test output
-rw-r--r--Core.py10
-rw-r--r--Plugins/YoutubeCom.py81
-rw-r--r--README2
-rw-r--r--module/Py_Load_File.py1
-rw-r--r--module/download_thread.py28
5 files changed, 99 insertions, 23 deletions
diff --git a/Core.py b/Core.py
index 1769282ff..b585fd581 100644
--- a/Core.py
+++ b/Core.py
@@ -30,7 +30,6 @@ from logging import warning, basicConfig
import urllib2
import re
from time import sleep, time
-import pickle
#my imports
from module.download_thread import Download_Thread
@@ -45,7 +44,6 @@ class Core(object):
def __init__(self):
self.download_folder = ""
self.link_file = "links.txt"
- self.plugin_index = "Plugins" + sep + "plugin_index.txt"
self.plugins_avaible = {}
#self.plugins_needed = {}
#self.plugins_dict = {}
@@ -93,7 +91,6 @@ class Core(object):
if plugin_pattern != "":
self.plugins_avaible[plugin_file] = plugin_pattern
print plugin_file, "hinzugefuegt"
- pickle.dump(self.plugins_avaible, open(self.plugin_index, "w"))
print "Index der Plugins erstellt"
## def check_needed_plugins(self):
@@ -219,8 +216,8 @@ class Core(object):
for pyfile in self.thread_list.py_downloading:
if pyfile.status.type == 'downloading':
- print pyfile.status.filename, "speed:" ,int(pyfile.status.get_speed()) ,"kb/s"
- print pyfile.status.filename, "ETA" , int(pyfile.status.get_ETA()), "s"
+ print pyfile.status.filename + ": speed is" ,int(pyfile.status.get_speed()) ,"kb/s"
+ print pyfile.status.filename + ": arraive in" ,pyfile.status.get_ETA() ,"seconds"
#try:
# fn = pyfile.status.filename
@@ -233,7 +230,7 @@ class Core(object):
# print pyfile.status.filename, "downloading"
if pyfile.status.type == 'waiting':
- print pyfile.status.filename + ": " + "wartet noch", int(pyfile.status.waituntil -time()) , "sekunden"
+ print pyfile.status.filename + ": wait", int(pyfile.status.waituntil -time()) , "seconds"
def start(self):
""" starts the machine
@@ -248,4 +245,3 @@ class Core(object):
testLoader = Core()
testLoader.start()
-#testLoader.create_plugin_index()
diff --git a/Plugins/YoutubeCom.py b/Plugins/YoutubeCom.py
new file mode 100644
index 000000000..2c019aa7c
--- /dev/null
+++ b/Plugins/YoutubeCom.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+
+import urllib2
+import re
+from time import time
+from Plugin import Plugin
+
+class YoutubeCom(Plugin):
+
+ def __init__(self, parent):
+ Plugin.__init__(self, parent)
+ self.plugin_name = "Youtube.com"
+ self.plugin_pattern = r"http://(www\.)?(de\.)?\youtube\.com/watch\?v=(.*)"
+ self.plugin_type = "hoster"
+ self.plugin_config = {}
+ pluginProp = {}
+ pluginProp ['name'] = "YoutubeCom"
+ pluginProp ['version'] = "0.1"
+ pluginProp ['format'] = "*.py"
+ pluginProp ['description'] = """Youtube Plugin"""
+ pluginProp ['author'] = "spoob"
+ pluginProp ['author_email'] = "spoob@pyload.org"
+ self.pluginProp = pluginProp
+ self.parent = parent
+ self.html = None
+ self.html_old = None #time() where loaded the HTML
+ self.time_plus_wait = None #time() + wait in seconds
+ self.want_reconnect = None
+
+ def set_parent_status(self):
+ """ sets all available Statusinfos about a File in self.parent.status
+ """
+ if self.html == None:
+ self.download_html()
+ self.parent.status.filename = self.get_file_name()
+ self.parent.status.url = self.get_file_url()
+ self.parent.status.wait = self.wait_until()
+
+ 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()
+ if not self.want_reconnect:
+ videoId = re.search(self.plugin_pattern, self.parent.url).group(3)
+ videoHash = re.search(r', "t": "([^"]+)"', self.html).group(1)
+ file_url = 'http://youtube.com/get_video?video_id=' + videoId + '&t=' + videoHash + '&fmt=18'
+ return file_url
+ else:
+ return False
+
+ def get_file_name(self):
+ if self.html == None:
+ self.download_html()
+ if not self.want_reconnect:
+ file_name_pattern = r"<title>YouTube - (.*)</title>"
+ return re.search(file_name_pattern, self.html).group(1).replace("/", "") + '.mp4'
+ else:
+ return self.parent.url
+
+ def file_exists(self):
+ """ returns True or False
+ """
+ if self.html == None:
+ self.download_html()
+ if re.search(r"(.*eine fehlerhafte Video-ID\.)", self.html) != None:
+ return False
+ else:
+ return True
+
+ def wait_until(self):
+ if self.html == None:
+ self.download_html()
+ return self.time_plus_wait
+
+ def __call__(self):
+ return self.plugin_name
diff --git a/README b/README
index 7c4b25c7b..b1e14b516 100644
--- a/README
+++ b/README
@@ -21,4 +21,4 @@ Add your links to the links.txt file and start pyload with:
python pyLoad.py
For more information, see
-http://pyload.org/ \ No newline at end of file
+http://pyload.org/
diff --git a/module/Py_Load_File.py b/module/Py_Load_File.py
index 8fb45c079..c4bf2b08c 100644
--- a/module/Py_Load_File.py
+++ b/module/Py_Load_File.py
@@ -16,7 +16,6 @@ class PyLoadFile:
self.download_folder = ""
self.status = Status(self)
-
def _get_my_plugin(self):
""" searches the right plugin for an url
"""
diff --git a/module/download_thread.py b/module/download_thread.py
index 7b6b0fe6d..31d449472 100644
--- a/module/download_thread.py
+++ b/module/download_thread.py
@@ -82,7 +82,7 @@ class Download_Thread(threading.Thread):
while (not self.shutdown):
if self.parent.py_load_files:
self.loadedPyFile = self.parent.get_job()
- if self.loadedPyFile:
+ if self.loadedPyFile:
self.download(self.loadedPyFile)
sleep(0.5)
if self.shutdown:
@@ -90,30 +90,30 @@ class Download_Thread(threading.Thread):
self.parent.remove_thread(self)
def download(self, py_load_file):
- pyfile = py_load_file
+ pyfile = py_load_file
status = pyfile.status
pyfile.prepareDownload()
- if status.exists:
+ if status.exists:
if status.want_reconnect:
print "handle reconnect"
while (time() < status.waituntil):
status.type = "waiting"
- sleep(1) #eventuell auf genaue zeit warten
+ sleep(1) #eventuell auf genaue zeit warten
- status.type = "downloading"
- print status.url , status.filename
-
- try:
- pyfile.plugin.req.download(status.url, pyfile.download_folder + "/" + status.filename)
- status.type = "finished"
- except:
- status.type = "failed"
-
- self.parent.job_finished(pyfile)
+ status.type = "downloading"
+ print status.url , status.filename
+
+ try:
+ pyfile.plugin.req.download(status.url, pyfile.download_folder + "/" + status.filename)
+ status.type = "finished"
+ except:
+ status.type = "failed"
+
+ self.parent.job_finished(pyfile)
#startet downloader
#urllib.urlretrieve(status.url, pyfile.download_folder + "/" + status.filename, status)