Skip to content

Commit

Permalink
Version Bumps
Browse files Browse the repository at this point in the history
Delete vscodecounter

update gitignore

Fix typo in command

Update dockerfile command

More modifications to s6

Remove windows only python package

Typo

Try changing the order

More s6 stuff

Typo bump

Major Refactor

Version Bump
  • Loading branch information
MrTyton committed May 27, 2024
1 parent cfd8a61 commit 23daeb4
Show file tree
Hide file tree
Showing 38 changed files with 4,710 additions and 1,572 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ jobs:
echo "CALIBRE_VERSION=$CALIBRE_VERSION" >> $GITHUB_ENV
FFF_VERSION=$(cat release-versions/fff.txt)
echo "FFF_VERSION=$FFF_VERSION" >> $GITHUB_ENV
S6_OVERLAY_VERSION=$(cat release-versions/s6.txt)
echo "S6_OVERLAY_VERSION=$S6_OVERLAY_VERSION" >> $GITHUB_ENV
- name: Print image tag
run: |
echo "Branch: $CI_ACTION_REF_NAME"
echo "Release Version: ${{ env.RELEASE_VERSION }}"
echo "Calibre Version: ${{ env.CALIBRE_VERSION }}"
echo "FFF Version: ${{ env.FFF_VERSION }}"
echo "S6 Overlay Version: ${{ env.S6_OVERLAY_VERSION }}"
- name: Login to DockerHub
uses: docker/[email protected]
with:
Expand All @@ -60,3 +62,4 @@ jobs:
VERSION=${{ env.RELEASE_VERSION }}
CALIBRE_RELEASE=${{ env.CALIBRE_VERSION }}
FFF_RELEASE=${{ env.FFF_VERSION }}
S6_OVERLAY_VERSION=${{ env.S6_OVERLAY_VERSION }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ ENV/
# mypy
.mypy_cache/

# Code Counter
.VSCodeCounter/
26 changes: 19 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ FROM python:3-slim
ARG VERSION
ARG CALIBRE_RELEASE
ARG FFF_RELEASE
LABEL build_version="FFDL-Auto version:- ${VERSION} Calibre: ${CALIBRE_RELEASE} FFF: ${FFF_RELEASE}"
ARG S6_OVERLAY_VERSION
LABEL build_version="FFDL-Auto version:- ${VERSION} Calibre: ${CALIBRE_RELEASE} FFF: ${FFF_RELEASE} S6_OVERLAY_VERSION: ${S6_OVERLAY_VERSION}"

ENV PUID="911" \
PGID="911"
Expand Down Expand Up @@ -36,6 +37,11 @@ RUN echo "**** install calibre ****" && \
apt-get install -y calibre && \
dbus-uuidgen > /etc/machine-id


RUN echo "*** Install Other Python Packages ***"
COPY requirements.txt /tmp/
RUN python3 -m pip install --no-cache-dir -r /tmp/requirements.txt

RUN echo "*** Install FFF ***" && \
if [ -z ${FFF_RELEASE} ]; then \
echo "FFF Using Default Release"; \
Expand All @@ -45,9 +51,14 @@ RUN echo "*** Install FFF ***" && \
python3 -m pip --no-cache-dir install --extra-index-url https://testpypi.python.org/pypi FanFicFare==${FFF_RELEASE}; \
fi


RUN echo "*** Install Other Python Packages ***" && \
python3 -m pip --no-cache-dir install pushbullet.py pillow
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-x86_64.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-arch.tar.xz

RUN echo "**** cleanup ****" && \
rm -rf \
Expand All @@ -57,10 +68,11 @@ RUN echo "**** cleanup ****" && \

COPY root/ /

RUN chmod -R +777 /etc/cont-init.d/
RUN chmod -R +777 /etc/s6-overlay/

VOLUME /config

WORKDIR /config

RUN groupmod -o -g "$PGID" abc && usermod -o -u "$PUID" abc && chown -R abc:abc /app && chown -R abc:abc /config && chown -R abc:abc /root && chmod +x /app/run.sh

CMD ["sh", "/app/run.sh"]
ENTRYPOINT ["/init"]
93 changes: 92 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,101 @@ Automated Fanfiction Download using FanficFare CLI

This is a docker image to run the Automated FFF CLI, with pushbullet integration.

[FanFicFare](https://github.com/JimmXinu/FanFicFare)

[Dockerhub Link](https://hub.docker.com/r/mrtyton/automated-ffdl)

## How to Install
- [AutomatedFanfic](#automatedfanfic)
- [Calibre Setup](#calibre-setup)
- [Execution](#execution)
- [How to Install - Docker](#how-to-install---docker)
- [How to Run - Non-Docker](#how-to-run---non-docker)
- [Configuration](#configuration)
- [Email](#email)
- [Calibre](#calibre)
- [Pushbullet](#pushbullet)


## Calibre Setup

1. Setup the Calibre Content Server. Instructions can be found on the [calibre website](https://manual.calibre-ebook.com/server.html)
2. Make note of the IP address, Port and Library for the server. If needed, also make note of the Username and Password.

## Execution

### How to Install - Docker

1. Install the docker image with `docker pull mrtyton/automated-ffdl`
2. Map the `/config` volume to someplace on your drive.
3. After running the image once, it will have copied over default configs. Fill them out and everything should start working.

### How to Run - Non-Docker

1. Make sure that you have calibre, and more importantly [calibredb](https://manual.calibre-ebook.com/generated/en/calibredb.html) installed on the system that you're running the script on. `calibredb` should be installed standard when you install calibre.
2. Install [Python3](https://www.python.org/downloads/)
3. Clone the Repo
4. Run `python -m pip install -r requirements.txt`
5. Install [FanficFare](https://github.com/JimmXinu/FanFicFare/wiki#command-line-interface-cli-version)
6. Fill out the config.toml file
7. Navigate to `root/app` and run `python fanficdownload.py`

## Configuration

The config file is a [TOML](https://toml.io/en/) file that contains the script's specific options. Changes to this file will only take effect upon script startup.


### Email

In order for the script to work, you have to fill out the email login information.

```toml
[email]
email = ""
password = ""
server = ""
mailbox = ""
sleep_time = 60
```


- `email`: The email address, username only.
- `password`: The password to the email address. It is recommened that you use an app password (Google's page on [App Password](https://support.google.com/accounts/answer/185833?hl=en)), rather than your email's actual password.
- `server`: Address for the email server. For Gmail, this is going to be `imap.gmail.com`. For other web services, you'll have to search for them.
- `mailbox`: Which mailbox to check, such as `INBOX`, for the unread update emails.
- `sleep_time`: How often to check the email account for new updates, in seconds. Default is 60 seconds, but you can make this as often as you want. Recommended that you don't go too fast though, since some email providers will not be happy.

### Calibre

The Calibre information for access and updating.

```toml
[calibre]
path=""
username=""
password=""
default_ini=""
personal_ini=""
```

- `path`: This is the path to your Calibre database. It's the location where your Calibre library is stored on your system. This can be either a directory that contains the `calibre.db` file, or the URL/Port/Library marked down above, such as `https://192.168.1.1:9001/#Fanfiction` This is the only argument that is **required** in this section.
- `username`: If your Calibre database is password protected, this is the username you use to access it.
- `password`: If your Calibre database is password protected, this is the password you use to access it.
- `default_ini`: This is the path to the [default INI configuration file](https://github.com/JimmXinu/FanFicFare/blob/main/fanficfare/defaults.ini) for FanFicFare.
- `personal_ini`: This is the path to your [personal INI configuration file](https://github.com/JimmXinu/FanFicFare/wiki/INI-File) for FanFicFare.

For both the default and personal INI, any changes made to them will take effect during the next update check, it does not require a restart of the script.

### Pushbullet

This script has an _optional_ [Pushbullet](https://pushbullet.com) integration, in case you want to get phone notifications when an update has occurred. The system will also send a notification if it fails to update a story, for whatever reason.

```toml
[pushbullet]
enabled = false
api_key = ""
device = ""
```

- `enabled`: Whether or not to enable the pushbullet notifications
- `api_key`: Your [[Pushbullet API Key](https://docs.pushbullet.com/#authentication)]
- `device`: If you want to send the notification to a specific device rather than the entirety of the pushbullet subscriptions, you can specify which device here with the device name.
2 changes: 1 addition & 1 deletion release-versions/fff.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.33.0
4.34.6
2 changes: 1 addition & 1 deletion release-versions/latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.04.01-1
2024.05.27-8
1 change: 1 addition & 0 deletions release-versions/s6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1.6.2
25 changes: 25 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
beautifulsoup4==4.12.3
Brotli==1.1.0
certifi==2024.2.2
chardet==5.2.0
charset-normalizer==3.3.2
cloudscraper==1.2.71
freezegun==1.5.1
html2text==2024.2.26
html5lib==1.1
idna==3.7
parameterized==0.9.0
pillow==10.3.0
pushbullet.py==0.12.0
pyparsing==3.1.2
python-dateutil==2.9.0.post0
python-magic==0.4.27
requests==2.31.0
requests-file==2.0.0
requests-toolbelt==1.0.0
setuptools==58.1.0
six==1.16.0
soupsieve==2.5
urllib3==2.2.1
webencodings==0.5.1
websocket-client==1.8.0
89 changes: 89 additions & 0 deletions root/app/calibre_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import multiprocessing as mp
import os
from subprocess import call

import ff_logging
import tomllib



class CalibreInfo:
"""
This class represents the Calibre library information.
It reads the configuration from a TOML file and provides access to the Calibre library details.
"""

def __init__(self, toml_path: str, manager: mp.Manager):
"""
Initialize the CalibreInfo object.
Args:
toml_path (str): The path to the TOML configuration file.
manager (mp.Manager): A multiprocessing Manager instance.
"""
# Open and load the TOML configuration file
with open(toml_path, "rb") as file:
config = tomllib.load(file)

# Get the 'calibre' section from the configuration
calibre_config = config.get("calibre", {})

# If the 'path' key is not present in the 'calibre' section, log a failure and raise an exception
if not calibre_config.get("path"):
message = "Calibre library location not set in the config file. Cannot search the calibre library or update it."
ff_logging.log_failure(message)
raise ValueError(message)

# Set the Calibre library details
self.location = calibre_config.get("path")
self.username = calibre_config.get("username")
self.password = calibre_config.get("password")
self.default_ini = self._append_filename(calibre_config.get("default_ini"), "defaults.ini")
self.personal_ini = self._append_filename(calibre_config.get("personal_ini"), "personal.ini")

# Create a lock for thread-safe operations
self.lock = manager.Lock()

@staticmethod
def _append_filename(path: str, filename: str) -> str:
"""
Append the filename to the path if it's not already there.
Args:
path (str): The original path.
filename (str): The filename to append.
Returns:
str: The path with the filename appended.
"""
# If the path is not None and does not already end with the filename, append the filename
if path and not path.endswith(filename):
return os.path.join(path, filename)
return path

# Check if Calibre is installed
def check_installed(self) -> bool:
try:
# Try to call calibredb
with open(os.devnull, "w") as nullout:
call(["calibredb"], stdout=nullout, stderr=nullout)
return True
except OSError:
# If calibredb is not found, log a failure and return False
ff_logging.log_failure(
"Calibredb is not installed on this system. Cannot search the calibre library or update it."
)
return False
except Exception as e:
# If any other error occurs, log a failure
ff_logging.log_failure(f"Some other issue happened. {e}")
return False

# String representation of the object
def __str__(self):
repr = f' --with-library "{self.location}"'
if self.username:
repr += f' --username "{self.username}"'
if self.password:
repr += f' --password "{self.password}"'
return repr
Loading

0 comments on commit 23daeb4

Please sign in to comment.