mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Create sub directories based on metadata when sending books to devices that support sub directories
This commit is contained in:
commit
9883f60ca5
@ -73,11 +73,20 @@ class CYBOOKG3(USBMS):
|
|||||||
if self.SUPPORTS_SUB_DIRS:
|
if self.SUPPORTS_SUB_DIRS:
|
||||||
if 'tags' in mdata.keys():
|
if 'tags' in mdata.keys():
|
||||||
for tag in mdata['tags']:
|
for tag in mdata['tags']:
|
||||||
if tag.startswith('/'):
|
if tag.startswith(('News')):
|
||||||
|
newpath = os.path.join(newpath, 'news')
|
||||||
|
newpath = os.path.join(newpath, mdata.get('title', ''))
|
||||||
|
newpath = os.path.join(newpath, mdata.get('timestamp', ''))
|
||||||
|
elif tag.startswith('/'):
|
||||||
|
newpath = path
|
||||||
newpath += tag
|
newpath += tag
|
||||||
newpath = os.path.normpath(newpath)
|
newpath = os.path.normpath(newpath)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if newpath == path:
|
||||||
|
newpath = os.path.join(newpath, mdata.get('authors', ''))
|
||||||
|
newpath = os.path.join(newpath, mdata.get('title', ''))
|
||||||
|
|
||||||
if not os.path.exists(newpath):
|
if not os.path.exists(newpath):
|
||||||
os.makedirs(newpath)
|
os.makedirs(newpath)
|
||||||
|
|
||||||
|
@ -103,11 +103,21 @@ class USBMS(Device):
|
|||||||
|
|
||||||
if 'tags' in mdata.keys():
|
if 'tags' in mdata.keys():
|
||||||
for tag in mdata['tags']:
|
for tag in mdata['tags']:
|
||||||
if tag.startswith('/'):
|
if tag.startswith(_('News')):
|
||||||
|
newpath = os.path.join(newpath, 'news')
|
||||||
|
newpath = os.path.join(newpath, mdata.get('title', ''))
|
||||||
|
newpath = os.path.join(newpath, mdata.get('timestamp', ''))
|
||||||
|
break
|
||||||
|
elif tag.startswith('/'):
|
||||||
|
newpath = path
|
||||||
newpath += tag
|
newpath += tag
|
||||||
newpath = os.path.normpath(newpath)
|
newpath = os.path.normpath(newpath)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if newpath == path:
|
||||||
|
newpath = os.path.join(newpath, mdata.get('authors', ''))
|
||||||
|
newpath = os.path.join(newpath, mdata.get('title', ''))
|
||||||
|
|
||||||
if not os.path.exists(newpath):
|
if not os.path.exists(newpath):
|
||||||
os.makedirs(newpath)
|
os.makedirs(newpath)
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ def set_metadata(stream, mi):
|
|||||||
stream.seek(0)
|
stream.seek(0)
|
||||||
|
|
||||||
def get_cover(stream):
|
def get_cover(stream):
|
||||||
|
data = StringIO.StringIO()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pdf = PdfFileReader(stream)
|
pdf = PdfFileReader(stream)
|
||||||
output = PdfFileWriter()
|
output = PdfFileWriter()
|
||||||
@ -88,13 +90,13 @@ def get_cover(stream):
|
|||||||
|
|
||||||
img = Image.open('%s.jpg' % cover_path)
|
img = Image.open('%s.jpg' % cover_path)
|
||||||
|
|
||||||
data = StringIO.StringIO()
|
|
||||||
img.save(data, 'JPEG')
|
img.save(data, 'JPEG')
|
||||||
return data.getvalue()
|
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
return data.getvalue()
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
p = get_parser('pdf')
|
p = get_parser('pdf')
|
||||||
p.remove_option('--category')
|
p.remove_option('--category')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user