Forces duplicate option. We're only searching by URL and removing by that as well, whereas calibredb uses the title of the story in order to search and update.

master
MrTyton 8 years ago
parent 8794f68bdf
commit 85bad22ff6

@ -1,7 +1,7 @@
from fanficfare import geturls from fanficfare import geturls
from os import listdir, remove, rename, utime, errno, devnull from os import listdir, remove, rename, utime, errno, devnull
from os.path import isfile, join from os.path import isfile, join
from subprocess import check_output, STDOUT, call from subprocess import check_output, STDOUT, call,PIPE
import logging import logging
from optparse import OptionParser from optparse import OptionParser
import re import re
@ -24,6 +24,7 @@ equal_chapters = re.compile('.* already contains \d* chapters.')
chapter_difference = re.compile('.* contains \d* chapters, more than source: \d*.') 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.") 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.') 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): def parse_url(url):
@ -86,11 +87,11 @@ def main(user, password, server, label, inout_file, path ):
try: try:
if path: if path:
try: try:
res = check_output('calibredb search "Identifiers:{}" {}'.format(url, path), shell=True,stderr=STDOUT) res = check_output('calibredb search "Identifiers:{}" {}'.format(url, path), shell=True,stderr=STDOUT,stdin=PIPE, )
storyId = res storyId = res
print "\tStory is in calibre with id {}".format(storyId) print "\tStory is in calibre with id {}".format(storyId)
print "\tExporting file" print "\tExporting file"
res = check_output('calibredb export {} --dont-save-cover --dont-write-opf --single-dir --to-dir "{}" {}'.format(storyId, loc, path), shell=True) 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)
cur = get_files(loc, ".epub", True)[0] cur = get_files(loc, ".epub", True)[0]
print '\tDownloading with fanficfare, updating file "{}"'.format(cur) print '\tDownloading with fanficfare, updating file "{}"'.format(cur)
moving="" moving=""
@ -98,29 +99,27 @@ def main(user, password, server, label, inout_file, path ):
#story is not in calibre #story is not in calibre
cur = url cur = url
moving = 'cd "{}" && '.format(loc) moving = 'cd "{}" && '.format(loc)
print '{}fanficfare -u "{}" --update-cover'.format(moving, cur)
res = check_output('{}fanficfare -u "{}" --update-cover'.format(moving, cur), shell=True,stderr=STDOUT) res = check_output('{}fanficfare -u "{}" --update-cover'.format(moving, cur), shell=True,stderr=STDOUT,stdin=PIPE, )
check_regexes(res) check_regexes(res)
if chapter_difference.search(res) or more_chapters.search(res):
if chapter_difference.search(res):
print "\tForcing download update\n" print "\tForcing download update\n"
res = check_output('{}fanficfare -u "{}" --force --update-cover'.format(moving, cur), shell=True,stderr=STDOUT) res = check_output('{}fanficfare -u "{}" --force --update-cover'.format(moving, cur), shell=True,stderr=STDOUT,stdin=PIPE, )
check_regexes(res) check_regexes(res)
cur = get_files(loc, '.epub', True)[0] cur = get_files(loc, '.epub', True)[0]
if storyId: if storyId:
print "\tRemoving {} from library".format(storyId) print "\tRemoving {} from library".format(storyId)
res = check_output('calibredb remove {} {}'.format(storyId, path), shell=True,stderr=STDOUT) res = check_output('calibredb remove {} {}'.format(storyId, path), shell=True,stderr=STDOUT,stdin=PIPE, )
print "\tAdding {} to library".format(cur) print "\tAdding {} to library".format(cur)
res = check_output('calibredb add "{}" {}'.format(cur, path), shell=True,stderr=STDOUT) res = check_output('calibredb add "{}" -d {}'.format(cur, path), shell=True,stderr=STDOUT,stdin=PIPE, )
res = check_output('calibredb search "Identifiers:{}" {}'.format(url, path), shell=True, stderr=STDOUT) res = check_output('calibredb search "Identifiers:{}" {}'.format(url, path), shell=True, stderr=STDOUT,stdin=PIPE, )
print "\tAdded {} to library with id {}".format(cur, res) print "\tAdded {} to library with id {}".format(cur, res)
remove(cur) remove(cur)
else: else:
res = check_output('cd "{}" && fanficfare -u "{}" --update-cover'.format(loc, url), shell=True,stderr=STDOUT) res = check_output('cd "{}" && fanficfare -u "{}" --update-cover'.format(loc, url), shell=True,stderr=STDOUT,stdin=PIPE, )
check_regexes(res) check_regexes(res)
cur = get_files(loc, '.epub', True)[0] cur = get_files(loc, '.epub', True)[0]
name = get_files(loc, '.epub', False)[0] name = get_files(loc, '.epub', False)[0]

Loading…
Cancel
Save