Skip to content

Commit d6cbca1

Browse files
author
Ivy Bowman
authored
Merge pull request #4 from ivybowman/dev
Overhaul and re-write of AutoBooks Web
2 parents fcf9966 + 8d862ec commit d6cbca1

File tree

8 files changed

+249
-208
lines changed

8 files changed

+249
-208
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ for personal use with your preferred audiobook player during the loan period.
1010

1111
# Features
1212

13-
- AutoBooks Web: Uses selenium and chromedriver to download the odm files from overdrive without user interaction.
14-
- Uses odmpy to fulfill and convert odm files to chapterized m4b audiobooks.
13+
- AutoBooks Web: Uses requests to download odm files.
14+
- Uses odmpy to fulfill and convert odm files to m4b audiobooks with chapters.
1515
- Moves the generated audiobooks to a chosen folder.
1616
- Backs up the download files in case you need to re-download the books.
1717
- Logs to console and timestamped logfile.
@@ -20,7 +20,7 @@ for personal use with your preferred audiobook player during the loan period.
2020

2121
# Prerequisites
2222

23-
- Tools: git, ffmpeg, odmpy, chromedriver (Installed in setup guide.)
23+
- Tools: git, ffmpeg, odmpy (Installed in setup guide.)
2424
- Accounts: [Cronitor](https://cronitor.io/) For script monitoring, optional but will display errors if not setup.
2525

2626
# Links

autobooks/AutoBooks.py

Lines changed: 165 additions & 179 deletions
Large diffs are not rendered by default.

autobooks/DiscordBot.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
import pandas as pd
88
from discord.ext import commands
99

10-
from AutoBooks import web_run, main_run, version, script_dir, parser, csv_path, LOG_FILENAME, logger
10+
from AutoBooks import web_run, main_run, version, script_dir, config, csv_path, LOG_FILENAME, logger
1111

1212
# Bot Settings
13-
try:
14-
token = parser.get("DEFAULT", "discord_bot_token")
15-
except KeyError:
16-
logger.critical("Bot token field not found in config file, exiting.")
13+
token = config["discord_bot_token"]
1714
bot = commands.Bot(command_prefix='?')
1815

1916

@@ -72,7 +69,7 @@ async def hello(ctx):
7269
try:
7370
df = pd.read_csv(csv_path, sep=",")
7471
embed_var = discord.Embed(title="Autobooks Known Books",
75-
description=df['audiobook_title'].to_string(index=False), color=0xFFAFCC)
72+
description=df['book_title'].to_string(index=False), color=0xFFAFCC)
7673
embed_var.set_footer(text="OS: " + platform.platform() + " Host: " + os.uname())
7774
await ctx.channel.send(embed=embed_var)
7875
except FileNotFoundError:

autobooks/testconf.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import glob
2+
import os
3+
import shutil
4+
import sys
5+
from configparser import ConfigParser
6+
from configobj import ConfigObj
7+
from datetime import datetime
8+
from pathlib import Path
9+
from time import sleep
10+
from unittest.mock import patch
11+
import json
12+
import cronitor
13+
import odmpy.odm as odmpy
14+
import pandas as pd
15+
import requests
16+
from loguru import logger
17+
18+
script_dir = os.path.join(Path.home(), "AutoBooks")
19+
#config = ConfigObj(os.path.join(script_dir, "autobooks.ini"))
20+
# Read config file
21+
parser = ConfigParser()
22+
parser.read(os.path.join(script_dir, "autobooks.ini"))
23+
print(parser.sections())
24+
config = parser['DEFAULT']
25+
print(section['cronitor_apikey'])
26+
section = parser.default_section
27+
28+
#print(config.keys())
29+
#odm_dir = parser.get("DEFAULT", "odm_folder")
30+
#out_dir = parser.get("DEFAULT", "out_folder")
31+
#library_count = len(parser.sections())
32+
# Cronitor Setup https://cronitor.io/
33+
#cronitor.api_key = parser.get("DEFAULT", "cronitor_apikey")
34+
#monitor = cronitor.Monitor(parser.get("DEFAULT", "cronitor_name_main"))

autobooks/utils.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
2-
2+
import lxml.etree
33
from loguru import logger
4+
import json
45

56

67
# Formatter to remove patterns from log output
@@ -45,3 +46,31 @@ def process_logfile(logfile, terms=None):
4546
if any(term in line for term in terms):
4647
log_list.append(line)
4748
return "".join(log_list)
49+
50+
51+
def parse_form(box, sort):
52+
form_dict = {}
53+
txt = lxml.etree.HTML(box.content)
54+
js = str(txt.xpath(f"//script[contains(text(), 'window.OverDrive.{sort} =')]/text()")[0]).strip()
55+
split_1 = js.split(sep=" = ")
56+
for i in range(0, len(split_1)):
57+
if "window.OverDrive." + sort in split_1[i]:
58+
form_dict = split_1[i + 1].strip().split(';')[0]
59+
break
60+
return dict(json.loads(form_dict))
61+
62+
63+
def craft_booklist(loans_page):
64+
book_dict = parse_form(loans_page, "mediaItems")
65+
book_list_parse = []
66+
for i in book_dict:
67+
book_format = book_dict[i]['overDriveFormat']['id']
68+
book_title = book_dict[i]['title']
69+
book_id = book_dict[i]['id']
70+
book_parse = {
71+
'id': book_id,
72+
'title': book_title,
73+
'format': book_format,
74+
}
75+
book_list_parse.append(book_parse)
76+
return book_list_parse
File renamed without changes.

