-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewDownload.py
executable file
·111 lines (96 loc) · 3.58 KB
/
NewDownload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
#
# <A PySide Gui for Aria2 Download Manager>
# Copyright (C) 2013 a.atalla <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
#TODO: Select between video formats. Target V-0.6
#TODO: Patched download. Target V-0.6
import os
import sys
from PySide.QtCore import Slot
from PySide import QtGui
from gui.Ui_NewDownloadDialog import Ui_NewDownloadDialog
from Aria2Manager import Aria2Manager
import pyperclip as clip
HOME_DIR = os.environ['HOME']
class NewDownload(QtGui.QDialog, Ui_NewDownloadDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
self.setupUi(self)
self.aria = Aria2Manager()
self.edtDir.setText(HOME_DIR + '/Downloads')
# Monitor clipboard for URLs
if len(clip.paste()) > 4:
if clip.paste()[:4] == 'http' or clip.paste()[:3] == 'ftp':
self.edtUrl.setText(clip.paste())
@Slot()
def on_btnDir_clicked(self):
dialog = QtGui.QFileDialog(self)
dirName = dialog.getExistingDirectory(
self, "Select Download Directory")
self.edtDir.setText(dirName)
@Slot()
def on_btnOk_clicked(self):
speed = str(self.spinSpeed.value()) + 'K'
pieces = str(self.spinPieces.value())
maxconnectionperserver = str(self.spinConnectionsPerServer.value())
dir = self.edtDir.text()
oFileName = self.edtFileName.text()
uris = []
for i in range(0, self.listUrls.count()):
url = self.listUrls.item(i).text()
if url.startswith('http') or url.startswith('ftp'):
uris.append(url)
else:
self.showMessage(url + '\n is not a valid url')
print dir + '/' + oFileName
params = {'dir': dir,
'max-download-limit': speed,
'max-concurrent-downloads': pieces,
'max-connection-per-server': maxconnectionperserver,
'out': oFileName}
if not len(uris) == 0:
try:
self.aria.addUris(uris, params)
self.close()
except:
self.showMessage(
'Unexpected error:\n' + str(sys.exc_info()[1]))
else:
self.showMessage('Please add at least one valid url to the list!')
@Slot()
def on_btnCancel_clicked(self):
self.close()
@Slot()
def on_btnAdd_clicked(self):
self.listUrls.addItem(self.edtUrl.text())
self.edtUrl.setText('')
@Slot()
def on_btnRemove_clicked(self):
self.listUrls.takeItem(self.listUrls.currentRow())
@Slot()
def on_btnLoadFile_clicked(self):
dialog = QtGui.QFileDialog(self)
fileName, _ = dialog.getOpenFileName(
self, "Select a file", HOME_DIR)
f = open(fileName, 'r')
for line in f.readlines():
self.listUrls.addItem(line.strip())
def showMessage(self, msg):
msgBox = QtGui.QMessageBox()
msgBox.setText(msg)
msgBox.exec_()