Пример #1
0
    def compare( self , comic_filename, comic_compare_filename):
        """
        Compare a comic file
        """

        """
        md = self.getComicMetadata(comic_filename)
        md_compare = self.getComicMetadata(comic_compare_filename)
        if md_compare is not None:
            compare_comic = self.createComicFromMetadata(md_compare)
        if md is not None:
            comic = self.createComicFromMetadata(md)
        if comic is None or compare_comic is None:
            return False
        """

        # preform metadata check....
        # FIX

        fingerprint_compare = ComicArchive(comic_filename,  default_image_path=AppFolders.missingPath("page.png")).fingerprint(sort=False)
        fingerprint = ComicArchive(comic_compare_filename,  default_image_path=AppFolders.missingPath("page.png")).fingerprint(sort=False)

        if fingerprint == fingerprint_compare:
            return True
        return False
Пример #2
0
    def compare(self, comic_filename, comic_compare_filename):
        """
        Compare a comic file
        """
        """
        md = self.getComicMetadata(comic_filename)
        md_compare = self.getComicMetadata(comic_compare_filename)
        if md_compare is not None:
            compare_comic = self.createComicFromMetadata(md_compare)
        if md is not None:
            comic = self.createComicFromMetadata(md)
        if comic is None or compare_comic is None:
            return False
        """

        # preform metadata check....
        # FIX

        fingerprint_compare = ComicArchive(
            comic_filename,
            default_image_path=AppFolders.missingPath("page.png")).fingerprint(
                sort=False)
        fingerprint = ComicArchive(
            comic_compare_filename,
            default_image_path=AppFolders.missingPath("page.png")).fingerprint(
                sort=False)

        if fingerprint == fingerprint_compare:
            return True
        return False
