PEP8-ed python files
This commit is contained in:
parent
021d471357
commit
7e6a23fa5d
@ -14,161 +14,183 @@ from configer import config
|
|||||||
|
|
||||||
|
|
||||||
class GUI(QMainWindow):
|
class GUI(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
loadUi('GUI/MainWindow.ui',self)
|
loadUi('GUI/MainWindow.ui', self)
|
||||||
self.applylang()
|
self.applylang()
|
||||||
self.btn.clicked.connect(self.download)
|
self.btn.clicked.connect(self.download)
|
||||||
self.actionSettings.triggered.connect(self.show_settings)
|
self.actionSettings.triggered.connect(self.show_settings)
|
||||||
self.actionHelp.triggered.connect(self.show_help)
|
self.actionHelp.triggered.connect(self.show_help)
|
||||||
|
|
||||||
def applylang(self):
|
def applylang(self):
|
||||||
self.title.setText(switch['title'][config["lang"]])
|
self.title.setText(switch['title'][config["lang"]])
|
||||||
chfont(self.title,switch['title'][f'font_{config["lang"]}'])
|
chfont(self.title, switch['title'][f'font_{config["lang"]}'])
|
||||||
self.input.setPlaceholderText(switch['placeholder'][config["lang"]])
|
self.input.setPlaceholderText(switch['placeholder'][config["lang"]])
|
||||||
chfont(self.input,switch['placeholder'][f'font_{config["lang"]}'])
|
chfont(self.input, switch['placeholder'][f'font_{config["lang"]}'])
|
||||||
self.btn.setText(switch['btn'][config["lang"]])
|
self.btn.setText(switch['btn'][config["lang"]])
|
||||||
chfont(self.btn,switch['btn'][f'font_{config["lang"]}'])
|
chfont(self.btn, switch['btn'][f'font_{config["lang"]}'])
|
||||||
self.menu.setTitle(switch['menu'][config["lang"]])
|
self.menu.setTitle(switch['menu'][config["lang"]])
|
||||||
chfont(self.menubar,switch['menu'][f'font_{config["lang"]}'])
|
chfont(self.menubar, switch['menu'][f'font_{config["lang"]}'])
|
||||||
self.actionSettings.setText(switch['settings'][config["lang"]])
|
self.actionSettings.setText(switch['settings'][config["lang"]])
|
||||||
self.actionHelp.setText(switch['helpbtn'][config["lang"]])
|
self.actionHelp.setText(switch['helpbtn'][config["lang"]])
|
||||||
|
|
||||||
def download(self):
|
def download(self):
|
||||||
# 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(
|
||||||
self.notification.exec()
|
switch['empinp'][config["lang"]])
|
||||||
return
|
self.notification.exec()
|
||||||
elif not songID.isdigit():
|
return
|
||||||
self.notification=NotificationDialog(switch['typerr'][config["lang"]])
|
elif not songID.isdigit():
|
||||||
self.notification.exec()
|
self.notification = NotificationDialog(
|
||||||
return
|
switch['typerr'][config["lang"]])
|
||||||
page=parse(load(f'https://www.newgrounds.com/audio/listen/{songID}').text,'html.parser')
|
self.notification.exec()
|
||||||
if page.find(id='pageerror') is not None:
|
return
|
||||||
self.notification=NotificationDialog(switch['404'][config["lang"]])
|
page = parse(load('https://www.newgrounds.com/audio/listen/'
|
||||||
self.notification.exec()
|
f'{songID}').text, 'html.parser')
|
||||||
return
|
if page.find(id='pageerror') is not None:
|
||||||
self.songTitle=page.find('title').text
|
self.notification = NotificationDialog(
|
||||||
# Getting download link
|
switch['404'][config["lang"]])
|
||||||
link='http://audio.ngfiles.com/'
|
self.notification.exec()
|
||||||
page=str(page)
|
return
|
||||||
i=page.find('audio.ngfiles.com')+len('audio.ngfiles.com/')
|
self.songTitle = page.find('title').text
|
||||||
while not link.endswith('.mp3'):
|
# Getting download link
|
||||||
if page[i]!='\\': link+=page[i]
|
link = 'http://audio.ngfiles.com/'
|
||||||
i+=1
|
page = str(page)
|
||||||
# Locating file
|
i = page.find('audio.ngfiles.com')+len('audio.ngfiles.com/')
|
||||||
self.dist=QFileDialog.getSaveFileName(self,switch['savefile'][config["lang"]],
|
while not link.endswith('.mp3'):
|
||||||
link.split('/')[-1],
|
if page[i] != '\\':
|
||||||
'MP3 Audio File (*.mp3)')[0]
|
link += page[i]
|
||||||
if not self.dist: return
|
i += 1
|
||||||
# Downloading
|
# Locating file
|
||||||
self.file=load(link,stream=True)
|
self.dist = (QFileDialog.
|
||||||
self.progress=ProgressDialog()
|
getSaveFileName(self, switch['savefile'][config["lang"]],
|
||||||
self.progress.label.setText(switch['downloading'][config["lang"]](self.songTitle))
|
link.split('/')[-1],
|
||||||
self.progress.setWindowTitle(switch['downloading'][config["lang"]](self.songTitle))
|
'MP3 Audio File (*.mp3)')[0])
|
||||||
self.progress.bar.setValue(0)
|
if not self.dist:
|
||||||
self.progress.exec()
|
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.bar.setValue(0)
|
||||||
|
self.progress.exec()
|
||||||
|
|
||||||
def show_settings(self):
|
def show_settings(self):
|
||||||
self.settings=SettingsDialog()
|
self.settings = SettingsDialog()
|
||||||
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):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
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() & ~
|
||||||
self.thread=DownloadThread()
|
QtCore.Qt.WindowCloseButtonHint)
|
||||||
self.thread.got_chunk.connect(lambda done:self.bar.setValue(done))
|
self.thread = DownloadThread()
|
||||||
self.thread.finished.connect(self.thread.finish)
|
self.thread.got_chunk.connect(lambda done: self.bar.setValue(done))
|
||||||
self.thread.start()
|
self.thread.finished.connect(self.thread.finish)
|
||||||
|
self.thread.start()
|
||||||
|
|
||||||
|
|
||||||
class DownloadThread(QThread):
|
class DownloadThread(QThread):
|
||||||
got_chunk=pyqtSignal(object)
|
got_chunk = pyqtSignal(object)
|
||||||
|
|
||||||
def __init__(self): super().__init__()
|
def __init__(self): super().__init__()
|
||||||
|
|
||||||
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
|
||||||
downloaded=0
|
else:
|
||||||
with open(ngad.dist,'wb') as out:
|
total = int(total)
|
||||||
for data in ngad.file.iter_content(chunk_size=max(total//100,1024)):
|
downloaded = 0
|
||||||
downloaded+=len(data)
|
with open(ngad.dist, 'wb') as out:
|
||||||
out.write(data)
|
for data in (ngad.file.
|
||||||
self.got_chunk.emit(100*downloaded//total)
|
iter_content(chunk_size=max(total//100, 1024))):
|
||||||
|
downloaded += len(data)
|
||||||
|
out.write(data)
|
||||||
|
self.got_chunk.emit(100*downloaded//total)
|
||||||
|
|
||||||
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(
|
||||||
ngad.notification.exec()
|
switch['success'][config["lang"]](ngad.songTitle))
|
||||||
self.deleteLater()
|
ngad.notification.exec()
|
||||||
|
self.deleteLater()
|
||||||
|
|
||||||
|
|
||||||
class NotificationDialog(QDialog):
|
class NotificationDialog(QDialog):
|
||||||
def __init__(self,msg):
|
def __init__(self, msg):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
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() & ~
|
||||||
ngad.input.clear()
|
QtCore.Qt.WindowCloseButtonHint)
|
||||||
self.btn.clicked.connect(self.accept)
|
ngad.input.clear()
|
||||||
|
self.btn.clicked.connect(self.accept)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
class SettingsDialog(QDialog):
|
class SettingsDialog(QDialog):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
loadUi('GUI/SettingsDialog.ui',self)
|
loadUi('GUI/SettingsDialog.ui', self)
|
||||||
self.setWindowTitle(switch['settings'][config["lang"]])
|
self.setWindowTitle(switch['settings'][config["lang"]])
|
||||||
self.title.setText(switch['settings'][config["lang"]])
|
self.title.setText(switch['settings'][config["lang"]])
|
||||||
self.label_lang.setText(switch['lang'][config["lang"]])
|
self.label_lang.setText(switch['lang'][config["lang"]])
|
||||||
chfont(self.label_lang,switch['lang'][f'font_{config["lang"]}'])
|
chfont(self.label_lang, switch['lang'][f'font_{config["lang"]}'])
|
||||||
if config["lang"]=='en':
|
if config["lang"] == 'en':
|
||||||
self.rbtn_en.setChecked(True)
|
self.rbtn_en.setChecked(True)
|
||||||
elif config["lang"]=='ru':
|
elif config["lang"] == 'ru':
|
||||||
self.rbtn_ru.setChecked(True)
|
self.rbtn_ru.setChecked(True)
|
||||||
elif config["lang"]=='jp':
|
elif config["lang"] == 'jp':
|
||||||
self.rbtn_jp.setChecked(True)
|
self.rbtn_jp.setChecked(True)
|
||||||
self.newlang=config["lang"]
|
self.newlang = config["lang"]
|
||||||
self.rbtn_en.toggled.connect(lambda:self.chlang('en'))
|
self.rbtn_en.toggled.connect(lambda: self.chlang('en'))
|
||||||
self.rbtn_ru.toggled.connect(lambda:self.chlang('ru'))
|
self.rbtn_ru.toggled.connect(lambda: self.chlang('ru'))
|
||||||
self.rbtn_jp.toggled.connect(lambda:self.chlang('jp'))
|
self.rbtn_jp.toggled.connect(lambda: self.chlang('jp'))
|
||||||
self.accepted.connect(self.updlang)
|
self.accepted.connect(self.updlang)
|
||||||
|
|
||||||
def chlang(self,newlang):
|
def chlang(self, newlang):
|
||||||
if newlang!=config["lang"]:
|
if newlang != config["lang"]:
|
||||||
self.newlang=newlang
|
self.newlang = newlang
|
||||||
|
|
||||||
def updlang(self):
|
def updlang(self):
|
||||||
config["lang"]=self.newlang
|
config["lang"] = self.newlang
|
||||||
ngad.applylang()
|
ngad.applylang()
|
||||||
|
|
||||||
|
|
||||||
def chfont(unit,font): unit.setStyleSheet(f'font-family:{font}')
|
def chfont(unit, font): unit.setStyleSheet(f'font-family:{font}')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from sys import argv
|
from sys import argv
|
||||||
app=QApplication(argv)
|
app = QApplication(argv)
|
||||||
ngad=GUI()
|
ngad = GUI()
|
||||||
ngad.show()
|
ngad.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|||||||
40
configer.py
40
configer.py
@ -1,31 +1,31 @@
|
|||||||
from json import load,dump
|
from json import load, dump
|
||||||
from os import access,F_OK
|
from os import access, F_OK
|
||||||
|
|
||||||
|
|
||||||
default={
|
default = {
|
||||||
"lang":"en"
|
"lang": "en"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if access('config.json',F_OK):
|
if access('config.json', F_OK):
|
||||||
with open('config.json',encoding='utf-8') as file:
|
with open('config.json', encoding='utf-8') as file:
|
||||||
self.data=load(file)
|
self.data = load(file)
|
||||||
else:
|
else:
|
||||||
self.data=default
|
self.data = default
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def __getitem__(self,key):
|
def __getitem__(self, key):
|
||||||
return self.data[key]
|
return self.data[key]
|
||||||
|
|
||||||
def __setitem__(self,key,value):
|
def __setitem__(self, key, value):
|
||||||
self.data[key]=value
|
self.data[key] = value
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
with open('config.json','w',encoding='utf-8') as file:
|
with open('config.json', 'w', encoding='utf-8') as file:
|
||||||
dump(self.data,file)
|
dump(self.data, file)
|
||||||
|
|
||||||
|
|
||||||
config=Config()
|
config = Config()
|
||||||
|
|||||||
180
langswitch.py
180
langswitch.py
@ -1,90 +1,90 @@
|
|||||||
switch={
|
switch = {
|
||||||
"title":{
|
"title": {
|
||||||
"en":"<strong>Newgrounds Audio Downloader</strong> by <em>H1K0</em>",
|
"en": "<strong>Newgrounds Audio Downloader</strong> by <em>H1K0</em>",
|
||||||
"ru":"<strong>Newgrounds Audio Downloader</strong> от <em>H1K0</em>",
|
"ru": "<strong>Newgrounds Audio Downloader</strong> от <em>H1K0</em>",
|
||||||
"jp":"<em>H1K0</em> の <strong>Newgrounds Audio Downloader</strong>",
|
"jp": "<em>H1K0</em> の <strong>Newgrounds Audio Downloader</strong>",
|
||||||
"font_en":"Comic Sans MS",
|
"font_en": "Comic Sans MS",
|
||||||
"font_ru":"Comic Sans MS",
|
"font_ru": "Comic Sans MS",
|
||||||
"font_jp":"UD Digi Kyokasho N-R"
|
"font_jp": "UD Digi Kyokasho N-R"
|
||||||
},
|
},
|
||||||
"placeholder":{
|
"placeholder": {
|
||||||
"en":"Enter Newgrounds song ID.",
|
"en": "Enter Newgrounds song ID.",
|
||||||
"ru":"Введи айдишник трека на Newgrounds.",
|
"ru": "Введи айдишник трека на Newgrounds.",
|
||||||
"jp":"NSIを入力しよう!",
|
"jp": "NSIを入力しよう!",
|
||||||
"font_en":"Maiandra GD",
|
"font_en": "Maiandra GD",
|
||||||
"font_ru":"Courier New",
|
"font_ru": "Courier New",
|
||||||
"font_jp":"Rounded Mplus 1c"
|
"font_jp": "Rounded Mplus 1c"
|
||||||
},
|
},
|
||||||
"btn":{
|
"btn": {
|
||||||
"en":"Download!",
|
"en": "Download!",
|
||||||
"ru":"Скачать!",
|
"ru": "Скачать!",
|
||||||
"jp":"ダウンロード!",
|
"jp": "ダウンロード!",
|
||||||
"font_en":"Cooper Black",
|
"font_en": "Cooper Black",
|
||||||
"font_ru":"851CHIKARA-DZUYOKU-KANA-A",
|
"font_ru": "851CHIKARA-DZUYOKU-KANA-A",
|
||||||
"font_jp":"Nagurigaki Crayon"
|
"font_jp": "Nagurigaki Crayon"
|
||||||
},
|
},
|
||||||
"ntf":{
|
"ntf": {
|
||||||
"font_en":"Maiandra GD",
|
"font_en": "Maiandra GD",
|
||||||
"font_ru":"Courier New",
|
"font_ru": "Courier New",
|
||||||
"font_jp":"Rounded Mplus 1c"
|
"font_jp": "Rounded Mplus 1c"
|
||||||
},
|
},
|
||||||
"empinp":{
|
"empinp": {
|
||||||
"en":"Hey-hey, don't leave the input empty!",
|
"en": "Hey-hey, don't leave the input empty!",
|
||||||
"ru":"Эй, ну хоть что-нибудь напиши!",
|
"ru": "Эй, ну хоть что-нибудь напиши!",
|
||||||
"jp":"おいおい、何も入力してねえんじゃねえかよ!"
|
"jp": "おいおい、何も入力してねえんじゃねえかよ!"
|
||||||
},
|
},
|
||||||
"typerr":{
|
"typerr": {
|
||||||
"en":"Newgrounds song ID consists of digits only!",
|
"en": "Newgrounds song ID consists of digits only!",
|
||||||
"ru":"Айдишник трека состоит только из цифр!",
|
"ru": "Айдишник трека состоит только из цифр!",
|
||||||
"jp":"NSIは数字だけだ!"
|
"jp": "NSIは数字だけだ!"
|
||||||
},
|
},
|
||||||
"404":{
|
"404": {
|
||||||
"en":"And there's no song with this ID!",
|
"en": "And there's no song with this ID!",
|
||||||
"ru":"А нет песенки с таким айдишником!",
|
"ru": "А нет песенки с таким айдишником!",
|
||||||
"jp":"そのNSIの曲は存在してないな!"
|
"jp": "そのNSIの曲は存在してないな!"
|
||||||
},
|
},
|
||||||
"savefile":{
|
"savefile": {
|
||||||
"en":"Save file",
|
"en": "Save file",
|
||||||
"ru":"Сохранить файл",
|
"ru": "Сохранить файл",
|
||||||
"jp":"ファイル保存"
|
"jp": "ファイル保存"
|
||||||
},
|
},
|
||||||
"downloading":{
|
"downloading": {
|
||||||
"en":lambda songTitle:f'Downloading «{songTitle}»...',
|
"en": lambda songTitle: f'Downloading «{songTitle}»...',
|
||||||
"ru":lambda songTitle:f'Скачивание трека «{songTitle}»...',
|
"ru": lambda songTitle: f'Скачивание трека «{songTitle}»...',
|
||||||
"jp":lambda songTitle:f'「{songTitle}」ダウンロード中・・・',
|
"jp": lambda songTitle: f'「{songTitle}」ダウンロード中・・・',
|
||||||
"font_en":"Maiandra GD",
|
"font_en": "Maiandra GD",
|
||||||
"font_ru":"Courier New",
|
"font_ru": "Courier New",
|
||||||
"font_jp":"Rounded Mplus 1c"
|
"font_jp": "Rounded Mplus 1c"
|
||||||
},
|
},
|
||||||
"success":{
|
"success": {
|
||||||
"en":lambda songTitle:f'«{songTitle}» has been downloaded successfully!',
|
"en": lambda songTitle: f'«{songTitle}» has been downloaded successfully!',
|
||||||
"ru":lambda songTitle:f'«{songTitle}»: скачано!',
|
"ru": lambda songTitle: f'«{songTitle}»: скачано!',
|
||||||
"jp":lambda songTitle:f'「{songTitle}」ダウンロード完了!'
|
"jp": lambda songTitle: f'「{songTitle}」ダウンロード完了!'
|
||||||
},
|
},
|
||||||
"menu":{
|
"menu": {
|
||||||
"en":"MENU",
|
"en": "MENU",
|
||||||
"ru":"МЕНЮ",
|
"ru": "МЕНЮ",
|
||||||
"jp":"メニュー",
|
"jp": "メニュー",
|
||||||
"font_en":"Century Gothic",
|
"font_en": "Century Gothic",
|
||||||
"font_ru":"Century Gothic",
|
"font_ru": "Century Gothic",
|
||||||
"font_jp":"Rounded Mplus 1c"
|
"font_jp": "Rounded Mplus 1c"
|
||||||
},
|
},
|
||||||
"settings":{
|
"settings": {
|
||||||
"en":"Settings",
|
"en": "Settings",
|
||||||
"ru":"Настройки",
|
"ru": "Настройки",
|
||||||
"jp":"設定"
|
"jp": "設定"
|
||||||
},
|
},
|
||||||
"helpbtn":{
|
"helpbtn": {
|
||||||
"en":"Help",
|
"en": "Help",
|
||||||
"ru":"Помощь",
|
"ru": "Помощь",
|
||||||
"jp":"ヘルプ"
|
"jp": "ヘルプ"
|
||||||
},
|
},
|
||||||
"lang":{
|
"lang": {
|
||||||
"en":"Language",
|
"en": "Language",
|
||||||
"ru":"Язык",
|
"ru": "Язык",
|
||||||
"jp":"言語",
|
"jp": "言語",
|
||||||
"font_en":"Century Gothic",
|
"font_en": "Century Gothic",
|
||||||
"font_ru":"Century Gothic",
|
"font_ru": "Century Gothic",
|
||||||
"font_jp":"Rounded Mplus 1c"
|
"font_jp": "Rounded Mplus 1c"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user