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