summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-16 23:59:16 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-16 23:59:16 +0200
commitdc0c62c8edff5f61dbdff0ef0b6236379f2ad1d1 (patch)
tree4f59fe689ff24e778c5c4a38f039cdb7a468bc41
parentfixed rapidshare server url bug (diff)
downloadpyload-dc0c62c8edff5f61dbdff0ef0b6236379f2ad1d1.tar.xz
new file list modul
-rw-r--r--Plugins/YoutubeChannel.py1
-rw-r--r--module/download_thread.py19
-rw-r--r--module/file_list.py45
-rw-r--r--module/thread_list.py60
-rw-r--r--pyLoadCore.py59
5 files changed, 85 insertions, 99 deletions
diff --git a/Plugins/YoutubeChannel.py b/Plugins/YoutubeChannel.py
index 312f8d9ce..28cadfd26 100644
--- a/Plugins/YoutubeChannel.py
+++ b/Plugins/YoutubeChannel.py
@@ -43,7 +43,6 @@ class YoutubeChannel(Plugin):
new_links = re.findall(r"href\='(http:\/\/www.youtube.com\/watch\?v\=[^']+)", rep)
if new_links != []:
temp_links.extend(new_links)
- print temp_links
else:
break
page += 1
diff --git a/module/download_thread.py b/module/download_thread.py
index a2318038a..a290bc4f7 100644
--- a/module/download_thread.py
+++ b/module/download_thread.py
@@ -60,16 +60,15 @@ class Download_Thread(threading.Thread):
def run(self):
while (not self.shutdown):
- if self.parent.py_load_files:
- self.loadedPyFile = self.parent.get_job()
- if self.loadedPyFile:
- try:
- self.download(self.loadedPyFile)
- except Exception, e:
- print "Error:", e #catch up all error here
- self.loadedPyFile.status.type = "failed"
- finally:
- self.parent.job_finished(self.loadedPyFile)
+ self.loadedPyFile = self.parent.get_job()
+ if self.loadedPyFile:
+ try:
+ self.download(self.loadedPyFile)
+ except Exception, e:
+ print "Error:", e #catch up all error here
+ self.loadedPyFile.status.type = "failed"
+ finally:
+ self.parent.job_finished(self.loadedPyFile)
sleep(0.5)
if self.shutdown:
sleep(1)
diff --git a/module/file_list.py b/module/file_list.py
index e8cc49ab2..c9a96635f 100644
--- a/module/file_list.py
+++ b/module/file_list.py
@@ -22,18 +22,18 @@ LIST_VERSION = 1
import cPickle
from Py_Load_File import PyLoadFile
-
+
class File_List(object):
- def __init__(self):
- self.version = LIST_VERSION
+ def __init__(self, core):
+ self.core = core
self.files = []
+ self.data = {'version': LIST_VERSION}
self.id = 0
+ #self.load()
- def set_core(self, core):
- self.core = core
-
- def new_pyfile(self):
- pyfile = PyLoadFile(self, url)
+ def new_pyfile(self, url):
+ url = url.replace("\n", "")
+ pyfile = PyLoadFile(self.core, url)
pyfile.download_folder = self.core.config['download_folder']
pyfile.id = self.id
self.id += 1
@@ -41,23 +41,26 @@ class File_List(object):
return pyfile
def append(self, url):
- self.links.append(url)
+ self.files.append(self.new_pyfile(url))
+
+ def extend(self, urls):
+ for url in urls:
+ self.append(url)
def save(self):
output = open('links.pkl', 'wb')
- cPickle.dump(self, output, -1)
-
+ cPickle.dump(self.data, output, -1)
-def load(core):
- try:
- pkl_file = open('links.pkl', 'rb')
- obj = cPickle.load(pkl_file)
- except:
- obj = File_List()
+ def load(self):
+ try:
+ pkl_file = open('links.pkl', 'rb')
+ obj = cPickle.load(pkl_file)
+ except:
+ obj = {'version': LIST_VERSION}
- if obj.version < LIST_VERSION:
- obj = File_List()
+ if obj['version'] < LIST_VERSION:
+ obj = {'version': LIST_VERSION}
- obj.set_core(core)
+ self.data = obj
- return obj
+
diff --git a/module/thread_list.py b/module/thread_list.py
index a7e92b77d..62131b20e 100644
--- a/module/thread_list.py
+++ b/module/thread_list.py
@@ -31,10 +31,11 @@ from download_thread import Download_Thread
class Thread_List(object):
def __init__(self, parent):
self.parent = parent
+ self.list = parent.file_list
self.threads = []
self.max_threads = int(self.parent.config['max_downloads'])
- self.py_load_files = [] # files in queque
- self.f_relation = [0, 0]
+ # self.py_load_files = [] # files in queque
+ # self.f_relation = [0, 0]
self.lock = RLock()
self.py_downloading = [] # files downloading
self.occ_plugins = [] #occupied plugins
@@ -50,36 +51,31 @@ class Thread_List(object):
self.threads.append(thread)
return True
- def get_loaded_urls(self):
- loaded_urls = []
- for file in self.py_load_files:
- loaded_urls.append(file.url)
- return loaded_urls
-
def remove_thread(self, thread):
self.threads.remove(thread)
+ def select_thread(self):
+ """ select a thread
+ """
+ while len(self.threads) < self.max_threads:
+ self.create_thread()
+
def get_job(self):
"""return job if suitable, otherwise send thread idle"""
- if not self.parent.is_dltime():
+ if not self.parent.is_dltime() or self.pause or self.reconnecting or not self.list.files: #conditions when threads dont download
return None
- if self.pause:
- return None
-
- if self.reconnecting:
- return None
self.init_reconnect()
self.lock.acquire()
pyfile = None
- for i in range(len(self.py_load_files)):
- if not self.py_load_files[i].modul.__name__ in self.occ_plugins:
- pyfile = self.py_load_files.pop(i)
+ for i in range(len(self.list.files)):
+ if not self.list.files[i].modul.__name__ in self.occ_plugins:
+ pyfile = self.list.files.pop(i)
break
if pyfile:
@@ -103,25 +99,13 @@ class Thread_List(object):
if pyfile.status.type == "finished":
self.parent.logger.info('Download finished: ' + pyfile.url + ' @' + str(pyfile.status.get_speed()) + 'kb/s')
- with open(self.parent.config['link_file'], 'r') as f:
- data = f.read()
-
if pyfile.plugin.props['type'] == "container":
- links = ""
+
+ self.list.extend(pyfile.plugin.links)
- for link in pyfile.plugin.links:
- links += link + "\n"
-
- self.parent.extend_links(pyfile.plugin.links)
- data = links + data # put the links into text file
-
- data = data.replace(pyfile.url + '\n', "")
-
- with open(self.parent.config['link_file'], 'w') as f:
- f.write(data)
if pyfile.status.type == "reconnected":#put it back in queque
- self.py_load_files.insert(0, pyfile)
+ self.list.files.insert(0, pyfile)
if pyfile.status.type == "failed":
self.parent.logger.warning("Download failed: " + pyfile.url)
@@ -131,18 +115,6 @@ class Thread_List(object):
self.lock.release()
return True
- def select_thread(self):
- """ select a thread
- """
- if len(self.threads) < self.max_threads:
- self.create_thread()
-
- def append_py_load_file(self, py_load_file):
- py_load_file.id = len(self.py_load_files)
- self.py_load_files.append(py_load_file)
- self.f_relation[1] += 1
- self.select_thread()
-
def init_reconnect(self):
"""initialise a reonnect"""
if not self.parent.config['use_reconnect']:
diff --git a/pyLoadCore.py b/pyLoadCore.py
index 159ef1366..a4178768e 100644
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -40,7 +40,6 @@ from module.remote.RequestObject import RequestObject
from module.remote.SocketServer import ServerThread
from module.thread_list import Thread_List
from module.file_list import File_List
-from module import file_list
class Core(object):
""" pyLoad main
@@ -66,9 +65,9 @@ class Core(object):
self.logger.info(_("Downloadtime: %s") % self.is_dltime()) # debug only
- self.thread_list = Thread_List(self)
- self.file_list = file_list.load(self)
+ self.file_list = File_List(self)
+ self.thread_list = Thread_List(self)
path.append(self.config['plugin_folder'])
self.create_plugin_index()
@@ -100,19 +99,33 @@ class Core(object):
self.logger.info(_("created index of plugins"))
- def _get_links(self, link_file):
- """ funktion nur zum testen ohne gui bzw. tui
- """
- links = open(link_file, 'r').readlines()
- self.extend_links(links)
+# def _get_links(self, link_file):
+# """ funktion nur zum testen ohne gui bzw. tui
+# """
+# links = open(link_file, 'r').readlines()
+# self.extend_links(links)
+
+ def read_links(self):
+ """read links from txt"""
+ txt = open(self.config['link_file'], 'r')
+ links = txt.readlines()
+ self.file_list.extend(links)
+
+ txt.close()
+
+ #self.file_list.save()
+
+ #txt = open(self.config['link_file'], 'w')
+ #txt.write("")
+ #txt.close()
- def append_link(self, link):
- if link not in self.thread_list.get_loaded_urls():
- self.__new_py_load_file(link.replace("\n", ""))
+# def append_link(self, link):
+# if link not in self.thread_list.get_loaded_urls():
+# self.__new_py_load_file(link.replace("\n", ""))
- def extend_links(self, links):
- for link in links:
- self.append_link(link)
+# def extend_links(self, links):
+# for link in links:
+# self.append_link(link)
#def check_update(self):
#"""checks newst version
@@ -137,15 +150,15 @@ class Core(object):
print _("could not create %s") % legend
exit()
- def __new_py_load_file(self, url):
- new_file = PyLoadFile(self, url)
- new_file.download_folder = self.config['download_folder']
- self.thread_list.append_py_load_file(new_file)
- return True
+# def __new_py_load_file(self, url):
+# new_file = PyLoadFile(self, url)
+# new_file.download_folder = self.config['download_folder']
+# self.thread_list.append_py_load_file(new_file)
+# return True
def init_logger(self, level):
- file_handler = logging.handlers.RotatingFileHandler(self.config['log_folder'] + sep + 'log.txt', maxBytes=102400, backupCount=int(self.config['log_count'])) #100 kib * 5
+ file_handler = logging.handlers.RotatingFileHandler(self.config['log_folder'] + sep + 'log.txt', maxBytes=102400, backupCount=int(self.config['log_count'])) #100 kib each
console = logging.StreamHandler(stdout)
frm = logging.Formatter("%(asctime)s: %(levelname)-8s %(message)s", "%d.%m.%Y %H:%M:%S")
@@ -177,7 +190,7 @@ class Core(object):
else:
return False
- def get_downloads(self): #only for debuging?!?
+ def get_downloads(self):
list = []
for pyfile in self.thread_list.py_downloading:
download = {}
@@ -189,7 +202,7 @@ class Core(object):
download['size'] = pyfile.status.size()
download['percent'] = pyfile.status.percent()
download['status'] = pyfile.status.type
- download['wait_until'] = pyfile.status.waituntil - time.time()
+ download['wait_until'] = pyfile.status.waituntil
list.append(download)
return list
@@ -216,7 +229,7 @@ class Core(object):
def start(self):
""" starts the machine
"""
- self._get_links(self.config['link_file'])
+ self.read_links()
while True:
#self.thread_list.status()
self._test_print_status()