Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Danila The Blaster committed Sep 1, 2017
0 parents commit 3331f6a
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
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!
51 changes: 51 additions & 0 deletions app.py
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.')

29 changes: 29 additions & 0 deletions app.spec
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 )
3 changes: 3 additions & 0 deletions requirements.txt
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

0 comments on commit 3331f6a

Please sign in to comment.