Пример #3
0
    def lastpage_extractor_for_blacklist(self):
        print "Extract Last Pages"
        query = self.getSession.query(Comic)
        x = os.path.join(AppFolders.appBlacklistPages(),"lastpage")
        y = os.path.join(AppFolders.appBlacklistPages(),"lastpage_double")
        z = os.path.join(AppFolders.appBlacklistPages(),"firstpage")
        w = os.path.join(AppFolders.appBlacklistPages(),"firstpage_double")
        if not os.path.isdir(x):
            os.makedirs(x)
        if not os.path.isdir(y):
            os.makedirs(y)
        if not os.path.isdir(z):
            os.makedirs(z)
        if not os.path.isdir(w):
            os.makedirs(w)
        c = 0
        for row in query:
            print('Extracting last page from ' + str(c) + ' '  + row.path)
            c += 1
            ca = self.getComicArchive(row.id,row.path)
            # auto convert webp (disable for chunky or fix web book reader)
            image_data = ca.getPage(row.page_count-1)
            hash = utils.hash(image_data)
            
            # ascept ratio check
            #im = Image.open(StringIO.StringIO(image_data))
            #w,h = im.size
            #if h > w:
            #    continue
            
            
            image_cover = ca.getPage(0)
            image_page2 = ca.getPage(1)
            if image_page2:
                imc = Image.open(StringIO.StringIO(image_cover))
                hash2 = utils.hash(image_cover)
                im2 = Image.open(StringIO.StringIO(image_page2))
                w1,h1 = imc.size
                w2,h2 = im2.size
                if h1 <= w1 and h2 > w2 and not self.checkHashBlacklist(hash2):
                    if os.path.isfile(os.path.join(z,str(hash2))):
                        if os.path.isfile(os.path.join(w,str(hash2))):
                            print "Double Already Exists"
                        else:
                            print "Adding Double"
                            file2 = open(os.path.join(w,str(hash2)), "w")
                            file2.write(image_cover)
                            file2.close()
                    else:
                        print "Adding Firstpage"
                        file2 = open(os.path.join(z,str(hash2)), "w")
                        #file2.write("1")
                        file2.write(image_cover)
                        file2.close()


            
            
                    """
Пример #4
0
    def getComicMetadata(self, path):
        ca = ComicArchive(
            path, default_image_path=AppFolders.missingPath("page.png"))

        if ca.seemsToBeAComicArchive():

            if ca.hasMetadata(MetaDataStyle.CIX):
                style = MetaDataStyle.CIX
            elif ca.hasMetadata(MetaDataStyle.CBI):
                style = MetaDataStyle.CBI
            elif ca.hasMetadata(MetaDataStyle.COMET):
                style = MetaDataStyle.COMET
            elif ca.hasMetadata(MetaDataStyle.CBW):
                style = MetaDataStyle.CBW
            else:
                logging.warning(u"Library: File Has No ComicMeta Data")
                if ca.hasMetadata(MetaDataStyle.CALIBRE):
                    style = MetaDataStyle.CALIBRE
                elif ca.hasMetadata(MetaDataStyle.EPUB):
                    style = MetaDataStyle.EPUB
                else:
                    style = None

            if style is not None:
                md = ca.readMetadata(style)
                if md.isEmpty:
                    md = ca.metadataFromFilename()
            else:
                # No metadata in comic.  make some guesses from the filename
                md = ca.metadataFromFilename()

            # patch version 2
            if (md.title is None or md.title
                    == "") and md.issue is None and not md.series is None:
                md.title = md.series
                md.series = None

            md.fingerprint = ca.fingerprint()
            md.path = ca.path

            md.page_count = ca.page_count

            md.mod_ts = datetime.utcfromtimestamp(getmtime(ca.path))
            md.filesize = os.path.getsize(md.path)
            md.hash = ""

            #thumbnail generation
            image_data = ca.getPage(0, AppFolders.missingPath("cover.png"))

            #now resize it
            thumb = StringIO.StringIO()

            try:
                utils.resize(image_data, (400, 400), thumb)
                md.thumbnail = thumb.getvalue()
            except:
                md.thumbnail = None
            return md
        return None
Пример #5
0
    def getComicMetadata(self, path):
        ca = ComicArchive(path,  default_image_path=AppFolders.missingPath("page.png"))

        
        if ca.seemsToBeAComicArchive():

            if ca.hasMetadata( MetaDataStyle.CIX ):
                style = MetaDataStyle.CIX
            elif ca.hasMetadata( MetaDataStyle.CBI ):
                style = MetaDataStyle.CBI
            elif ca.hasMetadata( MetaDataStyle.COMET ):
                style = MetaDataStyle.COMET
            elif ca.hasMetadata( MetaDataStyle.CBW ):
                style = MetaDataStyle.CBW
            else:
                logging.warning(u"Library: File Has No ComicMeta Data")
                if ca.hasMetadata( MetaDataStyle.CALIBRE ):
                    style = MetaDataStyle.CALIBRE
                elif ca.hasMetadata( MetaDataStyle.EPUB ):
                    style = MetaDataStyle.EPUB
                else:
                    style = None
                
            if style is not None:
                md = ca.readMetadata(style)
                if md.isEmpty:
                     md = ca.metadataFromFilename()
            else:
                # No metadata in comic.  make some guesses from the filename
                md = ca.metadataFromFilename()
            
            # patch version 2
            if (md.title is None or md.title == "") and md.issue is None and not md.series is None:
                md.title = md.series
                md.series = None
            
            md.fingerprint = ca.fingerprint()
            md.path = ca.path
            
            md.page_count = ca.page_count
            
            md.mod_ts = datetime.utcfromtimestamp(getmtime(ca.path))
            md.filesize = os.path.getsize(md.path)
            md.hash = ""

            #thumbnail generation
            image_data = ca.getPage(0, AppFolders.missingPath("cover.png"))
            
            #now resize it
            thumb = StringIO.StringIO()
            
            try:
                utils.resize(image_data, (400, 400), thumb)
                md.thumbnail = thumb.getvalue()
            except:
                md.thumbnail = None
            return md
        return None
Пример #6
0
    def lastpage_extractor_for_blacklist(self):
        print "Extract Last Pages"
        query = self.getSession.query(Comic)
        x = os.path.join(AppFolders.appBlacklistPages(), "lastpage")
        y = os.path.join(AppFolders.appBlacklistPages(), "lastpage_double")
        z = os.path.join(AppFolders.appBlacklistPages(), "firstpage")
        w = os.path.join(AppFolders.appBlacklistPages(), "firstpage_double")
        if not os.path.isdir(x):
            os.makedirs(x)
        if not os.path.isdir(y):
            os.makedirs(y)
        if not os.path.isdir(z):
            os.makedirs(z)
        if not os.path.isdir(w):
            os.makedirs(w)
        c = 0
        for row in query:
            print('Extracting last page from ' + str(c) + ' ' + row.path)
            c += 1
            ca = self.getComicArchive(row.id, row.path)
            # auto convert webp (disable for chunky or fix web book reader)
            image_data = ca.getPage(row.page_count - 1)
            hash = utils.hash(image_data)

            # ascept ratio check
            #im = Image.open(StringIO.StringIO(image_data))
            #w,h = im.size
            #if h > w:
            #    continue

            image_cover = ca.getPage(0)
            image_page2 = ca.getPage(1)
            if image_page2:
                imc = Image.open(StringIO.StringIO(image_cover))
                hash2 = utils.hash(image_cover)
                im2 = Image.open(StringIO.StringIO(image_page2))
                w1, h1 = imc.size
                w2, h2 = im2.size
                if h1 <= w1 and h2 > w2 and not self.checkHashBlacklist(hash2):
                    if os.path.isfile(os.path.join(z, str(hash2))):
                        if os.path.isfile(os.path.join(w, str(hash2))):
                            print "Double Already Exists"
                        else:
                            print "Adding Double"
                            file2 = open(os.path.join(w, str(hash2)), "w")
                            file2.write(image_cover)
                            file2.close()
                    else:
                        print "Adding Firstpage"
                        file2 = open(os.path.join(z, str(hash2)), "w")
                        #file2.write("1")
                        file2.write(image_cover)
                        file2.close()
                    """
