示例#1
0
 def __init__(self, **kwargs):
     super(LocalListsScreen, self).__init__(**kwargs)
     self.lists_loaded = BooleanProperty()
     self.lists_loaded = False
     self.app = App.get_running_app()
     self.fetch_data = None
     self.Data = ""
     self.fetch_data = ComicServerConn()
     self.base_url = self.app.base_url
     self.api_url = self.app.api_url
示例#2
0
    def __init__(self, reading_list=None, **kwords):
        self.reading_list = reading_list

        self.app = App.get_running_app()
        self.api_url = self.app.api_url
        self.fetch_data = ComicServerConn()
        self.num_file_done = 0
        self.comic_thumb_height = 240
        self.comic_thumb_width = 156
        id_folder = os.path.join(self.app.sync_folder, self.reading_list.slug)
        my_data_dir = Path(os.path.join(id_folder, 'data'))
        self.my_comic_dir = Path(os.path.join(id_folder, 'comics'))
        self.my_thumb_dir = Path(os.path.join(self.my_comic_dir, 'thumb'))
        if not self.my_comic_dir.is_dir():
            os.makedirs(self.my_comic_dir)
        if not self.my_thumb_dir.is_dir():
            os.makedirs(self.my_thumb_dir)
        # for item in SYNC_SETTINGS_ITEMS:
        #    val = ""
        #    tmp_defaults[key] = getattr(self, key)
        # NOTE: can be removed once DB functions added
        if not my_data_dir.is_dir():
            os.makedirs(my_data_dir)
        settings_json = os.path.join(my_data_dir, 'settings.json')
        comics_json = os.path.join(my_data_dir, 'sync_comics.json')
        self.this_test = "Test"
        self.sync_data = JsonStore(settings_json)
        self.sync_comics = JsonStore(comics_json)
        self.last_read_comic = self.get_last_comic_read()
        if self.sync_data.exists('options'):
            self.cb_only_read_state = self.sync_data.get(
                "options")["cb_only_read_state"]
            self.cb_keep_last_read_state = self.sync_data.get(
                "options")["cb_keep_last_read_state"]
            self.cb_optimize_size_state = self.sync_data.get(
                "options")["cb_optimize_size_state"]
            self.cb_limit_state = self.sync_data.get("options")[
                "cb_limit_state"]
            self.limit_num = self.sync_data.get("options")["limit_num"]
            self.sw_syn_this_active = self.sync_data.get("options")[
                'sw_syn_this_active']
        else:
            self.cb_only_read_state = 'normal'
            self.cb_keep_last_read_state = 'normal'
            self.cb_optimize_size_state = 'normal'
            self.cb_limit_state = 'normal'
            self.limit_num = 25
            self.sw_syn_this_active = False
        # end note

        self.last = 0
        self.limit = 25
        self.sync_range = int(self.last) + int(self.limit_num)
        self.api_key = self.app.config.get('General', 'api_key')
示例#3
0
 async def collect_readinglist_data():
     self.readinglist_name = readinglist_name
     self.app.set_screen(self.readinglist_name + " Page 1")
     self.reading_list_title = self.readinglist_name + " Page 1"
     self.readinglist_Id = readinglist_Id
     self.page_number = current_page_num
     self.mode = mode
     if self.mode == "From Server":
         self.fetch_data = ComicServerConn()
         lsit_count_url = "{}/Lists/{}/Comics/".format(
             self.api_url, readinglist_Id)
         # self.fetch_data.get_list_count(lsit_count_url,self)
         self.fetch_data.get_server_data(lsit_count_url, self)
     elif self.mode == "From DataBase":
         self.got_db_data()
