# Path: modules/mobi_split.py
# class mobi_read:
#     def __init__(self, infile, width=330, height=470, stretch=False):
# 
#         self.asin = ''
#         self.cdetype = 'PDOC'
#         self.cdecontentkey = ''
#         self.acr = ''
#         self.thumbnail = None
#         self.pagedata = b''
# 
#         datain = b''
#         with open(pathof(infile), 'rb') as f:
#             self.acr = re.sub('[^-A-Za-z0-9 ]+', '_', f.read(32).replace(b'\x00', b'').decode('latin-1'))
#             f.seek(0)
#             datain = f.read()
# 
#         datain_rec0 = readsection(datain, 0)
# 
#         exth121 = read_exth(datain_rec0, 121)
#         self.combo = True
#         if len(exth121) == 0:
#             self.combo = False
#         else:
#             # only pay attention to first exth121
#             # (there should only be one)
#             datain_kf8, = struct.unpack_from(b'>L', exth121[0], 0)
#             if datain_kf8 == 0xffffffff:
#                 self.combo = False
# 
#         # Look for PageMap
#         srcs = getint(datain_rec0, first_non_text)
#         num_srcs = getint(datain, number_of_pdb_records, b'H')
#         if srcs != 0xffffffff and num_srcs > 0:
#             for i in range(srcs, srcs + num_srcs):
#                 data = readsection(datain, i)
#                 if data[0:4] == b"PAGE":
#                     self.pagedata = data
# 
#         exth = read_exth(datain_rec0, exth_asin)
#         if len(exth) > 0:
#             self.asin = exth[0].decode("ascii")
#         exth = read_exth(datain_rec0, exth_cdetype)
#         if len(exth) > 0:
#             self.cdetype = exth[0].decode("ascii")
#         exth = read_exth(datain_rec0, exth_cdecontentkey)
#         if len(exth) > 0:
#             self.cdecontentkey = exth[0].decode("ascii")
# 
#         firstimage = getint(datain_rec0, first_resc_record)
# 
#         exth_cover = read_exth(datain_rec0, exth_cover_offset)
#         if len(exth_cover) > 0:
#             cover_index, = struct.unpack_from('>L', exth_cover[0], 0)
#             cover_index += firstimage
#         else:
#             cover_index = 0xffffffff
# 
#         exth_thumb = read_exth(datain_rec0, exth_thumb_offset)
#         if len(exth_thumb) > 0:
#             thumb_index, = struct.unpack_from('>L', exth_thumb[0], 0)
#             thumb_index += firstimage
#         else:
#             thumb_index = 0xffffffff
# 
#         if cover_index != 0xffffffff:
#             w, h = 0, 0
#             if thumb_index != 0xffffffff:
#                 image = readsection(datain, thumb_index)
#                 self.thumbnail = Image.open(BytesIO(image))
#                 w, h = self.thumbnail.size
#             if (w < width and h < height) or stretch:
#                 image = readsection(datain, cover_index)
#                 self.thumbnail = Image.open(BytesIO(image))
#                 if stretch:
#                     self.thumbnail = self.thumbnail.resize((width, height), Image.LANCZOS)
#                 else:
#                     self.thumbnail.thumbnail((width, height), Image.LANCZOS)
# 
#         if self.combo:
#             # always try to use information from KF8 part
#             datain_kfrec0 = readsection(datain, datain_kf8)
#             exth = read_exth(datain_kfrec0, exth_asin)
#             if len(exth) > 0:
#                 self.asin = exth[0].decode("ascii")
#             exth = read_exth(datain_kfrec0, exth_cdetype)
#             if len(exth) > 0:
#                 self.cdetype = exth[0].decode("ascii")
#             exth = read_exth(datain_kfrec0, exth_cdecontentkey)
#             if len(exth) > 0:
#                 self.cdecontentkey = exth[0].decode("ascii")
# 
#     def getACR(self):
#         return self.acr
# 
#     def getASIN(self):
#         return self.asin
# 
#     def getCdeType(self):
#         return self.cdetype
# 
#     def getCdeContentKey(self):
#         return self.cdecontentkey
# 
#     def getPageData(self):
#         return self.pagedata
# 
#     def getThumbnail(self):
#         return self.thumbnail


import os
import sys
import traceback
import argparse
import version
from modules.mobi_split import mobi_read
#!/usr/bin/env python3
# -*- coding: utf-8 -*-




count_files = 0
count_located = 0
count_processed = 0


def process_file(infile, kindle_dir, width, height, stretch, verbose):

    global count_files, count_located, count_processed

    count_files += 1
    if not os.path.exists(infile):
        if verbose:
            print('WARNING: File {0} not found'.format(infile))
        return

    count_located += 1
    if verbose:
        print('Processing file {}'.format(infile))
    try:

