Started developing GUI
This commit is contained in:
parent
e87869c1f4
commit
e17533e148
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
/Downloads
|
|
||||||
build*
|
build*
|
||||||
*.spec
|
*.spec
|
||||||
137
GUI/MainWindow.ui
Normal file
137
GUI/MainWindow.ui
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>600</width>
|
||||||
|
<height>200</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>600</width>
|
||||||
|
<height>200</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>600</width>
|
||||||
|
<height>200</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Newgrounds Audio Downloader</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<widget class="QLabel" name="title">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>551</width>
|
||||||
|
<height>41</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Century Gothic</family>
|
||||||
|
<pointsize>20</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Newgrounds Audio Downloader by H1K0</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLineEdit" name="input">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>86</y>
|
||||||
|
<width>551</width>
|
||||||
|
<height>24</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Courier New</family>
|
||||||
|
<pointsize>12</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Enter Newgrounds song ID.</string>
|
||||||
|
</property>
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="dlbtn">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>120</y>
|
||||||
|
<width>551</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Cooper Black</family>
|
||||||
|
<pointsize>16</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="cursor">
|
||||||
|
<cursorShape>PointingHandCursor</cursorShape>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Download!</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Return</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>600</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<action name="settings">
|
||||||
|
<property name="text">
|
||||||
|
<string>Settings...</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>F1, Alt+S</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="help">
|
||||||
|
<property name="text">
|
||||||
|
<string>Help</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>F1</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Binary file not shown.
@ -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 requests import get as load
|
||||||
from bs4 import BeautifulSoup as parse
|
from bs4 import BeautifulSoup as parse
|
||||||
import click
|
|
||||||
from sys import stdout
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
class GUI(QMainWindow):
|
||||||
@click.argument('songs',nargs=-1,metavar='<SongID [SongID [...]]>')
|
def __init__(self):
|
||||||
@click.option('-d','--dist',default='./Downloads',type=click.Path(exists=True),help='Where to save the songs (default: ./Downloads)')
|
super().__init__()
|
||||||
def CLI(songs,dist):
|
loadUi('GUI/MainWindow.ui',self)
|
||||||
"""===== Newgrounds Audio Downloader by H1K0 ====="""
|
self.dlbtn.clicked.connect(self.download)
|
||||||
for song in songs:
|
|
||||||
download(song,dist)
|
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):
|
if __name__ == '__main__':
|
||||||
print(f'Loading https://www.newgrounds.com/audio/listen/{songID}...')
|
from sys import argv
|
||||||
page=parse(load(f'https://www.newgrounds.com/audio/listen/{songID}').text,'html.parser')
|
app=QApplication(argv)
|
||||||
songTitle=page.find('title').text
|
ngad=GUI()
|
||||||
|
ngad.show()
|
||||||
print('Searching download link...')
|
app.exec_()
|
||||||
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()
|
|
||||||
11
README.md
11
README.md
@ -7,6 +7,7 @@ You just use **this**.
|
|||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- 
|
- 
|
||||||
|
- `PyQt5` library
|
||||||
- `requests` library
|
- `requests` library
|
||||||
- `bs4` library
|
- `bs4` library
|
||||||
- `click` library
|
- `click` library
|
||||||
@ -15,12 +16,6 @@ Or you just use the [`NGAudioDownloader.exe`](NGAudioDownloader.exe) so all you
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|

|
||||||
$ NGAudioDownloader.py [OPTIONS] <Newgrounds song ID>
|
|
||||||
|
|
||||||
===== Newgrounds Audio Downloader by H1K0 =====
|
It's easy as pie. You just run the downloader, enter your song ID and your file is being downloaded!
|
||||||
|
|
||||||
Options:
|
|
||||||
-d, --dist PATH Where to save the songs (default: ./Downloads)
|
|
||||||
--help Show this message and exit.
|
|
||||||
```
|
|
||||||
Reference in New Issue
Block a user