示例#4
0
    def collect_readinglist_data(self,
                                 readinglist_name,
                                 readinglist_Id,
                                 mode="From DataBase"):
        self.readinglist_name = readinglist_name

        self.reading_list_title = self.readinglist_name + " Page 1"
        self.readinglist_Id = readinglist_Id
        self.mode = mode
        if self.mode == "From Server":
            self.fetch_data = ComicServerConn()
            lsit_count_url = f"{self.api_url}/Lists/{readinglist_Id}/Comics/"
            # self.fetch_data.get_list_count(lsit_count_url,self)
            self.fetch_data.get_server_data(lsit_count_url, self)
        elif self.mode == "From DataBase":
            self.got_db_data()
示例#5
0
async def save_thumb(comic_id, c_image_source):
    def got_thumb(results):
        pass

    fetch_data = ComicServerConn()
    app = App.get_running_app()
    id_folder = app.store_dir
    my_thumb_dir = Path(os.path.join(id_folder, "comic_thumbs"))

    if not my_thumb_dir.is_dir():
        os.makedirs(my_thumb_dir)
    file_name = f"{comic_id}.jpg"
    t_file = os.path.join(my_thumb_dir, file_name)
    fetch_data.get_server_file_download(
        c_image_source,
        callback=lambda req, results: got_thumb(results),
        file_path=os.path.join(my_thumb_dir, t_file),
    )
示例#6
0
    def __init__(self, **kwargs):
        super(BaseScreen, self).__init__(**kwargs)
        self.app = App.get_running_app()
        self.fetch_data = None
        self.Data = ""

        self.fetch_data = ComicServerConn()
        self.myLoginPop = LoginPopupContent()
        self.popup = LoginPopup(
            content=self.myLoginPop, size_hint=(None, None), size=(500, 400)
        )
        # self.update_settings()
        # self.bind(username=self.update_settings)
        # self.bind_settings()
        self.password = self.app.password
        self.api_key = self.app.api_key
        self.username = self.app.username
        self.base_url = self.app.base_url
        self.open_last_comic_startup = self.app.open_last_comic_startup
示例#7
0
 def __init__(self, **kwargs):
     super(ServerComicBookScreen, self).__init__(**kwargs)
     self.fetch_data = None
     self.app = App.get_running_app()
     #        self.base_url = self.app.base_url
     #        self.api_url = self.app.api_url
     self.current_page = None
     self.fetch_data = ComicServerConn()
     self.api_key = self.app.config.get("General", "api_key")
     self.popup_bkcolor = (0.5, 0.5, 0.5, 0.87)
     self.full_screen = False
     self.option_isopen = False
     self.next_dialog_open = False
     self.prev_dialog_open = False
     config_app = App.get_running_app()
     settings_data = json.loads(settings_json_screen_tap_control)
     # Window.bind(on_keyboard=self.events_program)
     for setting in settings_data:
         if setting["type"] == "options":
             tap_config = config_app.config.get(setting["section"],
                                                setting["key"])
             if tap_config == "Disabled":
                 self.ids[setting["key"]].disabled = True