Пример #7
0
    def getComicPage(self, comic_id, page_number, max_height = None):
        (path, page_count) = self.getSession().query(Comic.path, Comic.page_count) \
                                 .filter(Comic.id == int(comic_id)).first()

        image_data = None
        default_img_file = AppFolders.imagePath("default.jpg")

        if path is not None:
            if int(page_number) < page_count:
                ca = self.getComicArchive(path)
                image_data = ca.getPage(int(page_number))

        if image_data is None:
            with open(default_img_file, 'rb') as fd:
                image_data = fd.read()
            return image_data

        # resize image
        if max_height is not None:
            try:
                image_data = utils.resizeImage(int(max_height), image_data)
            except Exception as e:
                #logging.error(e)
                pass
        return image_data
Пример #8
0
    def getComicPage(self, comic_id, page_number, cache=True, max_height=None):
        (path, page_count) = self.getSession().query(Comic.path, Comic.page_count) \
                                 .filter(Comic.id == int(comic_id)).first()

        image_data = None
        default_img_file = AppFolders.missingPath("page.png")

        if path is not None:
            if int(page_number) < page_count:
                if cache:
                    image_data = self.cache_load(comic_id, page_number, path)
                else:
                    ca = self.getComicArchive(comic_id, path)
                    # auto convert webp (disable for chunky or fix web book reader)
                    image_data = utils.webp_patch_convert(
                        self.isBlacklist(ca.getPage(int(page_number))))

        if image_data is None:
            with open(default_img_file, 'rb') as fd:
                image_data = fd.read()
            return image_data

        # resize image
        if max_height is not None:
            try:
                image_data = utils.resizeImage(int(max_height), image_data)
            except Exception as e:
                #logging.error(e)
                pass

        return image_data
