updated
This commit is contained in:
parent
10982f7172
commit
83895e3689
33
Dockerfile
33
Dockerfile
@ -2,9 +2,7 @@ FROM python:3.9-slim
|
|||||||
|
|
||||||
# set version label
|
# set version label
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
ARG CALIBRE_RELEASE
|
LABEL build_version="FFFRssLinkGrabber version:- ${VERSION}"
|
||||||
ARG FFF_RELEASE
|
|
||||||
LABEL build_version="FFDL-Auto version:- ${VERSION} Calibre: ${CALIBRE_RELEASE} FFF: ${FFF_RELEASE}"
|
|
||||||
|
|
||||||
ENV PUID="911" \
|
ENV PUID="911" \
|
||||||
PGID="911"
|
PGID="911"
|
||||||
@ -33,10 +31,10 @@ RUN set -x && \
|
|||||||
--shell /bin/bash \
|
--shell /bin/bash \
|
||||||
abc
|
abc
|
||||||
|
|
||||||
RUN echo "**** install calibre ****" && \
|
#RUN echo "**** install calibre ****" && \
|
||||||
set -x && \
|
# set -x && \
|
||||||
apt-get install -y calibre && \
|
# apt-get install -y calibre && \
|
||||||
dbus-uuidgen > /etc/machine-id
|
# dbus-uuidgen > /etc/machine-id
|
||||||
|
|
||||||
|
|
||||||
RUN echo "**** s6 omsta;; ****" && \
|
RUN echo "**** s6 omsta;; ****" && \
|
||||||
@ -54,16 +52,17 @@ RUN echo "**** s6 omsta;; ****" && \
|
|||||||
tar -xzf /tmp/${s6_package} -C /
|
tar -xzf /tmp/${s6_package} -C /
|
||||||
|
|
||||||
RUN echo *** Install Packages *** && \
|
RUN echo *** Install Packages *** && \
|
||||||
set -x && \
|
#set -x && \
|
||||||
if [ -z ${FFF_RELEASE} ]; then \
|
#if [ -z ${FFF_RELEASE} ]; then \
|
||||||
echo "FFF Using Default Release"; \
|
# echo "FFF Using Default Release"; \
|
||||||
python3 -m pip --no-cache-dir install FanFicFare; \
|
# python3 -m pip --no-cache-dir install FanFicFare; \
|
||||||
else \
|
#else \
|
||||||
echo "FF Using ${FFF_RELEASE} Release"; \
|
# echo "FF Using ${FFF_RELEASE} Release"; \
|
||||||
python3 -m pip --no-cache-dir install --extra-index-url https://testpypi.python.org/pypi FanFicFare==${FFF_RELEASE}; \
|
# python3 -m pip --no-cache-dir install --extra-index-url https://testpypi.python.org/pypi FanFicFare==${FFF_RELEASE}; \
|
||||||
fi && \
|
#fi && \
|
||||||
python3 -m pip --no-cache-dir install pushbullet.py pillow && \
|
#python3 -m pip --no-cache-dir install pushbullet.py pillow && \
|
||||||
ln -s /opt/calibre/calibredb /bin/calibredb
|
python3 -m pip --no-cache-dir install feedparser && \
|
||||||
|
#ln -s /opt/calibre/calibredb /bin/calibredb
|
||||||
|
|
||||||
RUN echo "**** cleanup ****" && \
|
RUN echo "**** cleanup ****" && \
|
||||||
rm -rf \
|
rm -rf \
|
||||||
|
BIN
release-versions/.DS_Store
vendored
Normal file
BIN
release-versions/.DS_Store
vendored
Normal file
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
6.12.0
|
|
@ -1 +0,0 @@
|
|||||||
4.20.6
|
|
@ -1 +1 @@
|
|||||||
2023.02.26
|
2023.06.06
|
@ -1,447 +0,0 @@
|
|||||||
from fanficfare import geturls
|
|
||||||
from os import listdir, remove, rename, utime, devnull
|
|
||||||
from os.path import isfile, join
|
|
||||||
from subprocess import check_output, STDOUT, call, PIPE
|
|
||||||
import logging
|
|
||||||
from optparse import OptionParser
|
|
||||||
import re
|
|
||||||
from configparser import ConfigParser
|
|
||||||
from tempfile import mkdtemp
|
|
||||||
from shutil import rmtree, copyfile
|
|
||||||
import socket
|
|
||||||
from time import strftime, localtime
|
|
||||||
import os
|
|
||||||
import errno
|
|
||||||
|
|
||||||
from multiprocessing import Pool
|
|
||||||
|
|
||||||
logging.getLogger("fanficfare").setLevel(logging.ERROR)
|
|
||||||
|
|
||||||
|
|
||||||
class bcolors:
|
|
||||||
HEADER = '\033[95m'
|
|
||||||
OKBLUE = '\033[94m'
|
|
||||||
OKGREEN = '\033[92m'
|
|
||||||
WARNING = '\033[93m'
|
|
||||||
FAIL = '\033[91m'
|
|
||||||
ENDC = '\033[0m'
|
|
||||||
BOLD = '\033[1m'
|
|
||||||
UNDERLINE = '\033[4m'
|
|
||||||
|
|
||||||
|
|
||||||
def log(msg, color=None, output=True):
|
|
||||||
if color:
|
|
||||||
col = bcolors.HEADER
|
|
||||||
if color == 'BLUE':
|
|
||||||
col = bcolors.OKBLUE
|
|
||||||
elif color == 'GREEN':
|
|
||||||
col = bcolors.OKGREEN
|
|
||||||
elif color == 'WARNING':
|
|
||||||
col = bcolors.WARNING
|
|
||||||
elif color == 'FAIL':
|
|
||||||
col = bcolors.FAIL
|
|
||||||
elif color == 'BOLD':
|
|
||||||
col = bcolors.BOLD
|
|
||||||
elif color == 'UNDERLINE':
|
|
||||||
col = bcolors.UNDERLINE
|
|
||||||
line = '{}{}{}: \t {}{}{}'.format(
|
|
||||||
bcolors.BOLD,
|
|
||||||
strftime(
|
|
||||||
'%m/%d/%Y %H:%M:%S',
|
|
||||||
localtime()),
|
|
||||||
bcolors.ENDC,
|
|
||||||
col,
|
|
||||||
msg,
|
|
||||||
bcolors.ENDC)
|
|
||||||
else:
|
|
||||||
line = '{}{}{}: \t {}'.format(
|
|
||||||
bcolors.BOLD,
|
|
||||||
strftime(
|
|
||||||
'%m/%d/%Y %H:%M:%S',
|
|
||||||
localtime()),
|
|
||||||
bcolors.ENDC,
|
|
||||||
msg)
|
|
||||||
if output:
|
|
||||||
print(line)
|
|
||||||
return ""
|
|
||||||
else:
|
|
||||||
return line + "\n"
|
|
||||||
|
|
||||||
|
|
||||||
def touch(fname, times=None):
|
|
||||||
with open(fname, 'a'):
|
|
||||||
utime(fname, times)
|
|
||||||
|
|
||||||
|
|
||||||
url_parsers = [(re.compile('(fanfiction.net/s/\d*/?).*'), "www."), #ffnet
|
|
||||||
(re.compile('(archiveofourown.org/works/\d*)/?.*'), ""), #ao3
|
|
||||||
(re.compile('(fictionpress.com/s/\d*)/?.*'), ""), #fictionpress
|
|
||||||
(re.compile('(royalroad.com/fiction/\d*)/?.*'), ""), #royalroad
|
|
||||||
(re.compile('https?://(.*)'), "")] #other sites
|
|
||||||
story_name = re.compile('(.*)-.*')
|
|
||||||
|
|
||||||
equal_chapters = re.compile('.* already contains \d* chapters.')
|
|
||||||
chapter_difference = re.compile(
|
|
||||||
'.* contains \d* chapters, more than source: \d*.')
|
|
||||||
bad_chapters = re.compile(
|
|
||||||
".* doesn't contain any recognizable chapters, probably from a different source. Not updating.")
|
|
||||||
no_url = re.compile('No story URL found in epub to update.')
|
|
||||||
more_chapters = re.compile(
|
|
||||||
".*File\(.*\.epub\) Updated\(.*\) more recently than Story\(.*\) - Skipping")
|
|
||||||
|
|
||||||
|
|
||||||
def parse_url(url):
|
|
||||||
for cur_parser, cur_prefix in url_parsers:
|
|
||||||
if cur_parser.search(url):
|
|
||||||
url = cur_prefix + cur_parser.search(url).group(1)
|
|
||||||
return url
|
|
||||||
return url
|
|
||||||
|
|
||||||
|
|
||||||
def get_files(mypath, filetype=None, fullpath=False):
|
|
||||||
ans = []
|
|
||||||
if filetype:
|
|
||||||
ans = [f for f in listdir(mypath) if isfile(
|
|
||||||
join(mypath, f)) and f.endswith(filetype)]
|
|
||||||
else:
|
|
||||||
ans = [f for f in listdir(mypath) if isfile(join(mypath, f))]
|
|
||||||
if fullpath:
|
|
||||||
return [join(mypath, f) for f in ans]
|
|
||||||
else:
|
|
||||||
return ans
|
|
||||||
|
|
||||||
|
|
||||||
def check_regexes(output):
|
|
||||||
if equal_chapters.search(output):
|
|
||||||
raise ValueError(
|
|
||||||
"Issue with story, site is broken. Story likely hasn't updated on site yet.")
|
|
||||||
if bad_chapters.search(output):
|
|
||||||
raise ValueError(
|
|
||||||
"Something is messed up with the site or the epub. No chapters found.")
|
|
||||||
if no_url.search(output):
|
|
||||||
raise ValueError("No URL in epub to update from. Fix the metadata.")
|
|
||||||
|
|
||||||
|
|
||||||
def downloader(args):
|
|
||||||
url, inout_file, path, live = args
|
|
||||||
loc = mkdtemp()
|
|
||||||
output = ""
|
|
||||||
output += log("Working with url {}".format(url), 'HEADER', live)
|
|
||||||
storyId = None
|
|
||||||
try:
|
|
||||||
if path:
|
|
||||||
try:
|
|
||||||
storyId = check_output(
|
|
||||||
'calibredb search "Identifiers:{}" {}'.format(
|
|
||||||
url, path), shell=True, stderr=STDOUT, stdin=PIPE, ).decode('utf-8')
|
|
||||||
output += log("\tStory is in calibre with id {}".format(storyId), 'BLUE', live)
|
|
||||||
output += log("\tExporting file", 'BLUE', live)
|
|
||||||
res = check_output(
|
|
||||||
'calibredb export {} --dont-save-cover --dont-write-opf --single-dir --to-dir "{}" {}'.format(
|
|
||||||
storyId, loc, path), shell=True, stdin=PIPE, stderr=STDOUT).decode('utf-8')
|
|
||||||
cur = get_files(loc, ".epub", True)[0]
|
|
||||||
output += log(
|
|
||||||
'\tDownloading with fanficfare, updating file "{}"'.format(cur),
|
|
||||||
'GREEN',
|
|
||||||
live)
|
|
||||||
moving = ""
|
|
||||||
except BaseException:
|
|
||||||
# story is not in calibre
|
|
||||||
output += log("\tStory is not in Calibre", 'WARNING', live)
|
|
||||||
cur = url
|
|
||||||
moving = 'cd "{}" && '.format(loc)
|
|
||||||
copyfile("/config/personal.ini", "{}/personal.ini".format(loc))
|
|
||||||
copyfile("/config/defaults.ini", "{}/defaults.ini".format(loc))
|
|
||||||
output += log('\tRunning: {}python3.9 -m fanficfare.cli -u "{}" --update-cover --non-interactive'.format(
|
|
||||||
moving, cur), 'BLUE', live)
|
|
||||||
res = check_output('{}python3.9 -m fanficfare.cli -u "{}" --update-cover --non-interactive --config={}/personal.ini'.format(
|
|
||||||
moving, cur, loc), shell=True, stderr=STDOUT, stdin=PIPE).decode('utf-8')
|
|
||||||
check_regexes(res)
|
|
||||||
if chapter_difference.search(res) or more_chapters.search(res):
|
|
||||||
output += log("\tForcing download update due to:",
|
|
||||||
'WARNING', live)
|
|
||||||
for line in res.split("\n"):
|
|
||||||
if line:
|
|
||||||
output += log("\t\t{}".format(line), 'WARNING', live)
|
|
||||||
res = check_output(
|
|
||||||
'{}python3.9 -m fanficfare.cli -u "{}" --force --update-cover --non-interactive --config={}/personal.ini'.format(
|
|
||||||
moving, cur, loc), shell=True, stderr=STDOUT, stdin=PIPE).decode('utf-8')
|
|
||||||
check_regexes(res)
|
|
||||||
cur = get_files(loc, '.epub', True)[0]
|
|
||||||
|
|
||||||
if storyId:
|
|
||||||
output += log("\tRemoving {} from library".format(storyId),
|
|
||||||
'BLUE', live)
|
|
||||||
try:
|
|
||||||
res = check_output(
|
|
||||||
'calibredb remove {} {}'.format(
|
|
||||||
path,
|
|
||||||
storyId),
|
|
||||||
shell=True,
|
|
||||||
stderr=STDOUT,
|
|
||||||
stdin=PIPE,
|
|
||||||
).decode('utf-8')
|
|
||||||
except BaseException:
|
|
||||||
if not live:
|
|
||||||
print(output.strip())
|
|
||||||
raise
|
|
||||||
|
|
||||||
output += log("\tAdding {} to library".format(cur), 'BLUE', live)
|
|
||||||
try:
|
|
||||||
res = check_output(
|
|
||||||
'calibredb add -d {} "{}"'.format(path, cur), shell=True, stderr=STDOUT, stdin=PIPE, ).decode('utf-8')
|
|
||||||
except Exception as e:
|
|
||||||
output += log(e)
|
|
||||||
if not live:
|
|
||||||
print(output.strip())
|
|
||||||
raise
|
|
||||||
try:
|
|
||||||
res = check_output(
|
|
||||||
'calibredb search "Identifiers:{}" {}'.format(
|
|
||||||
url, path), shell=True, stderr=STDOUT, stdin=PIPE).decode('utf-8')
|
|
||||||
output += log("\tAdded {} to library with id {}".format(cur,
|
|
||||||
res), 'GREEN', live)
|
|
||||||
except BaseException:
|
|
||||||
output += log(
|
|
||||||
"It's been added to library, but not sure what the ID is.",
|
|
||||||
'WARNING',
|
|
||||||
live)
|
|
||||||
output += log("Added /Story-file to library with id 0", 'GREEN', live)
|
|
||||||
remove(cur)
|
|
||||||
else:
|
|
||||||
res = check_output(
|
|
||||||
'cd "{}" && fanficfare -u "{}" --update-cover'.format(
|
|
||||||
loc, url), shell=True, stderr=STDOUT, stdin=PIPE).decode('utf-8')
|
|
||||||
check_regexes(res)
|
|
||||||
cur = get_files(loc, '.epub', True)[0]
|
|
||||||
name = get_files(loc, '.epub', False)[0]
|
|
||||||
rename(cur, name)
|
|
||||||
output += log(
|
|
||||||
"Downloaded story {} to {}".format(
|
|
||||||
story_name.search(name).group(1),
|
|
||||||
name),
|
|
||||||
'GREEN',
|
|
||||||
live)
|
|
||||||
if not live:
|
|
||||||
print(output.strip())
|
|
||||||
rmtree(loc)
|
|
||||||
except Exception as e:
|
|
||||||
output += log("Exception: {}".format(e), 'FAIL', live)
|
|
||||||
if not live:
|
|
||||||
print(output.strip())
|
|
||||||
try:
|
|
||||||
rmtree(loc)
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
with open(inout_file, "a") as fp:
|
|
||||||
fp.write("{}\n".format(url))
|
|
||||||
|
|
||||||
|
|
||||||
def main(user, password, server, label, inout_file, path, lib_user, lib_password, live):
|
|
||||||
|
|
||||||
if path:
|
|
||||||
path = '--with-library "{}" --username {} --password {}'.format(
|
|
||||||
path, lib_user, lib_password)
|
|
||||||
try:
|
|
||||||
with open(devnull, 'w') as nullout:
|
|
||||||
call(['calibredb'], stdout=nullout, stderr=nullout)
|
|
||||||
except OSError as e:
|
|
||||||
if e.errno == errno.ENOENT:
|
|
||||||
log("Calibredb is not installed on this system. Cannot search the calibre library or update it.", 'FAIL')
|
|
||||||
return
|
|
||||||
|
|
||||||
touch(inout_file)
|
|
||||||
|
|
||||||
with open(inout_file, "r") as fp:
|
|
||||||
urls = set([x.replace("\n", "") for x in fp.readlines()])
|
|
||||||
|
|
||||||
with open(inout_file, "w") as fp:
|
|
||||||
fp.write("")
|
|
||||||
|
|
||||||
try:
|
|
||||||
socket.setdefaulttimeout(55)
|
|
||||||
urls |= geturls.get_urls_from_imap(server, user, password, label)
|
|
||||||
socket.setdefaulttimeout(None)
|
|
||||||
except BaseException:
|
|
||||||
with open(inout_file, "w") as fp:
|
|
||||||
for cur in urls:
|
|
||||||
fp.write("{}\n".format(cur))
|
|
||||||
return
|
|
||||||
|
|
||||||
if not urls:
|
|
||||||
return
|
|
||||||
urls = set(parse_url(x) for x in urls)
|
|
||||||
log("URLs to parse ({}):".format(len(urls)), 'HEADER')
|
|
||||||
for url in urls:
|
|
||||||
log("\t{}".format(url), 'BLUE')
|
|
||||||
if len(urls) == 1:
|
|
||||||
downloader([list(urls)[0], inout_file, path, True])
|
|
||||||
else:
|
|
||||||
for url in urls:
|
|
||||||
downloader([url, inout_file, path, True])
|
|
||||||
with open(inout_file, "r") as fp:
|
|
||||||
urls = set([x.replace("\n", "") for x in fp.readlines()])
|
|
||||||
with open(inout_file, "w") as fp:
|
|
||||||
fp.writelines(["{}\n".format(x) for x in urls])
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
option_parser = OptionParser(usage="usage: %prog [flags]")
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-u',
|
|
||||||
'--user',
|
|
||||||
action='store',
|
|
||||||
dest='user',
|
|
||||||
help='Email Account Username. Required.')
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-p',
|
|
||||||
'--password',
|
|
||||||
action='store',
|
|
||||||
dest='password',
|
|
||||||
help='Email Account Password. Required.')
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-s',
|
|
||||||
'--server',
|
|
||||||
action='store',
|
|
||||||
dest='server',
|
|
||||||
default="imap.gmail.com",
|
|
||||||
help='Email IMAP Server. Default is "imap.gmail.com".')
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-m',
|
|
||||||
'--mailbox',
|
|
||||||
action='store',
|
|
||||||
dest='mailbox',
|
|
||||||
default='INBOX',
|
|
||||||
help='Email Label. Default is "INBOX".')
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-l',
|
|
||||||
'--library',
|
|
||||||
action='store',
|
|
||||||
dest='library',
|
|
||||||
help="calibre library db location. If none is passed, then this merely scrapes the email and error file for new stories and downloads them into the current directory.")
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-i',
|
|
||||||
'--input',
|
|
||||||
action='store',
|
|
||||||
dest='input',
|
|
||||||
default="./fanfiction.txt",
|
|
||||||
help="Error file. Any urls that fail will be output here, and file will be read to find any urls that failed previously. If file does not exist will create. File is overwitten every time the program is run.")
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-c',
|
|
||||||
'--config',
|
|
||||||
action='store',
|
|
||||||
dest='config',
|
|
||||||
help='Config file for inputs. Blank config file is provided. No default. If an option is present in whatever config file is passed it, the option will overwrite whatever is passed in through command line arguments unless the option is blank. Do not put any quotation marks in the options.')
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-o',
|
|
||||||
'--output',
|
|
||||||
action='store_true',
|
|
||||||
dest='live',
|
|
||||||
help='Include this if you want all the output to be saved and posted live. Useful when multithreading.')
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-q',
|
|
||||||
'--libuser',
|
|
||||||
action='store',
|
|
||||||
dest='libuser',
|
|
||||||
help='Calibre User. Required.')
|
|
||||||
|
|
||||||
option_parser.add_option(
|
|
||||||
'-w',
|
|
||||||
'--libpassword',
|
|
||||||
action='store',
|
|
||||||
dest='libpassword',
|
|
||||||
help='Calibre Password. Required.')
|
|
||||||
|
|
||||||
(options, args) = option_parser.parse_args()
|
|
||||||
|
|
||||||
if options.config:
|
|
||||||
touch(options.config)
|
|
||||||
config = ConfigParser(allow_no_value=True)
|
|
||||||
config.read(options.config)
|
|
||||||
|
|
||||||
def updater(option, newval): return newval if newval != "" else option
|
|
||||||
try:
|
|
||||||
options.user = updater(
|
|
||||||
options.user, config.get(
|
|
||||||
'login', 'user').strip())
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
options.password = updater(
|
|
||||||
options.password, config.get(
|
|
||||||
'login', 'password').strip())
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
options.libuser = updater(
|
|
||||||
options.libuser, config.get(
|
|
||||||
'login', 'libuser').strip())
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
options.libpassword = updater(
|
|
||||||
options.libpassword, config.get(
|
|
||||||
'login', 'libpassword').strip())
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
options.server = updater(
|
|
||||||
options.server, config.get(
|
|
||||||
'login', 'server').strip())
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
options.mailbox = updater(
|
|
||||||
options.mailbox, config.get(
|
|
||||||
'login', 'mailbox').strip())
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
options.library = updater(
|
|
||||||
options.library, config.get(
|
|
||||||
'locations', 'library').strip())
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
options.input = updater(
|
|
||||||
options.input, config.get(
|
|
||||||
'locations', 'input').strip())
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
options.live = updater(
|
|
||||||
options.live, config.getboolean(
|
|
||||||
'output', 'live').strip())
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if not (options.user or options.password):
|
|
||||||
raise ValueError("User or Password not given")
|
|
||||||
main(
|
|
||||||
options.user,
|
|
||||||
options.password,
|
|
||||||
options.server,
|
|
||||||
options.mailbox,
|
|
||||||
options.input,
|
|
||||||
options.library,
|
|
||||||
options.libuser,
|
|
||||||
options.libpassword,
|
|
||||||
options.live)
|
|
@ -1,8 +0,0 @@
|
|||||||
class Notification():
|
|
||||||
def __init__(self):
|
|
||||||
|
|
||||||
self.name="Fanfiction"
|
|
||||||
|
|
||||||
def send_notification(self, title, text):
|
|
||||||
return
|
|
||||||
|
|
@ -1,171 +1,181 @@
|
|||||||
from io import StringIO
|
# from io import StringIO
|
||||||
import re
|
# import re
|
||||||
from subprocess import check_output, STDOUT
|
# from subprocess import check_output, STDOUT
|
||||||
from time import sleep
|
# from time import sleep
|
||||||
import ntpath
|
# import ntpath
|
||||||
|
|
||||||
from os import utime
|
# from os import utime
|
||||||
from os.path import join
|
# from os.path import join
|
||||||
|
|
||||||
from notifications import Notification
|
# from notifications import Notification
|
||||||
from pushbullet import Pushbullet
|
# from pushbullet import Pushbullet
|
||||||
|
|
||||||
|
import feedparser
|
||||||
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
def enable_notifications(options):
|
# def enable_notifications(options):
|
||||||
if options.pushbullet:
|
# if options.pushbullet:
|
||||||
fail = False
|
# fail = False
|
||||||
try:
|
# try:
|
||||||
pb = Pushbullet(options.pushbullet)
|
# pb = Pushbullet(options.pushbullet)
|
||||||
except BaseException:
|
# except BaseException:
|
||||||
print("Problem wtih connecting to pushbullet. API Key likely invalid")
|
# print("Problem wtih connecting to pushbullet. API Key likely invalid")
|
||||||
fail = True
|
# fail = True
|
||||||
if options.pbdevice and not fail:
|
# if options.pbdevice and not fail:
|
||||||
try:
|
# try:
|
||||||
pb = pb.get_device(options.pbdevice)
|
# pb = pb.get_device(options.pbdevice)
|
||||||
except BaseException:
|
# except BaseException:
|
||||||
print("Cannot get this device.")
|
# print("Cannot get this device.")
|
||||||
fail = True
|
# fail = True
|
||||||
pass
|
# pass
|
||||||
if not fail:
|
# if not fail:
|
||||||
temp_note = Notification()
|
# temp_note = Notification()
|
||||||
temp_note.send_notification = pb.push_note
|
# temp_note.send_notification = pb.push_note
|
||||||
yield temp_note
|
# yield temp_note
|
||||||
|
|
||||||
|
|
||||||
def touch(fname, times=None):
|
# def touch(fname, times=None):
|
||||||
with open(fname, 'a'):
|
# with open(fname, 'a'):
|
||||||
utime(fname, times)
|
# utime(fname, times)
|
||||||
|
|
||||||
|
|
||||||
def main(options):
|
def main(config):
|
||||||
try:
|
|
||||||
res = check_output(
|
feed = feedparser.parse(config.get('locations', 'feed'))
|
||||||
f"python3.9 /app/fanficdownload.py -c {options.config}",
|
print(len(feed.entries))
|
||||||
shell=True,
|
print(feed.entries[0].link)
|
||||||
stderr=STDOUT)
|
with open(config.get('locations', 'output'), 'a') as f: #input=/config/fanfiction_file
|
||||||
except Exception as e:
|
for entry in feed.entries:
|
||||||
print(e)
|
f.write(f"{entry.link}\n")
|
||||||
res = None
|
# try:
|
||||||
if not res:
|
# res = check_output(
|
||||||
return
|
# f"python3.9 /app/fanficdownload.py -c {options.config}",
|
||||||
else:
|
# shell=True,
|
||||||
res = res.decode('utf-8')
|
# stderr=STDOUT)
|
||||||
print(res)
|
# except Exception as e:
|
||||||
buf = StringIO(res)
|
# print(e)
|
||||||
regex = re.compile("Added (?:.*/)?(.*)-.* to library with id \d*")
|
# return False
|
||||||
searcher = regex.search
|
# res = None
|
||||||
stripper = False
|
# if not res:
|
||||||
for line in buf.readlines():
|
# return
|
||||||
r = searcher(line)
|
# else:
|
||||||
if r:
|
# res = res.decode('utf-8')
|
||||||
story = ntpath.basename(r.group(1).strip())
|
# print(res)
|
||||||
stripper = True
|
# buf = StringIO(res)
|
||||||
for notify in enable_notifications(options):
|
# regex = re.compile("Added (?:.*/)?(.*)-.* to library with id \d*")
|
||||||
notify.send_notification("New Fanfiction Download", story)
|
# searcher = regex.search
|
||||||
if stripper and options.tag:
|
# stripper = False
|
||||||
import sqlite3
|
# for line in buf.readlines():
|
||||||
with sqlite3.connect(join(options.library_path, "metadata.db")) as conn:
|
# r = searcher(line)
|
||||||
c = conn.cursor()
|
# if r:
|
||||||
c.execute("delete from books_tags_link where id in (select id from books_tags_link where tag in (select id from tags where name like '%Last Update%'));")
|
# story = ntpath.basename(r.group(1).strip())
|
||||||
return
|
# stripper = True
|
||||||
|
# for notify in enable_notifications(options):
|
||||||
|
# notify.send_notification("New Fanfiction Download", story)
|
||||||
|
# if stripper and options.tag:
|
||||||
|
# import sqlite3
|
||||||
|
# with sqlite3.connect(join(options.library_path, "metadata.db")) as conn:
|
||||||
|
# c = conn.cursor()
|
||||||
|
# c.execute("delete from books_tags_link where id in (select id from books_tags_link where tag in (select id from tags where name like '%Last Update%'));")
|
||||||
|
# return True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
option_parser = OptionParser(usage="usage: %prog [flags]")
|
option_parser = OptionParser(usage="usage: %prog [flags]")
|
||||||
option_parser.add_option(
|
# option_parser.add_option(
|
||||||
'-p',
|
# '-p',
|
||||||
'--pushbullet',
|
# '--pushbullet',
|
||||||
action='store',
|
# action='store',
|
||||||
dest='pushbullet',
|
# dest='pushbullet',
|
||||||
help='If you want to use pushbullet, pass in your key here.')
|
# help='If you want to use pushbullet, pass in your key here.')
|
||||||
option_parser.add_option(
|
# option_parser.add_option(
|
||||||
'-d',
|
# '-d',
|
||||||
'--device',
|
# '--device',
|
||||||
action='store',
|
# action='store',
|
||||||
dest='pbdevice',
|
# dest='pbdevice',
|
||||||
help='If you wish to only send to a certian pushbullet device, put the device name here. If the device name is invalid, will just send to all pushbullets associated with the acc')
|
# help='If you wish to only send to a certian pushbullet device, put the device name here. If the device name is invalid, will just send to all pushbullets associated with the acc')
|
||||||
option_parser.add_option(
|
# option_parser.add_option(
|
||||||
'-n',
|
# '-n',
|
||||||
'--notify',
|
# '--notify',
|
||||||
action='store_true',
|
# action='store_true',
|
||||||
dest='notify',
|
# dest='notify',
|
||||||
help='Enable if you want to use system notifications. Only for Win/Linux.')
|
# help='Enable if you want to use system notifications. Only for Win/Linux.')
|
||||||
option_parser.add_option(
|
option_parser.add_option(
|
||||||
'-c',
|
'-c',
|
||||||
'--config',
|
'--config',
|
||||||
action='store',
|
action='store',
|
||||||
dest='config',
|
dest='config',
|
||||||
help='Config file for inputs. Blank config file is provided. No default. If an option is present in whatever config file is passed it, the option will overwrite whatever is passed in through command line arguments unless the option is blank. Do not put any quotation marks in the options.')
|
help='Config file for inputs. Blank config file is provided. No default. If an option is present in whatever config file is passed it, the option will overwrite whatever is passed in through command line arguments unless the option is blank. Do not put any quotation marks in the options.')
|
||||||
option_parser.add_option(
|
# option_parser.add_option(
|
||||||
'-t',
|
# '-t',
|
||||||
'--tag',
|
# '--tag',
|
||||||
action='store_true',
|
# action='store_true',
|
||||||
dest='tag',
|
# dest='tag',
|
||||||
help='Strip Last Updated tags from calibredb. Requires library to be passed in.')
|
# help='Strip Last Updated tags from calibredb. Requires library to be passed in.')
|
||||||
option_parser.add_option(
|
# option_parser.add_option(
|
||||||
'-l',
|
# '-l',
|
||||||
'--library',
|
# '--library',
|
||||||
action='store',
|
# action='store',
|
||||||
dest='library',
|
# dest='library',
|
||||||
help='Path to calibre library. If you are connecting to a calibre webserver then this should be the url.')
|
# help='Path to calibre library. If you are connecting to a calibre webserver then this should be the url.')
|
||||||
option_parser.add_option(
|
# option_parser.add_option(
|
||||||
'-a',
|
# '-a',
|
||||||
'--library-path',
|
# '--library-path',
|
||||||
action='store',
|
# action='store',
|
||||||
dest='library_path',
|
# dest='library_path',
|
||||||
help='Path location of library. Will be equal to library if nothing is passed in.')
|
# help='Path location of library. Will be equal to library if nothing is passed in.')
|
||||||
|
|
||||||
(options, args) = option_parser.parse_args()
|
(options, args) = option_parser.parse_args()
|
||||||
|
|
||||||
if options.library and not options.library_path:
|
# if options.library and not options.library_path:
|
||||||
options.library_path = options.library
|
# options.library_path = options.library
|
||||||
|
|
||||||
if options.config:
|
if options.config:
|
||||||
config = ConfigParser(allow_no_value=True)
|
config = ConfigParser(allow_no_value=True)
|
||||||
config.read(options.config)
|
config.read(options.config)
|
||||||
|
|
||||||
def updater(option, newval): return newval if newval != "" else option
|
# def updater(option, newval): return newval if newval != "" else option
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
options.pushbullet = updater(
|
# options.pushbullet = updater(
|
||||||
options.pushbullet, config.get(
|
# options.pushbullet, config.get(
|
||||||
'runner', 'pushbullet'))
|
# 'runner', 'pushbullet'))
|
||||||
except BaseException:
|
# except BaseException:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
options.pbdevice = updater(
|
# options.pbdevice = updater(
|
||||||
options.pbdevice, config.get(
|
# options.pbdevice, config.get(
|
||||||
'runner', 'pbdevice'))
|
# 'runner', 'pbdevice'))
|
||||||
except BaseException:
|
# except BaseException:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
options.tag = updater(
|
# options.tag = updater(
|
||||||
options.tag, config.getboolean(
|
# options.tag, config.getboolean(
|
||||||
'runner', 'tag'))
|
# 'runner', 'tag'))
|
||||||
except BaseException:
|
# except BaseException:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
options.library = updater(
|
# options.library = updater(
|
||||||
options.library, config.get(
|
# options.library, config.get(
|
||||||
'locations', 'library'))
|
# 'locations', 'library'))
|
||||||
except BaseException:
|
# except BaseException:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
options.library_path = updater(
|
# options.library_path = updater(
|
||||||
options.library, config.get(
|
# options.library, config.get(
|
||||||
'locations', 'library_path'))
|
# 'locations', 'library_path'))
|
||||||
except BaseException:
|
# except BaseException:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
if options.pbdevice and not options.pushbullet:
|
# if options.pbdevice and not options.pushbullet:
|
||||||
raise ValueError("Can't use a pushbullet device without key")
|
# raise ValueError("Can't use a pushbullet device without key")
|
||||||
if options.tag and not options.library:
|
# if options.tag and not options.library:
|
||||||
raise ValueError(
|
# raise ValueError(
|
||||||
"Can't strip tags from calibre library without a library location.")
|
# "Can't strip tags from calibre library without a library location.")
|
||||||
main(options)
|
print(main(config))
|
||||||
|
@ -1,18 +1,3 @@
|
|||||||
[login]
|
|
||||||
user=
|
|
||||||
password=
|
|
||||||
server=
|
|
||||||
mailbox=
|
|
||||||
libuser=
|
|
||||||
libpassword=
|
|
||||||
|
|
||||||
[locations]
|
[locations]
|
||||||
library=
|
output=/output/fanfiction_file
|
||||||
input=/config/fanfiction_file
|
feed=https://archiveofourown.org/tags/80334609/feed.atom
|
||||||
|
|
||||||
[runner]
|
|
||||||
pushbullet=False
|
|
||||||
pbdevice=
|
|
||||||
|
|
||||||
[output]
|
|
||||||
live=False
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,25 @@
|
|||||||
|
https://archiveofourown.org/works/47695222
|
||||||
|
https://archiveofourown.org/works/47693077
|
||||||
|
https://archiveofourown.org/works/47690845
|
||||||
|
https://archiveofourown.org/works/47687437
|
||||||
|
https://archiveofourown.org/works/47687314
|
||||||
|
https://archiveofourown.org/works/47686051
|
||||||
|
https://archiveofourown.org/works/47682619
|
||||||
|
https://archiveofourown.org/works/47677738
|
||||||
|
https://archiveofourown.org/works/47676718
|
||||||
|
https://archiveofourown.org/works/47675752
|
||||||
|
https://archiveofourown.org/works/47668351
|
||||||
|
https://archiveofourown.org/works/47664049
|
||||||
|
https://archiveofourown.org/works/47663485
|
||||||
|
https://archiveofourown.org/works/47662927
|
||||||
|
https://archiveofourown.org/works/47662135
|
||||||
|
https://archiveofourown.org/works/47659663
|
||||||
|
https://archiveofourown.org/works/47655937
|
||||||
|
https://archiveofourown.org/works/47654830
|
||||||
|
https://archiveofourown.org/works/47653144
|
||||||
|
https://archiveofourown.org/works/47652034
|
||||||
|
https://archiveofourown.org/works/47650858
|
||||||
|
https://archiveofourown.org/works/47650072
|
||||||
|
https://archiveofourown.org/works/47649337
|
||||||
|
https://archiveofourown.org/works/47647927
|
||||||
|
https://archiveofourown.org/works/47640946
|
@ -1,140 +0,0 @@
|
|||||||
## This is an example of what your personal configuration might look
|
|
||||||
## like. Uncomment options by removing the '#' in front of them.
|
|
||||||
|
|
||||||
[defaults]
|
|
||||||
## [defaults] section applies to all formats and sites but may be
|
|
||||||
## overridden at several levels. Example:
|
|
||||||
|
|
||||||
## [defaults]
|
|
||||||
## titlepage_entries: category,genre, status
|
|
||||||
## [www.whofic.com]
|
|
||||||
## # overrides defaults.
|
|
||||||
## titlepage_entries: category,genre, status,dateUpdated,rating
|
|
||||||
## [epub]
|
|
||||||
## # overrides defaults & site section
|
|
||||||
## titlepage_entries: category,genre, status,datePublished,dateUpdated,dateCreated
|
|
||||||
## [www.whofic.com:epub]
|
|
||||||
## # overrides defaults, site section & format section
|
|
||||||
## titlepage_entries: category,genre, status,datePublished
|
|
||||||
## [overrides]
|
|
||||||
## # overrides all other sections
|
|
||||||
## titlepage_entries: category
|
|
||||||
|
|
||||||
## Some sites also require the user to confirm they are adult for
|
|
||||||
## adult content. Uncomment by removing '#' in front of is_adult.
|
|
||||||
is_adult:true
|
|
||||||
|
|
||||||
## Don't like the numbers at the start of chapter titles on some
|
|
||||||
## sites? You can use strip_chapter_numbers to strip them off. Just
|
|
||||||
## want to make them all look the same? Strip them off, then add them
|
|
||||||
## back on with add_chapter_numbers. Don't like the way it strips
|
|
||||||
## numbers or adds them back? See chapter_title_strip_pattern and
|
|
||||||
## chapter_title_add_pattern.
|
|
||||||
#strip_chapter_numbers:true
|
|
||||||
#add_chapter_numbers:true
|
|
||||||
|
|
||||||
## Add this to genre if there's more than one category.
|
|
||||||
#add_genre_when_multi_category: Crossover
|
|
||||||
|
|
||||||
[epub]
|
|
||||||
## include images from img tags in the body and summary of stories.
|
|
||||||
## Images will be converted to jpg for size if possible. Images work
|
|
||||||
## in epub format only. To get mobi or other format with images,
|
|
||||||
## download as epub and use Calibre to convert.
|
|
||||||
include_images:true
|
|
||||||
|
|
||||||
## If not set, the summary will have all html stripped for safety.
|
|
||||||
## Both this and include_images must be true to get images in the
|
|
||||||
## summary.
|
|
||||||
#keep_summary_html:true
|
|
||||||
|
|
||||||
## If set, the first image found will be made the cover image. If
|
|
||||||
## keep_summary_html is true, any images in summary will be before any
|
|
||||||
## in chapters.
|
|
||||||
make_firstimage_cover:true
|
|
||||||
|
|
||||||
## Resize images down to width, height, preserving aspect ratio.
|
|
||||||
## Nook size, with margin.
|
|
||||||
#image_max_size: 580, 725
|
|
||||||
|
|
||||||
## Change image to grayscale, if graphics library allows, to save
|
|
||||||
## space.
|
|
||||||
#grayscale_images: false
|
|
||||||
|
|
||||||
|
|
||||||
## Most common, I expect will be using this to save username/passwords
|
|
||||||
## for different sites. Here are a few examples. See defaults.ini
|
|
||||||
## for the full list.
|
|
||||||
|
|
||||||
[www.twilighted.net]
|
|
||||||
#username:YourPenname
|
|
||||||
#password:YourPassword
|
|
||||||
## default is false
|
|
||||||
#collect_series: true
|
|
||||||
|
|
||||||
[ficwad.com]
|
|
||||||
#username:YourUsername
|
|
||||||
#password:YourPassword
|
|
||||||
|
|
||||||
[www.adastrafanfic.com]
|
|
||||||
## Some sites do not require a login, but do require the user to
|
|
||||||
## confirm they are adult for adult content.
|
|
||||||
#is_adult:true
|
|
||||||
|
|
||||||
[www.fictionalley.org]
|
|
||||||
#is_adult:true
|
|
||||||
|
|
||||||
[www.harrypotterfanfiction.com]
|
|
||||||
#is_adult:true
|
|
||||||
|
|
||||||
[www.fimfiction.net]
|
|
||||||
#is_adult:true
|
|
||||||
#fail_on_password: false
|
|
||||||
|
|
||||||
[www.tthfanfic.org]
|
|
||||||
#is_adult:true
|
|
||||||
## tth is a little unusual--it doesn't require user/pass, but the site
|
|
||||||
## keeps track of which chapters you've read and won't send another
|
|
||||||
## update until it thinks you're up to date. This way, on download,
|
|
||||||
## it thinks you're up to date.
|
|
||||||
#username:YourName
|
|
||||||
#password:yourpassword
|
|
||||||
|
|
||||||
[www.fanfiction.net]
|
|
||||||
check_next_chapter:true
|
|
||||||
skip_author_cover:false
|
|
||||||
user_agent:Mozilla/5.0
|
|
||||||
continue_on_chapter_error:false
|
|
||||||
# for use with the workaround
|
|
||||||
#use_nsapa_proxy:true
|
|
||||||
#use_cloudscraper:false
|
|
||||||
use_flaresolverr_proxy:true
|
|
||||||
# option settings, these are the defaults:
|
|
||||||
flaresolverr_proxy_address:localhost
|
|
||||||
flaresolverr_proxy_port:8191
|
|
||||||
flaresolverr_proxy_protocol:http
|
|
||||||
|
|
||||||
## This option if uncommented, will put a box around the spoiler
|
|
||||||
## blocks with the original spoiler button text as a label using
|
|
||||||
## fieldset and legend HTML tags. For a simple box, see the
|
|
||||||
## add_to_output_css example for [base_xenforoforum:epub].
|
|
||||||
#legend_spoilers:true
|
|
||||||
|
|
||||||
|
|
||||||
## This section will override anything in the system defaults or other
|
|
||||||
## sections here.
|
|
||||||
[overrides]
|
|
||||||
## default varies by site. Set true here to force all sites to
|
|
||||||
## collect series.
|
|
||||||
#collect_series: true
|
|
||||||
|
|
||||||
# Change oneshot to ['Completed'] to ['Completed','Oneshot'] only when
|
|
||||||
# numChapters is exactly 1.
|
|
||||||
# with ',' instead of '\,' it would be ['Completed'] to
|
|
||||||
# ['Completed,Oneshot']--one string instead of two.
|
|
||||||
add_to_replace_metadata:
|
|
||||||
oneshot=>Completed=>Completed\,Oneshot&&numChapters=>^1$
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -6,20 +6,20 @@ then
|
|||||||
cp /config.default/config.ini /config/
|
cp /config.default/config.ini /config/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -f "/config/defaults.ini" ]
|
# if ! [ -f "/config/defaults.ini" ]
|
||||||
then
|
# then
|
||||||
echo "[default-confs] restoring default 'defaults.ini'."
|
# echo "[default-confs] restoring default 'defaults.ini'."
|
||||||
cp /config.default/defaults.ini /config/
|
# cp /config.default/defaults.ini /config/
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
if ! [ -f "/config/personal.ini" ]
|
# if ! [ -f "/config/personal.ini" ]
|
||||||
then
|
# then
|
||||||
echo "[default-confs] restoring default 'personal.ini'."
|
# echo "[default-confs] restoring default 'personal.ini'."
|
||||||
cp /config.default/personal.ini /config/
|
# cp /config.default/personal.ini /config/
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
if ! [ -f "/config/fanfiction_file" ]
|
# if ! [ -f "/config/fanfiction_file" ]
|
||||||
then
|
# then
|
||||||
echo "[default-confs] restoring default 'fanfiction_file'."
|
# echo "[default-confs] restoring default 'fanfiction_file'."
|
||||||
cp /config.default/fanfiction_file /config/
|
# cp /config.default/fanfiction_file /config/
|
||||||
fi
|
# fi
|
@ -7,5 +7,5 @@ User uid: $(id -u abc)
|
|||||||
User gid: $(id -g abc)
|
User gid: $(id -g abc)
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
Image Made By: MrTyton
|
Image Made By: Sam
|
||||||
"
|
"
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/with-contenv bash
|
#!/usr/bin/with-contenv bash
|
||||||
|
|
||||||
sleep 30s
|
|
||||||
exec s6-setuidgid abc /app/run.sh
|
exec s6-setuidgid abc /app/run.sh
|
||||||
|
sleep 1800s
|
Loading…
Reference in New Issue
Block a user