示例#8
0
    def do_sync(self):
        def _syncrun_callback(*args):
            pass

        app = App.get_running_app()
        if app.sync_is_running is True:
            self.please_wait_dialog = MDDialog(
                title="Sync Already in Progress",
                size_hint=(0.8, 0.4),
                text_button_ok="Ok",
                text=f"Please wait till current Sync is done",
                events_callback=_syncrun_callback,
            )
            self.please_wait_dialog.open()
            return
        self.num_file_done = 0
        sync_range = 0
        self.fetch_data = ComicServerConn()
        rl_db = ReadingList.get(ReadingList.slug == self.slug)

        end_last_sync_num = rl_db.end_last_sync_num
        if end_last_sync_num != 0:
            end_last_sync_num = end_last_sync_num - 1
        comicindex_db = ComicIndex.get(ComicIndex.readinglist == self.slug)
        last_read_comic_db = self.db.comics.where(
            (Comic.UserLastPageRead == Comic.PageCount - 1)
            & (Comic.PageCount > 1)
        ).order_by(comicindex_db.index)
        if len(last_read_comic_db) > 1:
            last_read_index = ComicIndex.get(
                ComicIndex.comic == last_read_comic_db[-1].Id,
                ComicIndex.readinglist == self.slug,
            ).index
        elif len(last_read_comic_db) != 0:
            last_read_index = ComicIndex.get(
                ComicIndex.comic == last_read_comic_db[0].Id,
                ComicIndex.readinglist == self.slug,
            ).index
        else:
            last_read_index = 0
        if self.cb_limit_active:
            if self.cb_only_read_active:
                list_comics = self.db.comics.where(
                    ~(Comic.UserLastPageRead == Comic.PageCount - 1)
                    & (Comic.PageCount > 1)
                    & (Comic.been_sync)
                    != True
                ).order_by(
                    comicindex_db.index
                )  # noqa: E712
                if last_read_index < end_last_sync_num:
                    sync_range = int(self.limit_num)
                    tmp_comic_list = list_comics[0:int(sync_range)]
                else:
                    sync_range = int(end_last_sync_num) + int(self.limit_num)
                    tmp_comic_list = list_comics[end_last_sync_num:int(sync_range)]
                purge_list = self.db.comics.where(
                    (Comic.UserLastPageRead == Comic.PageCount - 1)
                    & (Comic.PageCount > 1)
                    & (Comic.is_sync == True)
                ).order_by(
                    comicindex_db.index
                )  # noqa: E712
            else:
                list_comics = (
                    Comic.select()
                    .where(
                        (Comic.is_sync == False) & (Comic.been_sync == False)
                    )
                    .order_by(comicindex_db.index)
                )  # noqa: E712,E501
                sync_range = int(self.limit_num)
                tmp_comic_list = list_comics[0:int(sync_range)]
                purge_list = self.db.comics.where(
                    Comic.is_sync == True
                ).order_by(
                    comicindex_db.index
                )  # noqa: E712
        else:
            sync_range = int(len(self.comics))
            # rl_db.end_last_sync_num = new_end_last_sync_num
            # rl_db.save()
            if self.cb_only_read_active:
                list_comics = self.db.comics.where(
                    ~(Comic.UserLastPageRead == Comic.PageCount - 1)
                    & (Comic.PageCount > 1)
                ).order_by(
                    comicindex_db.index
                )  # noqa: E712
                tmp_comic_list = list_comics[0:int(sync_range)]
            else:
                list_comics = self.db.comics.where(
                    (Comic.is_sync == False) & (Comic.been_sync == False)
                ).order_by(
                    comicindex_db.index
                )  # noqa: E712,E501
                tmp_comic_list = list_comics
        db_item = ReadingList.get(ReadingList.slug == self.slug)
        for key in READINGLIST_SETTINGS_KEYS:
            v = getattr(db_item, key)
            globals()["%s" % key] = v
        app = App.get_running_app()
        id_folder = os.path.join(app.sync_folder, self.slug)
        my_comic_dir = Path(os.path.join(id_folder, "comics"))
        if os.path.isdir(my_comic_dir):
            print(f"{get_size(my_comic_dir)/1000000} MB")
        sync_comic_list = []
        for comic in tmp_comic_list:
            if comic.is_sync is False:
                sync_comic_list.append(comic)
        if self.cb_purge_active:
            for item in purge_list:
                os.remove(item.local_file)
                db_comic = Comic.get(Comic.Id == item.Id)
                db_comic.is_sync = False
                db_comic.local_file = ""
                db_comic.save()
                server_readinglists_screen = app.manager.get_screen(
                    "server_readinglists_screen"
                )
                server_readinglists_screen.file_sync_update(item.Id, False)
        self.sync_readinglist(comic_list=sync_comic_list)