Пример #9
0
    def comicBlacklist(self,comic_id, pagenum):
        #obj = session.query(database.Blacklist).filter(database.Blacklist.comic_id == int(comic_id),database.Blacklist.page == int(pagenum)).first()
         #       if obj is None:
        
        session = self.getSession()
        
        #self.getComic()
        #x = self.getSession().query(Comic.id, Comic.path, Comic.mod_ts)

        image_data = self.getComicPage(comic_id, pagenum, False)
        hash = utils.hash(image_data)

        #comichash = self.getHashEntity(Blacklist, hash)
        #self.getComic(comic_id).blacklist(comichash)
        
        obj = self.getSession().query(Blacklist.hash).filter(Blacklist.hash == hash).first()
        if obj is None:
            try:
                blacklist = Blacklist()
                blacklist.hash = hash
                blacklist.detect = len(image_data)
                
                file = open(os.path.join(AppFolders.appBlacklistPages(),str(blacklist.hash)), "w")
                file.write(image_data)
                file.close()
                
                #blacklist.comic_id = int(comic_id)
                #blacklist.page = int(pagenum)
                blacklist.ts = datetime.datetime.utcnow()
                session.add(blacklist)
                session.commit()
                session.close()
            except Exception, e:
                print str(e)
                logging.error("Blacklist: Problem blocking page {} on comic {}".format(pagenum, comic_id))
Пример #10
0
    def getComicPage(self, comic_id, page_number, cache = True, max_height = None):
        (path, page_count) = self.getSession().query(Comic.path, Comic.page_count) \
                                 .filter(Comic.id == int(comic_id)).first()

        image_data = None
        default_img_file = AppFolders.missingPath("page.png")
        
        if path is not None:
            if int(page_number) < page_count:
                if cache:
                    image_data = self.cache_load(comic_id,page_number,path)
                else:
                    ca = self.getComicArchive(comic_id,path)
                    # auto convert webp (disable for chunky or fix web book reader)
                    image_data = utils.webp_patch_convert(self.isBlacklist(ca.getPage(int(page_number))))
                    
        if image_data is None:
            with open(default_img_file, 'rb') as fd:
                image_data = fd.read()
            return image_data

        # resize image
        if max_height is not None:
            try:
                image_data = utils.resizeImage(int(max_height), image_data)
            except Exception as e:
                #logging.error(e)
                pass
                
        return image_data
Пример #11
0
    def getComicPage(self, comic_id, page_number, max_height=None):
        (path, page_count) = self.getSession().query(Comic.path, Comic.page_count) \
                                 .filter(Comic.id == int(comic_id)).first()

        image_data = None
        default_img_file = AppFolders.imagePath("default.jpg")

        if path is not None:
            if int(page_number) < page_count:
                ca = self.getComicArchive(path)
                image_data = ca.getPage(int(page_number))

        if image_data is None:
            with open(default_img_file, 'rb') as fd:
                image_data = fd.read()
            return image_data

        # resize image
        if max_height is not None:
            try:
                image_data = utils.resizeImage(int(max_height), image_data)
            except Exception as e:
                #logging.error(e)
                pass
        return image_data
Пример #12
0
    def getComicThumbnail(self, comic_fingerprint):

        filename = comic_fingerprint + ".png"
        foldername = filename[0]
        folderpath = AppFolders.appThumbPath(foldername, filename)
        with open(folderpath, 'rb') as fd:
            thumbnail = fd.read()
            self.write(thumbnail.getvalue())
Пример #13
0
 def createBlacklistFromFolder(self, file):
     # loop over files in blacklist folder
     # and save them to a file with \n seperated
     # untested
     for root, dirs, filenames in os.walk(AppFolders.appBlacklistPages()):
         for f in filenames:
             with open(file) as f:
                 f.write(str(f) + str(os.stat(file).st_size) + '\n')
Пример #14
0
 def createBlacklistFromFolder(self,file):
     # loop over files in blacklist folder
     # and save them to a file with \n seperated
     # untested
     for root, dirs, filenames in os.walk(AppFolders.appBlacklistPages()):
         for f in filenames:
             with open(file) as f:
                 f.write(str(f)+str(os.stat(file).st_size)+'\n')
