PEP8-ed python files
This commit is contained in:
parent
021d471357
commit
7e6a23fa5d
@ -38,16 +38,20 @@ class GUI(QMainWindow):
|
||||
# Validating input
|
||||
songID = self.input.text()
|
||||
if not songID:
|
||||
self.notification=NotificationDialog(switch['empinp'][config["lang"]])
|
||||
self.notification = NotificationDialog(
|
||||
switch['empinp'][config["lang"]])
|
||||
self.notification.exec()
|
||||
return
|
||||
elif not songID.isdigit():
|
||||
self.notification=NotificationDialog(switch['typerr'][config["lang"]])
|
||||
self.notification = NotificationDialog(
|
||||
switch['typerr'][config["lang"]])
|
||||
self.notification.exec()
|
||||
return
|
||||
page=parse(load(f'https://www.newgrounds.com/audio/listen/{songID}').text,'html.parser')
|
||||
page = parse(load('https://www.newgrounds.com/audio/listen/'
|
||||
f'{songID}').text, 'html.parser')
|
||||
if page.find(id='pageerror') is not None:
|
||||
self.notification=NotificationDialog(switch['404'][config["lang"]])
|
||||
self.notification = NotificationDialog(
|
||||
switch['404'][config["lang"]])
|
||||
self.notification.exec()
|
||||
return
|
||||
self.songTitle = page.find('title').text
|
||||
@ -56,18 +60,23 @@ class GUI(QMainWindow):
|
||||
page = str(page)
|
||||
i = page.find('audio.ngfiles.com')+len('audio.ngfiles.com/')
|
||||
while not link.endswith('.mp3'):
|
||||
if page[i]!='\\': link+=page[i]
|
||||
if page[i] != '\\':
|
||||
link += page[i]
|
||||
i += 1
|
||||
# Locating file
|
||||
self.dist=QFileDialog.getSaveFileName(self,switch['savefile'][config["lang"]],
|
||||
self.dist = (QFileDialog.
|
||||
getSaveFileName(self, switch['savefile'][config["lang"]],
|
||||
link.split('/')[-1],
|
||||
'MP3 Audio File (*.mp3)')[0]
|
||||
if not self.dist: return
|
||||
'MP3 Audio File (*.mp3)')[0])
|
||||
if not self.dist:
|
||||
return
|
||||
# Downloading
|
||||
self.file = load(link, stream=True)
|
||||
self.progress = ProgressDialog()
|
||||
self.progress.label.setText(switch['downloading'][config["lang"]](self.songTitle))
|
||||
self.progress.setWindowTitle(switch['downloading'][config["lang"]](self.songTitle))
|
||||
self.progress.label.setText(
|
||||
switch['downloading'][config["lang"]](self.songTitle))
|
||||
self.progress.setWindowTitle(
|
||||
switch['downloading'][config["lang"]](self.songTitle))
|
||||
self.progress.bar.setValue(0)
|
||||
self.progress.exec()
|
||||
|
||||
@ -76,12 +85,19 @@ class GUI(QMainWindow):
|
||||
self.settings.exec()
|
||||
|
||||
def show_help(self):
|
||||
if config["lang"]=='en': web.open('https://github.com/H1K0/NGAudioDownloader/blob/master/README.md#newgrounds-audio-downloader--',new=2)
|
||||
else: web.open(f'https://github.com/H1K0/NGAudioDownloader/blob/master/README-{config["lang"].upper()}.md#newgrounds-audio-downloader--',new=2)
|
||||
if config["lang"] == 'en':
|
||||
web.open('https://github.com/H1K0/NGAudioDownloader/blob/master/'
|
||||
'README.md#newgrounds-audio-downloader--', new=2)
|
||||
else:
|
||||
web.open('https://github.com/H1K0/NGAudioDownloader/blob/master/'
|
||||
f'README-{config["lang"].upper()}.md#'
|
||||
'newgrounds-audio-downloader--', new=2)
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.key()==16777216: self.close()
|
||||
elif event.key()==16777220: self.download()
|
||||
if event.key() == 16777216:
|
||||
self.close()
|
||||
elif event.key() == 16777220:
|
||||
self.download()
|
||||
|
||||
|
||||
class ProgressDialog(QDialog):
|
||||
@ -89,7 +105,8 @@ class ProgressDialog(QDialog):
|
||||
super().__init__()
|
||||
loadUi('GUI/ProgressDialog.ui', self)
|
||||
chfont(self.label, switch['downloading'][f'font_{config["lang"]}'])
|
||||
self.setWindowFlags(self.windowFlags()&~QtCore.Qt.WindowCloseButtonHint)
|
||||
self.setWindowFlags(self.windowFlags() & ~
|
||||
QtCore.Qt.WindowCloseButtonHint)
|
||||
self.thread = DownloadThread()
|
||||
self.thread.got_chunk.connect(lambda done: self.bar.setValue(done))
|
||||
self.thread.finished.connect(self.thread.finish)
|
||||
@ -103,11 +120,14 @@ class DownloadThread(QThread):
|
||||
|
||||
def run(self):
|
||||
total = ngad.file.headers.get('content-length')
|
||||
if total is None: total=-1
|
||||
else: total=int(total)
|
||||
if total is None:
|
||||
total = -1
|
||||
else:
|
||||
total = int(total)
|
||||
downloaded = 0
|
||||
with open(ngad.dist, 'wb') as out:
|
||||
for data in ngad.file.iter_content(chunk_size=max(total//100,1024)):
|
||||
for data in (ngad.file.
|
||||
iter_content(chunk_size=max(total//100, 1024))):
|
||||
downloaded += len(data)
|
||||
out.write(data)
|
||||
self.got_chunk.emit(100*downloaded//total)
|
||||
@ -115,7 +135,8 @@ class DownloadThread(QThread):
|
||||
def finish(self):
|
||||
global ngad
|
||||
ngad.progress.hide()
|
||||
ngad.notification=NotificationDialog(switch['success'][config["lang"]](ngad.songTitle))
|
||||
ngad.notification = NotificationDialog(
|
||||
switch['success'][config["lang"]](ngad.songTitle))
|
||||
ngad.notification.exec()
|
||||
self.deleteLater()
|
||||
|
||||
@ -126,7 +147,8 @@ class NotificationDialog(QDialog):
|
||||
loadUi('GUI/NotificationDialog.ui', self)
|
||||
self.label.setText(msg)
|
||||
chfont(self.label, switch['ntf'][f'font_{config["lang"]}'])
|
||||
self.setWindowFlags(self.windowFlags()&~QtCore.Qt.WindowCloseButtonHint)
|
||||
self.setWindowFlags(self.windowFlags() & ~
|
||||
QtCore.Qt.WindowCloseButtonHint)
|
||||
ngad.input.clear()
|
||||
self.btn.clicked.connect(self.accept)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user