示例#9
0
    def do_db_refresh(self, screen=None):
        def __finish_toast(dt):
            app = App.get_running_app()
            screen = app.manager.get_screen("server_readinglists_screen")
            screen.refresh_callback()
            toast("DataBase Refresh Complete")

        def __got_readlist_data(results):
            def __updated_progress(results):
                pass

            the_keys = [
                "Id",
                "Series",
                "Number",
                "Volume",
                "Year",
                "Month",
                "UserCurrentPage",
                "UserLastPageRead",
                "PageCount",
                "Summary",
                "FilePath",
            ]
            for server_comic in results["items"]:
                for db_comic in self.comics:
                    if db_comic.Id == server_comic["Id"]:
                        for key in the_keys:
                            if getattr(db_comic, key) != server_comic[key]:
                                if key in (
                                    "UserCurrentPage",
                                    "UserLastPageRead",
                                ) and (db_comic.is_sync):
                                    if (
                                        db_comic.UserLastPageRead
                                        > server_comic["UserLastPageRead"]
                                    ) or (
                                        db_comic.UserCurrentPage
                                        > server_comic["UserCurrentPage"]
                                    ):
                                        if (
                                            db_comic.UserCurrentPage
                                            > db_comic.UserLastPageRead
                                        ):
                                            current_page = (
                                                db_comic.UserCurrentPage
                                            )  # noqa
                                        else:
                                            current_page = (
                                                db_comic.UserLastPageRead
                                            )  # noqa
                                        update_url = "{}/Comics/{}/Progress".format(
                                            api_url, db_comic.Id
                                        )
                                        self.fetch_data.update_progress(
                                            update_url,
                                            current_page,
                                            callback=lambda req, results: __updated_progress(
                                                results
                                            ),
                                        )
                                    else:
                                        x_str = db_comic.__str__
                                        Logger.info(
                                            "Updating DB Record for {} of {}".format(
                                                key, x_str
                                            )
                                        )
                                        toast(
                                            "Updating DB Record for {} of {}".format(
                                                key, x_str
                                            )
                                        )
                                        db_item = Comic.get(
                                            Comic.Id == db_comic.Id
                                        )
                                        if db_item:
                                            setattr(
                                                db_item, key, server_comic[key]
                                            )
                                            db_item.save()
                                            setattr(self, key, db_item)

            Clock.schedule_once(__finish_toast, 3)

        self.fetch_data = ComicServerConn()
        app = App.get_running_app()
        api_url = app.api_url
        server_url = f"{api_url}/Lists/{self.slug}/Comics/"

        self.fetch_data.get_server_data_callback(
            server_url,
            callback=lambda req, results: __got_readlist_data(results),
        )