Пример #15
0
    def __init__(self):
        super(ComicStreamerConfig, self).__init__()

        self.csfolder = AppFolders.settings()

        # make sure folder exisits
        if not os.path.exists(self.csfolder):
            os.makedirs(self.csfolder)

        # set up initial values
        self.filename = os.path.join(self.csfolder, "comicstreamer")
        if platform.system() == "Windows":
            self.filename += ".ini"
        else:  #if platform.system() == "Darwin":
            self.filename += ".conf"

        self.configspec = io.StringIO(ComicStreamerConfig.configspec)
        self.encoding = "UTF8"

        # since some stuff in the configobj has to happen during object initialization,
        # use a temporary delegate,  and them merge it into self
        tmp = ConfigObj(self.filename,
                        configspec=self.configspec,
                        encoding=self.encoding)
        validator = Validator()
        tmp.validate(validator, copy=True)

        if tmp['format.ebook']['calibre'] == '':
            if platform.system() == "Darwin":
                calibre = '/Applications/calibre.app/Contents/MacOS/ebook-convert'
                if os.path.isfile(calibre):
                    tmp['format.ebook']['calibre'] = calibre

        # set up the install ID
        if tmp['general']['install_id'] == '':
            tmp['general']['install_id'] = uuid.uuid4().hex

        #set up the cookie secret
        if tmp['security']['cookie_secret'] == '':
            tmp['security']['cookie_secret'] = base64.b64encode(
                uuid.uuid4().bytes + uuid.uuid4().bytes)

        # normalize the folder list
        tmp['general']['folder_list'] = [
            os.path.abspath(os.path.normpath(unicode(a)))
            for a in tmp['general']['folder_list']
        ]
        tmp['database.mysql']['password'] = utils.encode(
            tmp['general']['install_id'], 'comic')

        self.merge(tmp)
        if not os.path.exists(self.filename):
            self.write()
Пример #16
0
    def lastpage_extractor_for_blacklist(self):
        print "Extract Last Pages"
        query = self.getSession.query(Comic)
        x = os.path.join(AppFolders.appBlacklistPages(), "lastpage")
        y = os.path.join(AppFolders.appBlacklistPages(), "lastpage_double")
        if not os.path.isdir(x):
            os.makedirs(x)
        if not os.path.isdir(y):
            os.makedirs(y)
        c = 0
        for row in query:
            print('Extracting last page from ' + str(c) + ' ' + row.path)
            c += 1
            ca = self.getComicArchive(row.id, row.path)
            # auto convert webp (disable for chunky or fix web book reader)
            image_data = ca.getPage(row.page_count - 1)
            hash = utils.hash(image_data)

            # ascept ratio check
            #im = Image.open(StringIO.StringIO(image_data))
            #w,h = im.size
            #if h > w:
            #    continue

            if self.checkHashBlacklist(hash):
                continue
            if os.path.isfile(os.path.join(x, str(hash))):
                if os.path.isfile(os.path.join(y, str(hash))):
                    print "Double Already Exists"
                    continue
                else:
                    print "Adding Double"
                    file = open(os.path.join(y, str(hash)), "w")
                    file.write(image_data)
            else:
                print "Adding Lastpage"
                file = open(os.path.join(x, str(hash)), "w")
                #file.write("1")
                file.write(image_data)
            file.close()
Пример #17
0
 def __init__(self, apiServer):
     
     self.apiServer = apiServer
     
     self.icon = AppFolders.iconsPath("logo.ico")
     self.hover_text = "ComicStreamer"
     self.on_quit = self.bye    
         
     menu_options = (
                     ('Show Interface', None, self.show),
                    )
     
     menu_options = menu_options + (('Quit', None, self.QUIT),)
     self._next_action_id = self.FIRST_ID
     self.menu_actions_by_id = set()
     self.menu_options = self._add_ids_to_menu_options(list(menu_options))
     self.menu_actions_by_id = dict(self.menu_actions_by_id)
     del self._next_action_id
     
     
     self.default_menu_index = 1
     self.window_class_name = "ComicStreamerTrayIcon"
     
     message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
                    win32con.WM_DESTROY: self.destroy,
                    win32con.WM_COMMAND: self.command,
                    win32con.WM_USER+20 : self.notify,}
     # Register the Window class.
     window_class = win32gui.WNDCLASS()
     hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
     window_class.lpszClassName = self.window_class_name
     window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
     window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(window_class)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom,
                                       self.window_class_name,
                                       style,
                                       0,
                                       0,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT,
                                       0,
                                       0,
                                       hinst,
                                       None)
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
Пример #18
0
 def isBlacklist(self,image, hash=None):
     if hash is None:
         hash = utils.hash(image)
     
     # should be replaced with database query...
     
     obj = self.getSession().query(Blacklist.hash).filter(Blacklist.hash == hash).first()
     if obj is not None:
         with open(AppFolders.missingPath("blacklist.png"), 'rb') as fd:
             image_data = fd.read()
         return image_data
     else:
         return image
