CLIized this
This commit is contained in:
parent
0bc2d9827d
commit
8bbe687323
Binary file not shown.
@ -1,33 +1,38 @@
|
||||
from os import access,F_OK,mkdir
|
||||
from requests import get as load
|
||||
from bs4 import BeautifulSoup as parse
|
||||
import click
|
||||
|
||||
print()
|
||||
@click.command()
|
||||
@click.argument('songid',nargs=1,metavar='<Newgrounds song ID>')
|
||||
@click.option('-d','--dist',default='./Downloads',type=click.Path(exists=True),help='Where to save the songs (default: ./Downloads)')
|
||||
def CLI(songid,dist):
|
||||
"""===== Newgrounds Audio Downloader by H1K0 ====="""
|
||||
print('Loading HTML...')
|
||||
page=parse(load(f'https://www.newgrounds.com/audio/listen/{songid}').text,'html.parser')
|
||||
songTitle=page.find('title').text
|
||||
|
||||
songId=input('Enter song id: ')
|
||||
print('Creating download link...')
|
||||
link=f'http://audio.ngfiles.com/{songid[:3]}000/{songid}_'
|
||||
count=0
|
||||
for char in songTitle:
|
||||
if 97<=ord(char.lower())<=122:
|
||||
link+=char
|
||||
count+=1
|
||||
elif char==' ':
|
||||
link+='-'
|
||||
count+=1
|
||||
if count==26:
|
||||
break
|
||||
link+='.mp3'
|
||||
|
||||
print('Loading HTML...')
|
||||
page=parse(load(f'https://www.newgrounds.com/audio/listen/{songId}').text,'html.parser')
|
||||
songTitle=page.find('title').text
|
||||
if not access(dist,F_OK):
|
||||
mkdir(dist)
|
||||
|
||||
print('Creating download link...')
|
||||
dllink=f'http://audio.ngfiles.com/{songId[:3]}000/{songId}_'
|
||||
count=0
|
||||
for char in songTitle:
|
||||
if 97<=ord(char.lower())<=122:
|
||||
dllink+=char
|
||||
count+=1
|
||||
elif char==' ':
|
||||
dllink+='-'
|
||||
count+=1
|
||||
if count==26:
|
||||
break
|
||||
dllink+='.mp3'
|
||||
print(f'Downloading "{songTitle}"...')
|
||||
with open(f'{dist}/{link.split("/")[-1]}','wb') as out:
|
||||
out.write(load(link).content)
|
||||
print(f'{songTitle} successfully downloaded.')
|
||||
|
||||
if not access('Downloads',F_OK):
|
||||
mkdir('Downloads')
|
||||
|
||||
print(f'Downloading "{songTitle}"...')
|
||||
with open(f'Downloads/{dllink.split("/")[-1]}','wb') as out:
|
||||
out.write(load(dllink).content)
|
||||
print(f'{songTitle} successfully downloaded.')
|
||||
if __name__=='__main__':
|
||||
CLI()
|
||||
21
README.md
21
README.md
@ -9,27 +9,22 @@ You just use **this**.
|
||||
- 
|
||||
- `requests` library
|
||||
- `bs4` library
|
||||
- `click` library
|
||||
|
||||
Or you just use the [`NGAudioDownloader.exe`](NGAudioDownloader.exe) so all you need is .
|
||||
|
||||
## Usage
|
||||
|
||||
Just run the code and enter the Newgrounds ID of the song you wanna download. That's all.
|
||||
|
||||
_Example:_
|
||||
|
||||
```
|
||||
$ python .\NGAudioDownloader.py
|
||||
$ NGAudioDownloader.py [OPTIONS] <Newgrounds song ID>
|
||||
|
||||
Enter song id: 807461
|
||||
Loading HTML...
|
||||
Creating download link...
|
||||
Downloading "Mysterious Planet"...
|
||||
Mysterious Planet successfully downloaded.
|
||||
===== Newgrounds Audio Downloader by H1K0 =====
|
||||
|
||||
Options:
|
||||
-d, --dist PATH Where to save the songs (default: ./Downloads)
|
||||
--help Show this message and exit.
|
||||
```
|
||||
|
||||
Your downloads will appear in the `Downloads` folder.
|
||||
|
||||
## NOTE!
|
||||
## ※NOTE!
|
||||
|
||||
Please note that you can download the songs named with *latin symbols only*. I'll fix it later so just for now bear with what we have. :3
|
||||
Reference in New Issue
Block a user