示例#10
0
    def callback_for_menu_items(self, *args):
        def __updated_progress(results, state):
            Logger.info(results)
            if state == "Unread":
                # self.img_color = (1, 1, 1, 1)
                self.is_read = False
                self.page_count_text = "0%"
                self.comic_obj.UserLastPage = 0
                self.comic_obj.UserCurrentPage = 0
                self.comic_obj.update()
            elif state == "Read":
                # self.img_color = (.89, .15, .21, 5)
                self.is_read = True
                self.page_count_text = "100%"
                the_page = self.comic_obj.PageCount
                self.comic_obj.UserLastPage = the_page
                self.comic_obj.UserCurrentPage = the_page

        action = args[0].replace("[color=#000000]", "").replace("[/color]", "")
        if action == "Open This Comic":
            self.open_comic()
        elif action == "Mark as Read":
            try:
                db_comic = Comic.get(Comic.Id == self.comic_obj.Id)
                if db_comic:
                    db_comic.UserLastPageRead = self.comic_obj.PageCount - 1
                    db_comic.UserCurrentPage = self.comic_obj.PageCount - 1
                    db_comic.save()
                    self.comic_obj.UserLastPageRead = (
                        self.comic_obj.PageCount - 1)  # noqa
                    self.comic_obj.UserCurrentPage = (
                        self.comic_obj.PageCount - 1)
                    server_readinglists_screen = self.app.manager.get_screen(
                        "server_readinglists_screen")
                    for item in server_readinglists_screen.new_readinglist.comics:
                        if item.Id == self.comic_obj.Id:
                            item.UserCurrentPage = self.comic_obj.PageCount - 1
                            item.UserLastPageRead = self.comic_obj.PageCount - 1
            except (ProgrammingError, OperationalError, DataError) as e:
                Logger.error(f"Mar as unRead DB: {e}")
            server_con = ComicServerConn()
            update_url = "{}/Comics/{}/Progress".format(
                self.app.api_url, self.comic_obj.Id)
            server_con.update_progress(
                update_url,
                self.comic_obj.PageCount - 1,
                callback=lambda req, results: __updated_progress(
                    results, "Read"),
            )
        elif action == "Mark as UnRead":
            try:
                db_comic = Comic.get(Comic.Id == self.comic_obj.Id)
                if db_comic:
                    db_comic.UserLastPageRead = 0
                    db_comic.UserCurrentPage = 0
                    db_comic.save()
                    self.comic_obj.UserLastPageRead = 0
                    self.comic_obj.UserCurrentPage = 0
                    server_readinglists_screen = self.app.manager.get_screen(
                        "server_readinglists_screen")
                    for item in server_readinglists_screen.new_readinglist.comics:
                        if item.Id == self.comic_obj.Id:
                            item.UserCurrentPage = 0
                            item.UserLastPageRead = 0
            except (ProgrammingError, OperationalError, DataError) as e:
                Logger.error(f"Mark as unRead DB: {e}")
            server_con = ComicServerConn()
            update_url = "{}/Comics/{}/Mark_Unread".format(
                self.app.api_url, self.comic_obj.Id)
            server_con.update_progress(
                update_url,
                0,
                callback=lambda req, results: __updated_progress(
                    results, "Unread"),
            )