Пример #19
0
 def getComicArchive(self, path):
     # should also look at modified time of file
     for ca in self.comicArchiveList:
         if ca.path == path:
             # remove from list and put at end
             self.comicArchiveList.remove(ca)
             self.comicArchiveList.append(ca)
             return ca
     else:
         ca = ComicArchive(path, default_image_path=AppFolders.imagePath("default.jpg"))
         self.comicArchiveList.append(ca)
         if len(self.comicArchiveList) > 10:
             self.comicArchiveList.pop(0)
         return ca
Пример #20
0
    def isBlacklist(self, image, hash=None):
        if hash is None:
            hash = utils.hash(image)

        # should be replaced with database query...

        obj = self.getSession().query(
            Blacklist.hash).filter(Blacklist.hash == hash).first()
        if obj is not None:
            with open(AppFolders.missingPath("blacklist.png"), 'rb') as fd:
                image_data = fd.read()
            return image_data
        else:
            return image
Пример #21
0
 def getComicArchive(self, id, path):
     # should also look at modified time of file
     for ca in self.comicArchiveList:
         if ca.path == path:
             # remove from list and put at end
             self.comicArchiveList.remove(ca)
             self.comicArchiveList.append(ca)
             return ca
     else:
         ca = ComicArchive(path, default_image_path=AppFolders.missingPath("page.png"))
         self.comicArchiveList.append(ca)
         if len(self.comicArchiveList) > 10:
             self.comicArchiveList.pop(0)
         return ca
Пример #22
0
    def __init__(self):
        super(ComicStreamerConfig, self).__init__()
               
        self.csfolder = AppFolders.settings()

        # make sure folder exisits
        if not os.path.exists( self.csfolder ):
            os.makedirs( self.csfolder )

        # set up initial values
        self.filename = os.path.join(self.csfolder, "comicstreamer")
        if  platform.system() == "Windows":
            self.filename += ".ini"
        else: #if platform.system() == "Darwin":
            self.filename += ".conf"
        
        self.configspec=io.StringIO(ComicStreamerConfig.configspec)
        self.encoding="UTF8"
        
        # since some stuff in the configobj has to happen during object initialization,
        # use a temporary delegate,  and them merge it into self
        tmp = ConfigObj(self.filename, configspec=self.configspec, encoding=self.encoding)
        validator = Validator()
        tmp.validate(validator,  copy=True)
       
       
        if tmp['format.ebook']['calibre'] == '':
            if platform.system() == "Darwin":
                calibre = '/Applications/calibre.app/Contents/MacOS/ebook-convert'
                if os.path.isfile(calibre):
                    tmp['format.ebook']['calibre'] = calibre

        # set up the install ID
        if tmp['general']['install_id'] == '':
            tmp['general']['install_id'] = uuid.uuid4().hex
            
        #set up the cookie secret
        if tmp['security']['cookie_secret'] == '':
            tmp['security']['cookie_secret'] = base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)

        # normalize the folder list
        tmp['general']['folder_list'] = [os.path.abspath(os.path.normpath(unicode(a))) for a in tmp['general']['folder_list']]
        tmp['database.mysql']['password'] = utils.encode(tmp['general']['install_id'],'comic')

        self.merge(tmp)
        if not os.path.exists( self.filename ):
            self.write()