setup.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Open a PowerShell window then follow the steps below.
1313
`Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`
1414
2. Run the Scoop installer, this is a package manager used to install some prerequisites.
1515
`iwr -useb get.scoop.sh | iex`
16-
3. Install prerequisites. Note: Chromedriver requires Google Chrome to be installed.
17-
`scoop install ffmpeg chromedriver git`
16+
3. Install prerequisites.
17+
`scoop install ffmpeg git`
1818

1919
## macOS Setup Guide
2020

@@ -23,20 +23,15 @@ Open a terminal window then follow the steps below. Works with both M1 and Intel
2323
2. Install Homebrew. Be sure to follow instructions at the end for adding it to path.
2424
`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
2525
3. Install prerequisites. On trying to use these tools you might see an unideditifed developer pop up, this is normal just open the folder and ctrl+click or right click on the file and click open.
26-
Note: Chromedriver requires Google Chrome to be installed.
27-
`brew install ffmpeg chromedriver`
26+
`brew install ffmpeg`
2827

2928
## Debian/Ubuntu Linux Setup Guide
3029

3130
Open a terminal window then follow the steps below.
3231
2. Update package list.
3332
`sudo apt-get update`
34-
2. Install most prerequisites.
35-
`sudo apt-get install -y unzip ffmpeg git`
36-
3. Run script to install the other prerequisites. Note: Chrome is required for AutoBooksWeb.
37-
With Google Chrome: `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/ivybowman/AutoBooks/main/ubuntusetupchrome.sh)"`
38-
Without Google Chrome: `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/ivybowman/AutoBooks/main/ubuntusetup.sh)"`
39-
Note: AutoBooks Web is not compatible with WSL, and requires X11 forwarding to run via ssh if headless mode is disabled.
33+
2. Install prerequisites.
34+
`sudo apt-get install -y ffmpeg git`
4035

4136

4237
## AutoBooks Install & Setup (All Operating Systems)
@@ -45,17 +40,17 @@ Note: AutoBooks Web is not compatible with WSL, and requires X11 forwarding to r
4540
To install from the latest source run the following command.
4641
`pip3 install git+https://git@github.com/ivybowman/autobooks.git --upgrade --force-reinstall`
4742
To install from a specific version run the following command.
48-
`pip3 install git+https://git@github.com/ivybowman/autobooks.git@v0.2.1-alpha --upgrade`
43+
`pip3 install git+https://git@github.com/ivybowman/autobooks.git@v0.3-alpha --upgrade`
4944
To uninstall AutoBooks run the following command.
5045
`pip3 uninstall autobooks`
5146

5247
### Configuration
5348

5449
1. Open a terminal and run `autobooks` this will run setup commands to create the data folder.
55-
2. Edit the `autobooks.conf` file using one of the commands below or by browsing to the autobooks folder inside your home directory.
56-
- Windows(GUI) PowerShell: `notepad $env:USERPROFILE\AutoBooks\autobooks.conf`
57-
- Windows(GUI) Command Prompt: `notepad %userprofile%\AutoBooks\autobooks.conf`
58-
- macOS(GUI) Terminal: `open -a TextEdit ~/AutoBooks/autobooks.conf`
59-
- Linux or macOS(CLI): `nano ~/AutoBooks/autobooks.conf`
50+
2. Edit the `autobooks.ini` file using one of the commands below or by browsing to the autobooks folder inside your home directory.
51+
- Windows(GUI) PowerShell: `notepad $env:USERPROFILE\AutoBooks\autobooks.ini`
52+
- Windows(GUI) Command Prompt: `notepad %userprofile%\AutoBooks\autobooks.ini`
53+
- macOS(GUI) Terminal: `open -a TextEdit ~/AutoBooks/autobooks.ini`
54+
- Linux or macOS(CLI): `nano ~/AutoBooks/autobooks.ini`
6055

6156

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup
22

3-
VERSION = '0.3'
3+
VERSION = '0.4'
44
DESCRIPTION = 'Python tool to automate processing a batch of OverDrive audiobooks.'
55
LONG_DESCRIPTION = 'Python tool to automate processing a batch of OverDrive audiobooks.'
66

@@ -21,8 +21,8 @@
2121
"autobooks-discord = autobooks.AutoBooksDiscord:run"
2222
]
2323
},
24-
install_requires=['odmpy @ git+https://git@github.com/ping/odmpy.git', "cronitor", "pandas", "discord.py",
25-
"selenium", "requests", "loguru"],
24+
install_requires=["odmpy @ git+https://git@github.com/ping/odmpy.git", "cronitor", "pandas", "discord.py",
25+
"requests", "loguru", "lxml"],
2626
include_package_data=True,
2727
platforms="any",
2828
keywords=['python', 'AutoBooks'],

0 commit comments

Comments
 (0)