diff --git a/.gitignore b/.gitignore index 6043407..534dc86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ __pycache__ -/Downloads build* *.spec \ No newline at end of file diff --git a/GUI/MainWindow.ui b/GUI/MainWindow.ui new file mode 100644 index 0000000..724dbc3 --- /dev/null +++ b/GUI/MainWindow.ui @@ -0,0 +1,137 @@ + + + MainWindow + + + + 0 + 0 + 600 + 200 + + + + + 0 + 0 + + + + + 600 + 200 + + + + + 600 + 200 + + + + Newgrounds Audio Downloader + + + + + + 20 + 20 + 551 + 41 + + + + + Century Gothic + 20 + + + + Newgrounds Audio Downloader by H1K0 + + + Qt::AlignCenter + + + + + + 20 + 86 + 551 + 24 + + + + + Courier New + 12 + + + + + + + Enter Newgrounds song ID. + + + true + + + + + + 20 + 120 + 551 + 31 + + + + + Cooper Black + 16 + + + + PointingHandCursor + + + Download! + + + Return + + + + + + + 0 + 0 + 600 + 21 + + + + + + Settings... + + + F1, Alt+S + + + + + Help + + + F1 + + + + + + diff --git a/NGAudioDownloader.exe b/NGAudioDownloader.exe index 409e640..977d58d 100644 Binary files a/NGAudioDownloader.exe and b/NGAudioDownloader.exe differ diff --git a/NGAudioDownloader.py b/NGAudioDownloader.py index 007e3a0..353433e 100644 --- a/NGAudioDownloader.py +++ b/NGAudioDownloader.py @@ -1,50 +1,47 @@ -from os import access,F_OK,mkdir +from PyQt5.uic import loadUi +from PyQt5.QtWidgets import ( + QApplication, QMainWindow, QWidget, + QDialog, QFileDialog, QInputDialog +) from requests import get as load from bs4 import BeautifulSoup as parse -import click -from sys import stdout -@click.command() -@click.argument('songs',nargs=-1,metavar='') -@click.option('-d','--dist',default='./Downloads',type=click.Path(exists=True),help='Where to save the songs (default: ./Downloads)') -def CLI(songs,dist): - """===== Newgrounds Audio Downloader by H1K0 =====""" - for song in songs: - download(song,dist) +class GUI(QMainWindow): + def __init__(self): + super().__init__() + loadUi('GUI/MainWindow.ui',self) + self.dlbtn.clicked.connect(self.download) + + def download(self): + # Validating input + songID=self.input.text() + page=parse(load(f'https://www.newgrounds.com/audio/listen/{songID}').text,'html.parser') + if page.find(id='pageerror') is not None: + self.input.clear() + return + songTitle=page.find('title').text + # Getting download link + link='http://audio.ngfiles.com/' + page=str(page) + i=page.find('audio.ngfiles.com')+len('audio.ngfiles.com/') + while not link.endswith('.mp3'): + if page[i]!='\\': link+=page[i] + i+=1 + # Locating file + dist=QFileDialog.getSaveFileName(self,'Save File', + link.split('/')[-1], + 'MP3 Audio File (*.mp3)')[0] + if not dist: return + # Downloading + with open(dist,'wb') as out: + out.write(load(link).content) + self.input.clear() -def download(songID,dist): - print(f'Loading https://www.newgrounds.com/audio/listen/{songID}...') - page=parse(load(f'https://www.newgrounds.com/audio/listen/{songID}').text,'html.parser') - songTitle=page.find('title').text - - print('Searching download link...') - link='http://audio.ngfiles.com/' - page=str(page) - i=page.find('audio.ngfiles.com')+len('audio.ngfiles.com/') - while not link.endswith('.mp3'): - if page[i]!='\\': link+=page[i] - i+=1 - - if not access(dist,F_OK): mkdir(dist) - print(f'Downloading "{songTitle}"...') - BARLEN=50 - with open(f'{dist}/{link.split("/")[-1]}','wb') as out: - file=load(link,stream=True) - total=file.headers.get('content-length') - if total is None: total=-1 - else: total=int(total) - downloaded=0 - for data in file.iter_content(chunk_size=max(total//BARLEN,1024)): - downloaded+=len(data) - out.write(data) - done=BARLEN*downloaded//total - stdout.write(f'\r[{"█"*done}{"·"*(BARLEN-done)}]') - stdout.flush() - print() - print(f'"{songTitle}" successfully downloaded.') - - -if __name__=='__main__': - CLI() \ No newline at end of file +if __name__ == '__main__': + from sys import argv + app=QApplication(argv) + ngad=GUI() + ngad.show() + app.exec_() \ No newline at end of file diff --git a/README.md b/README.md index 7da5069..62a53e7 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ You just use **this**. ## Requirements - ![(Python 3+)](https://img.shields.io/badge/Python-3+-blue.svg) +- `PyQt5` library - `requests` library - `bs4` library - `click` library @@ -15,12 +16,6 @@ Or you just use the [`NGAudioDownloader.exe`](NGAudioDownloader.exe) so all you ## Usage -``` -$ NGAudioDownloader.py [OPTIONS] +![Start screen shot](https://i.ibb.co/X2dRVTS/2020-08-23-19-39-14-Newgrounds-Audio-Downloader.png) - ===== Newgrounds Audio Downloader by H1K0 ===== - -Options: - -d, --dist PATH Where to save the songs (default: ./Downloads) - --help Show this message and exit. -``` \ No newline at end of file +It's easy as pie. You just run the downloader, enter your song ID and your file is being downloaded! \ No newline at end of file