Пример #23
0
    def __init__(self, apiServer):

        self.apiServer = apiServer

        self.icon = AppFolders.iconsPath("logo.ico")
        self.hover_text = "ComicStreamer"
        self.on_quit = self.bye

        menu_options = (('Show Interface', None, self.show), )

        menu_options = menu_options + (('Quit', None, self.QUIT), )
        self._next_action_id = self.FIRST_ID
        self.menu_actions_by_id = set()
        self.menu_options = self._add_ids_to_menu_options(list(menu_options))
        self.menu_actions_by_id = dict(self.menu_actions_by_id)
        del self._next_action_id

        self.default_menu_index = 1
        self.window_class_name = "ComicStreamerTrayIcon"

        message_map = {
            win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
            win32con.WM_DESTROY: self.destroy,
            win32con.WM_COMMAND: self.command,
            win32con.WM_USER + 20: self.notify,
        }
        # Register the Window class.
        window_class = win32gui.WNDCLASS()
        hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
        window_class.lpszClassName = self.window_class_name
        window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(window_class)
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name,
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.refresh_icon()
Пример #24
0
    def comicBlacklist(self, comic_id, pagenum):
        #obj = session.query(database.Blacklist).filter(database.Blacklist.comic_id == int(comic_id),database.Blacklist.page == int(pagenum)).first()
        #       if obj is None:

        session = self.getSession()

        #self.getComic()
        #x = self.getSession().query(Comic.id, Comic.path, Comic.mod_ts)

        image_data = self.getComicPage(comic_id, pagenum, False)
        hash = utils.hash(image_data)

        #comichash = self.getHashEntity(Blacklist, hash)
        #self.getComic(comic_id).blacklist(comichash)

        obj = self.getSession().query(
            Blacklist.hash).filter(Blacklist.hash == hash).first()
        if obj is None:
            try:
                blacklist = Blacklist()
                blacklist.hash = hash
                blacklist.detect = len(image_data)

                file = open(
                    os.path.join(AppFolders.appBlacklistPages(),
                                 str(blacklist.hash)), "w")
                file.write(image_data)
                file.close()

                #blacklist.comic_id = int(comic_id)
                #blacklist.page = int(pagenum)
                blacklist.ts = datetime.datetime.utcnow()
                session.add(blacklist)
                session.commit()
                session.close()
            except Exception, e:
                print str(e)
                logging.error(
                    "Blacklist: Problem blocking page {} on comic {}".format(
                        pagenum, comic_id))
Пример #25
0
    def getComicMetadata(self, path):
        ca = ComicArchive(
            path, default_image_path=AppFolders.missingPath("page.png"))

        if ca.seemsToBeAComicArchive():

            if ca.hasMetadata(MetaDataStyle.CIX):
                style = MetaDataStyle.CIX
            elif ca.hasMetadata(MetaDataStyle.CBI):
                style = MetaDataStyle.CBI
            elif ca.hasMetadata(MetaDataStyle.COMET):
                style = MetaDataStyle.COMET
            elif ca.hasMetadata(MetaDataStyle.CBW):
                style = MetaDataStyle.CBW
            else:
                logging.warning(u"Library: File Has No ComicMeta Data")
                if ca.hasMetadata(MetaDataStyle.CALIBRE):
                    style = MetaDataStyle.CALIBRE
                elif ca.hasMetadata(MetaDataStyle.EPUB):
                    style = MetaDataStyle.EPUB
                else:
                    style = None

            if style is not None:
                md = ca.readMetadata(style)
                if md.isEmpty:
                    md = ca.metadataFromFilename()
            else:
                # No metadata in comic.  make some guesses from the filename
                md = ca.metadataFromFilename()

            # patch version 2
            if (md.title is None or md.title
                    == "") and md.issue is None and not md.series is None:
                md.title = md.series
                md.series = None

            md.fingerprint = ca.fingerprint()
            md.path = ca.path

            md.page_count = ca.page_count

            md.mod_ts = datetime.utcfromtimestamp(getmtime(ca.path))
            md.filesize = os.path.getsize(md.path)
            md.hash = ""

            #thumbnail generation
            image_data = ca.getPage(0, AppFolders.missingPath("cover.png"))

            #now resize it
            thumb = StringIO.StringIO()

            #Lets right thumbs to files. large libraries cause the database to bloat
            try:
                utils.resize(image_data, (400, 400), thumb)
                filename = md.fingerprint + ".png"
                foldername = filename[0]
                thumbSubFolder = AppFolders.appThumbFolder(foldername)
                if not os.path.exists(thumbSubFolder):
                    os.makedirs(thumbSubFolder)
                folderpath = AppFolders.appThumbPath(foldername, filename)
                with open(folderpath, 'wb') as f:
                    f.write(thumb.getvalue())

                print("Extracted thumb: " + filename)

            except:
                print("Thumbnail extraction failed")
            # print md
            return md
        return None