# Path: modules/mobi_split.py
# class mobi_read:
#     def __init__(self, infile, width=330, height=470, stretch=False):
# 
#         self.asin = ''
#         self.cdetype = 'PDOC'
#         self.cdecontentkey = ''
#         self.acr = ''
#         self.thumbnail = None
#         self.pagedata = b''
# 
#         datain = b''
#         with open(pathof(infile), 'rb') as f:
#             self.acr = re.sub('[^-A-Za-z0-9 ]+', '_', f.read(32).replace(b'\x00', b'').decode('latin-1'))
#             f.seek(0)
#             datain = f.read()
# 
#         datain_rec0 = readsection(datain, 0)
# 
#         exth121 = read_exth(datain_rec0, 121)
#         self.combo = True
#         if len(exth121) == 0:
#             self.combo = False
#         else:
#             # only pay attention to first exth121
#             # (there should only be one)
#             datain_kf8, = struct.unpack_from(b'>L', exth121[0], 0)
#             if datain_kf8 == 0xffffffff:
#                 self.combo = False
# 
#         # Look for PageMap
#         srcs = getint(datain_rec0, first_non_text)
#         num_srcs = getint(datain, number_of_pdb_records, b'H')
#         if srcs != 0xffffffff and num_srcs > 0:
#             for i in range(srcs, srcs + num_srcs):
#                 data = readsection(datain, i)
#                 if data[0:4] == b"PAGE":
#                     self.pagedata = data
# 
#         exth = read_exth(datain_rec0, exth_asin)
#         if len(exth) > 0:
#             self.asin = exth[0].decode("ascii")
#         exth = read_exth(datain_rec0, exth_cdetype)
#         if len(exth) > 0:
#             self.cdetype = exth[0].decode("ascii")
#         exth = read_exth(datain_rec0, exth_cdecontentkey)
#         if len(exth) > 0:
#             self.cdecontentkey = exth[0].decode("ascii")
# 
#         firstimage = getint(datain_rec0, first_resc_record)
# 
#         exth_cover = read_exth(datain_rec0, exth_cover_offset)
#         if len(exth_cover) > 0:
#             cover_index, = struct.unpack_from('>L', exth_cover[0], 0)
#             cover_index += firstimage
#         else:
#             cover_index = 0xffffffff
# 
#         exth_thumb = read_exth(datain_rec0, exth_thumb_offset)
#         if len(exth_thumb) > 0:
#             thumb_index, = struct.unpack_from('>L', exth_thumb[0], 0)
#             thumb_index += firstimage
#         else:
#             thumb_index = 0xffffffff
# 
#         if cover_index != 0xffffffff:
#             w, h = 0, 0
#             if thumb_index != 0xffffffff:
#                 image = readsection(datain, thumb_index)
#                 self.thumbnail = Image.open(BytesIO(image))
#                 w, h = self.thumbnail.size
#             if (w < width and h < height) or stretch:
#                 image = readsection(datain, cover_index)
#                 self.thumbnail = Image.open(BytesIO(image))
#                 if stretch:
#                     self.thumbnail = self.thumbnail.resize((width, height), Image.LANCZOS)
#                 else:
#                     self.thumbnail.thumbnail((width, height), Image.LANCZOS)
# 
#         if self.combo:
#             # always try to use information from KF8 part
#             datain_kfrec0 = readsection(datain, datain_kf8)
#             exth = read_exth(datain_kfrec0, exth_asin)
#             if len(exth) > 0:
#                 self.asin = exth[0].decode("ascii")
#             exth = read_exth(datain_kfrec0, exth_cdetype)
#             if len(exth) > 0:
#                 self.cdetype = exth[0].decode("ascii")
#             exth = read_exth(datain_kfrec0, exth_cdecontentkey)
#             if len(exth) > 0:
#                 self.cdecontentkey = exth[0].decode("ascii")
# 
#     def getACR(self):
#         return self.acr
# 
#     def getASIN(self):
#         return self.asin
# 
#     def getCdeType(self):
#         return self.cdetype
# 
#     def getCdeContentKey(self):
#         return self.cdecontentkey
# 
#     def getPageData(self):
#         return self.pagedata
# 
#     def getThumbnail(self):
#         return self.thumbnail


# Path: synccovers.py
import os
import sys
import traceback
import argparse
import version
from modules.mobi_split import mobi_read

#!/usr/bin/env python3
# -*- coding: utf-8 -*-




count_files = 0
count_located = 0
count_processed = 0


def process_file(infile, kindle_dir, width, height, stretch, verbose):

    global count_files, count_located, count_processed

    count_files += 1
    if not os.path.exists(infile):
        if verbose:
            print('WARNING: File {0} not found'.format(infile))
        return

    count_located += 1
    if verbose:
        print('Processing file {}'.format(infile))
    try:

        reader = mobi_read(infile, width, height, stretch)