From 0b10aa6e8a75824b9e3138e4acaa4c15731f7047 Mon Sep 17 00:00:00 2001 From: bobermilk Date: Fri, 24 Feb 2023 21:23:10 +0800 Subject: [PATCH] v6 --- constants.py | 2 +- main.py | 48 +++++++++++++++++++++++++++++++++++------------- scraper.py | 9 ++++++--- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/constants.py b/constants.py index aa577c8..0bae52a 100644 --- a/constants.py +++ b/constants.py @@ -1,4 +1,4 @@ -APP_VERSION=5 +APP_VERSION=6 api_get_interval=0.1 osu_get_interval=3 # osu site diff --git a/main.py b/main.py index 36d9535..8d8c92b 100644 --- a/main.py +++ b/main.py @@ -51,9 +51,12 @@ def reset_job_toggle_button_text(): # called when jobs are completed main_window.m_toggle_downloading.SetLabelText(constants.activity_start) -def show_dialog(msg, ok=None): +def show_dialog(msg, ok=None, focus_main=True): + focus=main_window + if not focus_main: + focus=add_source_window # called when new release dropped on github - dlg = wx.MessageDialog(main_window, + dlg = wx.MessageDialog(focus, msg, "Alert OwO", wx.OK|wx.CANCEL|wx.ICON_QUESTION) result = dlg.ShowModal() @@ -285,16 +288,22 @@ async def onDestroy(self, event): #User closed application if main_window != None: main_window.m_add_source.Enable() + main_window.SetFocus() async def add_userpage(self, event): - links=self.m_userpages.GetValue() + links=self.m_userpages.GetValue().strip() scope=[self.m_user_top100.GetValue(), self.m_user_favourites.GetValue(), self.m_user_everything.GetValue(), self.m_user_ranked.GetValue(), self.m_user_loved.GetValue(), self.m_user_pending.GetValue(), self.m_user_graveyarded.GetValue()] + success=True + if not "ppy.sh/users/" in links: + show_dialog("You need to input a link to the osu user profile", focus_main=False) + success=False if all(x==0 for x in scope): - show_dialog("You need to select something to download from the userpage!") - else: + show_dialog("You need to select something to download from the userpage!", focus_main=False) + success=False + if success: self.Destroy() - StartCoroutine(main_window.add_userpage(links, scope), main_window) + StartCoroutine(main_window.add_userpage(links, scope), main_window) async def add_tournament(self, event): selection=self.m_tournament.GetPageText(self.m_tournament.GetSelection()) @@ -308,15 +317,28 @@ async def add_mappack(self, event): await data.Sources.add_mappack_source(ids) async def add_osucollector(self, event): - links=self.m_osu_collector.GetValue() - self.Destroy() - StartCoroutine(main_window.add_osucollector(links), main_window) + success=True + links=self.m_osu_collector.GetValue().strip() + if not "osucollector.com/collections/" in links: + show_dialog("You need to input osucollector collection url", focus_main=False) + success=False + if success: + self.Destroy() + StartCoroutine(main_window.add_osucollector(links), main_window) async def add_osuweblinks(self, event): - title=self.m_osu_weblinks_key.GetValue() - links=self.m_osu_weblinks.GetValue() - self.Destroy() - StartCoroutine(main_window.add_osuweblinks(title, links), main_window) + success=True + title=self.m_osu_weblinks_key.GetValue().strip() + links=self.m_osu_weblinks.GetValue().strip() + if not title: + show_dialog("You need to name the collection", focus_main=False) + success=False + if not "ppy.sh/beatmapsets/" in links: + show_dialog("You need to input beatmaps for this collection", focus_main=False) + success=False + if success: + self.Destroy() + StartCoroutine(main_window.add_osuweblinks(title, links), main_window) async def change_mappack_section(self, event): selection=str(self.m_mappack_section.GetSelection()) diff --git a/scraper.py b/scraper.py index 6146ba0..9261809 100644 --- a/scraper.py +++ b/scraper.py @@ -30,7 +30,7 @@ async def get_userpage_beatmaps(source): cached_beatmap_ids=set() for beatmap in source.all_beatmaps: cached_beatmap_ids.add(beatmap[1]) - for i, item in enumerate(j): + for i, item in enumerate(j, 1): beatmap_id=item['beatmap_id'] pub.sendMessage("show.loading", msg=f"Getting beatmap data from osu! api ({i}/{len(j)})") if data.Settings.valid_oauth and not beatmap_id in cached_beatmap_ids: @@ -145,7 +145,7 @@ async def get_tournament_beatmaps(source): cached_beatmap_ids=set() for beatmap in source.all_beatmaps: cached_beatmap_ids.add(beatmap[1]) - for i, beatmap in enumerate(beatmaps): + for i, beatmap in enumerate(beatmaps, 1): pub.sendMessage("show.loading", msg=f"Getting beatmap data from osu! api ({i}/{len(beatmaps)})") if data.Settings.valid_oauth and not beatmap[1] in cached_beatmap_ids: checksum, beatmapset_id=await api.query_osu_beatmap(session, beatmap[1]) @@ -199,8 +199,11 @@ async def get_osuweblinks_beatmaps(source): all_beatmaps.add((beatmapset_id, None, None)) async with aiohttp.ClientSession() as session: - for beatmap_id in source.get_beatmap_ids(): + for i, beatmap_id in enumerate(source.get_beatmap_ids(), 1): + pub.sendMessage("show.loading", msg=f"Getting beatmap data from osu! api ({i}/{len(source.get_beatmap_ids())})") beatmap_checksum, beatmapset_id = await api.query_osu_beatmap(session, beatmap_id) + if (beatmapset_id, None, None) in all_beatmaps: + all_beatmaps.remove((beatmapset_id, None, None)) all_beatmaps.add((beatmapset_id, beatmap_id, beatmap_checksum)) pub.sendMessage("show.loading", msg=None)