Пример #26
0
class DataManager():
    def __init__(self, config):
        global mysql_active
        self.config = config
        self.init()

    def stop(self):
        if mysql_active:
            logging.debug("Database: MySQL: Stopped")
        else:
            logging.debug("Database: SQLite: Stopped")

    def init(self):
        global mysql_active

        if mysql_active:
            try:
                logging.debug("Database: MySQL: Started")
                self.engine = create_engine(
                    "mysql://" + self.config['database.mysql']['username'] +
                    ":" +
                    utils.decode(self.config['general']['install_id'],
                                 self.config['database.mysql']['password']) +
                    "@" + self.config['database.mysql']['host'] + ":" +
                    str(self.config['database.mysql']['port']) + "/" +
                    self.config['database.mysql']['database'] +
                    "?charset=utf8",
                    pool_recycle=3600,
                    echo=False)
                logging.info("Database: MySQL: " +
                             self.config['database.mysql']['database'] + " (" +
                             self.config['database.mysql']['host'] + ":" +
                             str(self.config['database.mysql']['port']) + ")")
            except Exception, e:
                mysql_active = False
                logging.error("Database: MySQL: Failed (" +
                              self.config['database.mysql']['database'] +
                              " [" + self.config['database.mysql']['host'] +
                              ":" +
                              str(self.config['database.mysql']['port']) +
                              "])")
                logging.error("Database: MySQL: Failed (" + str(e) + ")")
                logging.warning("Database: Switching to SQLite Engine")

        if not mysql_active:
            logging.debug("Database: SQLite: Started")

            db = self.config['database.sqlite']['database']
            if db == "": db = "comicstreamer"
            db += u".sqlite"

            self.dbfile = self.config['database.sqlite']['location']

            if self.dbfile == "":
                self.dbfile = os.path.join(AppFolders.appData(), db)
            else:
                if os.path.isdir(self.dbfile):
                    self.dbfile = os.path.join(self.dbfile, db)
                else:
                    logging.error(
                        "Database: SQLite: Database Location Unavailable (" +
                        self.dbfile + ")")
                    logging.warning(
                        "Database: Switching to SQLite Engine Default Database Location"
                    )
                    self.dbfile = os.path.join(AppFolders.appData(), db)

            try:
                self.engine = create_engine(u'sqlite:///' + self.dbfile,
                                            echo=False)
                logging.info("Database: SQLite: (" + self.dbfile + ")")
            except:
                logging.error("Database: SQLite Failed (" + self.dbfile + ")")
                logging.warning(
                    "Database: Switching to SQLite Engine Default Database Location"
                )
                self.dbfile = os.path.join(AppFolders.appData(),
                                           "comicstreamer.sqlite")
                try:
                    self.engine = create_engine('sqlite:///' + self.dbfile,
                                                echo=False)
                    logging.info("Database: SQLite: (" + self.dbfile + ")")
                except:
                    logging.error("Database: SQLite: Failed (" + self.dbfile +
                                  ")")

        if mysql_active:
            session_factory = sessionmaker(
                bind=self.engine,
                expire_on_commit=True,
                autoflush=True,
                autocommit=False
            )  #, autoflush=False, autocommit=True, expire_on_commit=True) #,autocommit=True)
        else:
            session_factory = sessionmaker(
                bind=self.engine, expire_on_commit=True
            )  #, autocommit=True) #, autoflush=False, autocommit=True, expire_on_commit=True) #,autocommit=True)
        self.Session = scoped_session(session_factory)