示例#11
0
    def build_last_comic_section(  # noqa
        self, readinglist_name, readinglist_Id
    ):
        def __got_readlist_data(results):
            async def __load_readinglist_scree(paginator_obj=None):
                if tmp_last_comic_type == "local_file":
                    x_readinglists_screen = self.app.manager.get_screen(
                        "local_readinglists_screen"
                    )
                else:
                    x_readinglists_screen = self.app.manager.get_screen(
                        "server_readinglists_screen"
                    )
                x_readinglists_screen.list_loaded = False
                x_readinglists_screen.setup_screen()
                x_readinglists_screen.page_number = tmp_last_pag_pagnum
                x_readinglists_screen.loading_done = False
                self.call_collect(
                    set_mode,
                    x_readinglists_screen,
                    readinglist_name,
                    readinglist_Id,
                )

            tmp_last_comic_id = self.app.config.get("Saved", "last_comic_id")
            tmp_last_comic_type = self.app.config.get(
                "Saved", "last_comic_type"
            )
            tmp_last_pag_pagnum = int(
                self.app.config.get("Saved", "last_pag_pagnum")
            )
            if tmp_last_comic_id == "":
                return
            else:
                query = ReadingList.select().where(
                    ReadingList.slug == readinglist_Id
                )
                if query.exists():
                    Logger.info(f"{readinglist_name} already in Database")
                    set_mode = "From DataBase"
                    mode = ""
                    if tmp_last_comic_type == "local_file":
                        mode = "local_file"
                    self.new_readinglist = ComicReadingList(
                        name=self.readinglist_name,
                        data="db_data",
                        slug=self.readinglist_Id,
                        mode=mode,
                    )

                    # self.new_readinglist.comics_write()
                    max_books_page = int(
                        self.app.config.get("General", "max_books_page")
                    )
                    new_readinglist_reversed = self.new_readinglist.comics
                    paginator_obj = Paginator(
                        new_readinglist_reversed, max_books_page
                    )
                    for x in range(1, paginator_obj.num_pages()):
                        this_page = paginator_obj.page(x)
                        for comic in this_page.object_list:
                            if tmp_last_comic_id == comic.Id:
                                tmp_last_pag_pagnum = this_page.number
                    asynckivy.start(
                        __load_readinglist_scree(paginator_obj=paginator_obj)
                    )
                    if (
                        self.open_last_comic_startup == 1
                        and not self.app.app_started
                    ):
                        for comic in self.new_readinglist.comics:
                            if comic.slug == tmp_last_comic_id:

                                self.open_comic(
                                    tmp_last_comic_id=tmp_last_comic_id,
                                    tmp_last_comic_type=tmp_last_comic_type,
                                    paginator_obj=paginator_obj,
                                    comic=comic,
                                    tmp_last_pag_pagnum=tmp_last_pag_pagnum,
                                )
                    else:
                        grid = self.ids["main_grid"]
                        grid.cols = 1
                        grid.clear_widgets()
                        for comic in self.new_readinglist.comics:
                            if comic.slug == tmp_last_comic_id:
                                c = ReadingListComicImage(comic_obj=comic)
                                c.readinglist_obj = self.new_readinglist
                                c.paginator_obj = paginator_obj
                                x = self.app.comic_thumb_width
                                y = self.app.comic_thumb_height
                                if tmp_last_comic_type == "local_file":
                                    if comic.local_file == "":
                                        return
                                    import os

                                    id_folder = os.path.join(
                                        self.app.sync_folder,
                                        self.new_readinglist.slug,
                                    )
                                    my_thumb_dir = os.path.join(
                                        id_folder, "thumb"
                                    )
                                    thumb_name = f"{comic.Id}.jpg"
                                    t_file = os.path.join(
                                        my_thumb_dir, thumb_name
                                    )
                                    c_image_source = t_file
                                else:
                                    round_y = round(dp(y))
                                    part_url = f"/Comics/{comic.Id}/Pages/0?"
                                    part_api = "&apiKey={}&height={}".format(
                                        self.api_key, round_y
                                    )
                                    c_image_source = "{}{}{}".format(
                                        self.app.api_url, part_url, part_api
                                    )
                                c.source = c_image_source
                                c.PageCount = comic.PageCount
                                c.pag_pagenum = tmp_last_pag_pagnum
                                if tmp_last_comic_type == "local_file":
                                    c.view_mode = "Sync"
                                strtxt = f"{comic.Series} #{comic.Number}"
                                tmp_color = get_hex_from_color((1, 1, 1, 1))
                                c.text = f"[color={tmp_color}]{strtxt}[/color]"
                                grid.add_widget(c)
                                tmp_txt = f"Last Comic Load from \
                                        {self.new_readinglist.name}"
                                self.ids.last_comic_label.text = tmp_txt
                else:
                    Logger.info(
                        f"{readinglist_name} \
                            not in Database This could be a problems"
                    )

                    set_mode = "From Server"
                # set_mode = 'From Server'

        self.readinglist_name = readinglist_name
        # self.app.set_screen(self.readinglist_name + ' Page 1')
        self.reading_list_title = self.readinglist_name + " Page 1"
        self.readinglist_Id = readinglist_Id

        # self.fetch_data.get_list_count(lsit_count_url,self)
        tmp_last_comic_type = self.app.config.get("Saved", "last_comic_type")
        if tmp_last_comic_type == "local_file":
            Clock.schedule_once(lambda dt: __got_readlist_data("none"), 0.15)
        else:
            self.fetch_data = ComicServerConn()
            lsit_count_url = (
                f"{self.app.api_url}/Lists/{readinglist_Id}/Comics/"
            )  # noqa
            self.fetch_data.get_server_data_callback(
                lsit_count_url,
                callback=lambda req, results: __got_readlist_data(results),
            )