-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Danila The Blaster
committed
Sep 1, 2017
0 parents
commit 3331f6a
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Download multi-part audio books from Audioknigi.club | ||
---------------------------------------------------- | ||
|
||
## Pre-requisites | ||
|
||
* Python3 (https://www.python.org/downloads) | ||
* pip (https://pip.pypa.io/en/stable/installing/) | ||
* virtualenv (https://pypi.python.org/pypi/virtualenv) | ||
* git client (ftp://git.narod.ru) | ||
|
||
## Installation (Windows) | ||
|
||
* Create a virtual environment, clone the code: | ||
``` | ||
virtualenv downloader | ||
cd downloader | ||
git clone https://github.com/deathtracktor/audioknigi-club-downloader-app.git src | ||
``` | ||
|
||
* Install dependencies: | ||
``` | ||
scripts\pip install -r src\requirements.txt | ||
``` | ||
|
||
* Run the app: | ||
``` | ||
cd src | ||
scripts\python app.py | ||
``` | ||
* Or build a single-file executable: | ||
``` | ||
cd src | ||
pyinstaller app.spec --onefile | ||
``` | ||
NB: the current version of PyInstaller (3.2.1) is broken. Use development version instead: | ||
``` | ||
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz | ||
``` | ||
|
||
Enjoy! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Download complete audio books from audioknigi.ru | ||
""" | ||
import re | ||
import requests | ||
import sys | ||
from bs4 import BeautifulSoup | ||
|
||
|
||
CHAPTERS_URL = 'https://audioknigi.club/rest/bid/{}' | ||
USAGE_HELP = ''' | ||
Audioknigi.club book downloader. | ||
Usage: {0} <url> | ||
url: a URL of a multi-part audio book. | ||
''' | ||
|
||
def get_book_id(url): | ||
"""Get internal book ID.""" | ||
resp = requests.get(url) | ||
soup = BeautifulSoup(resp.content, 'html.parser') | ||
player = re.compile(r'audioPlayer\((.*)\,') | ||
script_code = next(filter(lambda el: player.search(el.text), soup.findAll('script'))) | ||
return player.search(str(script_code)).group(1) | ||
|
||
|
||
def get_chapters(book_id): | ||
"""Get chapter info.""" | ||
for chapter in requests.get(CHAPTERS_URL.format(book_id)).json(): | ||
yield chapter['title'], chapter['mp3'] | ||
|
||
|
||
def download_chapter(url): | ||
"""Download a chapter.""" | ||
return requests.get(url).content | ||
|
||
# start the app | ||
if __name__ == '__main__': | ||
|
||
if len(sys.argv) != 2: | ||
print(USAGE_HELP.format(*sys.argv)) | ||
sys.exit(1) | ||
|
||
book_url = sys.argv[1] | ||
|
||
for fname, url in get_chapters(get_book_id(book_url)): | ||
print('Downloading chapter {}'.format(fname)) | ||
with open('{}.mp3'.format(fname), 'wb') as outfile: | ||
outfile.write(download_chapter(url)) | ||
|
||
print('All done.') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- mode: python -*- | ||
|
||
block_cipher = None | ||
|
||
|
||
a = Analysis(['app.py'], | ||
pathex=['C:\\Users\\danila\\OneDrive\\downloader\\src'], | ||
binaries=[], | ||
datas=[], | ||
hiddenimports=[], | ||
hookspath=[], | ||
runtime_hooks=[], | ||
excludes=[], | ||
win_no_prefer_redirects=False, | ||
win_private_assemblies=False, | ||
cipher=block_cipher) | ||
pyz = PYZ(a.pure, a.zipped_data, | ||
cipher=block_cipher) | ||
exe = EXE(pyz, | ||
a.scripts, | ||
a.binaries, | ||
a.zipfiles, | ||
a.datas, | ||
name='app', | ||
debug=False, | ||
strip=False, | ||
upx=True, | ||
runtime_tmpdir=None, | ||
console=True ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bs4==0.0.1 | ||
requests==2.18.4 | ||
PyInstaller==3.3 |