Skip to content

Commit

Permalink
AutoAdd directory for magazines
Browse files Browse the repository at this point in the history
  • Loading branch information
philborman committed Dec 21, 2017
1 parent 139d5e1 commit 8a47995
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
20 changes: 19 additions & 1 deletion data/interfaces/bookstrap/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ <h1>${title}</h1>
</fieldset>
<fieldset>
<div class="form-group">
<label for="imp_autoadd">Calibre Auto Add Directory:</label>
<label for="imp_autoadd">Calibre Books Auto Add Directory:</label>
<input type="text" id="imp_autoadd" name="imp_autoadd" value="${lazylibrarian.CONFIG['IMP_AUTOADD']}" class="form-control">
<span class="help-block">Directory for a copy to be placed for auto add process</span>
</div>
Expand All @@ -1393,6 +1393,24 @@ <h1>${title}</h1>
Only add eBook, not opf or jpg</label>
</div>
</fieldset>
<fieldset>
<div class="form-group">
<label for="imp_autoadd">Calibre Magazines Auto Add Directory:</label>
<input type="text" id="imp_autoaddmag" name="imp_autoaddmag" value="${lazylibrarian.CONFIG['IMP_AUTOADDMAG']}" class="form-control">
<span class="help-block">Directory for a copy to be placed for auto add process</span>
</div>
<div class="checkbox">
<%
if lazylibrarian.CONFIG['IMP_AUTOADD_MAGONLY'] == True:
checked = 'checked="checked"'
else:
checked = ''
%>
<label for="imp_autoadd_magonly">
<input type="checkbox" id="imp_autoadd_magonly" name="imp_autoadd_magonly" value="1" ${checked} />
Only add magazine, not opf or jpg</label>
</div>
</fieldset>
</div>
<div class="col-md-4">
<fieldset>
Expand Down
5 changes: 4 additions & 1 deletion lazylibrarian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
'REJECT_MAXAUDIO', 'REJECT_MINAUDIO', 'NEWAUDIO_STATUS', 'TOGGLES', 'AUDIO_TAB',
'USER_ACCOUNTS', 'GR_SYNC', 'GR_SECRET', 'GR_OAUTH_TOKEN', 'GR_OAUTH_SECRET',
'GR_OWNED', 'GR_WANTED', 'GR_UNIQUE', 'GR_FOLLOW', 'GR_FOLLOWNEW', 'GOODREADS_INTERVAL',
'AUDIOBOOK_DEST_FILE', 'SINGLE_USER', 'FMT_SERNAME', 'FMT_SERNUM', 'FMT_SERIES']
'AUDIOBOOK_DEST_FILE', 'SINGLE_USER', 'FMT_SERNAME', 'FMT_SERNUM', 'FMT_SERIES',
'AUTOADDMAG', 'AUTOADD_MAGONLY']
CONFIG_DEFINITIONS = {
# Name Type Section Default
'USER_ACCOUNTS': ('bool', 'General', 0),
Expand Down Expand Up @@ -207,6 +208,8 @@
'IMP_MONTHLANG': ('str', 'General', ''),
'IMP_AUTOADD': ('str', 'General', ''),
'IMP_AUTOADD_BOOKONLY': ('bool', 'General', 0),
'IMP_AUTOADDMAG': ('str', 'General', ''),
'IMP_AUTOADD_MAGONLY': ('bool', 'General', 0),
'IMP_AUTOSEARCH': ('bool', 'General', 0),
'IMP_CALIBREDB': ('str', 'General', ''),
'CALIBRE_USE_SERVER': ('bool', 'General', 0),
Expand Down
22 changes: 16 additions & 6 deletions lazylibrarian/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,9 @@ def processDir(reset=False):
# create a thumbnail cover for the new issue
create_cover(dest_file)
processMAGOPF(dest_file, book['BookID'], book['AuxInfo'], iss_id)
if lazylibrarian.CONFIG['IMP_AUTOADDMAG']:
dest_path = os.path.dirname(dest_file)
processAutoAdd(dest_path, booktype='mag')

# calibre or ll copied/moved the files we want, now delete source files

Expand Down Expand Up @@ -1028,7 +1031,7 @@ def processExtras(dest_file=None, global_name=None, bookid=None, book_type="eBoo
if match:
update_totals(match['AuthorID'])

if book_type != 'eBook': # only do autoadd/img/opf for ebooks
elif book_type != 'eBook': # only do autoadd/img/opf for ebooks
return

cmd = 'SELECT AuthorName,BookID,BookName,BookDesc,BookIsbn,BookImg,BookDate,BookLang,BookPub'
Expand Down Expand Up @@ -1335,15 +1338,18 @@ def processDestination(pp_path=None, dest_path=None, authorname=None, bookname=N
return True, newbookfile


def processAutoAdd(src_path=None):
def processAutoAdd(src_path=None, booktype='book'):
# Called to copy/move the book files to an auto add directory for the likes of Calibre which can't do nested dirs
# ensure directory is unicode so we get unicode results from listdir
if isinstance(src_path, str) and hasattr(src_path, "decode"):
src_path = src_path.decode(lazylibrarian.SYS_ENCODING)
autoadddir = lazylibrarian.CONFIG['IMP_AUTOADD']
if booktype == 'mag':
autoadddir = lazylibrarian.CONFIG['IMP_AUTOADDMAG']

if not os.path.exists(autoadddir):
logger.error('AutoAdd directory [%s] is missing or not set - cannot perform autoadd' % autoadddir)
logger.error('AutoAdd directory for %s [%s] is missing or not set - cannot perform autoadd' % (
booktype, autoadddir))
return False
# Now try and copy all the book files into a single dir.
try:
Expand All @@ -1357,7 +1363,7 @@ def processAutoAdd(src_path=None):
# ignores author/title data in opf file if there is any embedded in book

match = False
if lazylibrarian.CONFIG['ONE_FORMAT']:
if booktype == 'book' and lazylibrarian.CONFIG['ONE_FORMAT']:
booktype_list = getList(lazylibrarian.CONFIG['EBOOK_TYPE'])
for booktype in booktype_list:
while not match:
Expand All @@ -1368,9 +1374,13 @@ def processAutoAdd(src_path=None):
break
copied = False
for name in names:
if match and is_valid_booktype(name, booktype="book") and not name.endswith(match):
if match and is_valid_booktype(name, booktype=booktype) and not name.endswith(match):
logger.debug('Skipping %s' % os.path.splitext(name)[1])
elif lazylibrarian.CONFIG['IMP_AUTOADD_BOOKONLY'] and not is_valid_booktype(name, booktype="book"):
elif booktype == 'book' and lazylibrarian.CONFIG['IMP_AUTOADD_BOOKONLY'] and not \
is_valid_booktype(name, booktype="book"):
logger.debug('Skipping %s' % name)
elif booktype == 'mag' and lazylibrarian.CONFIG['IMP_AUTOADD_MAGONLY'] and not \
is_valid_booktype(name, booktype="mag"):
logger.debug('Skipping %s' % name)
else:
srcname = os.path.join(src_path, name)
Expand Down

0 comments on commit 8a47995

Please sign in to comment.