finished creatinng settings

This commit is contained in:
Benedict Xavier Wanyonyi
2024-05-22 18:35:45 +03:00
parent 0154f109bf
commit 021aa20443
5 changed files with 67 additions and 18 deletions

View File

@@ -1 +1,6 @@
themes_available = ['Aliceblue', 'Antiquewhite', 'Aqua', 'Aquamarine', 'Azure', 'Beige', 'Bisque', 'Black', 'Blanchedalmond', 'Blue', 'Blueviolet', 'Brown', 'Burlywood', 'Cadetblue', 'Chartreuse', 'Chocolate', 'Coral', 'Cornflowerblue', 'Cornsilk', 'Crimson', 'Cyan', 'Darkblue', 'Darkcyan', 'Darkgoldenrod', 'Darkgray', 'Darkgrey', 'Darkgreen', 'Darkkhaki', 'Darkmagenta', 'Darkolivegreen', 'Darkorange', 'Darkorchid', 'Darkred', 'Darksalmon', 'Darkseagreen', 'Darkslateblue', 'Darkslategray', 'Darkslategrey', 'Darkturquoise', 'Darkviolet', 'Deeppink', 'Deepskyblue', 'Dimgray', 'Dimgrey', 'Dodgerblue', 'Firebrick', 'Floralwhite', 'Forestgreen', 'Fuchsia', 'Gainsboro', 'Ghostwhite', 'Gold', 'Goldenrod', 'Gray', 'Grey', 'Green', 'Greenyellow', 'Honeydew', 'Hotpink', 'Indianred', 'Indigo', 'Ivory', 'Khaki', 'Lavender', 'Lavenderblush', 'Lawngreen', 'Lemonchiffon', 'Lightblue', 'Lightcoral', 'Lightcyan', 'Lightgoldenrodyellow', 'Lightgreen', 'Lightgray', 'Lightgrey', 'Lightpink', 'Lightsalmon', 'Lightseagreen', 'Lightskyblue', 'Lightslategray', 'Lightslategrey', 'Lightsteelblue', 'Lightyellow', 'Lime', 'Limegreen', 'Linen', 'Magenta', 'Maroon', 'Mediumaquamarine', 'Mediumblue', 'Mediumorchid', 'Mediumpurple', 'Mediumseagreen', 'Mediumslateblue', 'Mediumspringgreen', 'Mediumturquoise', 'Mediumvioletred', 'Midnightblue', 'Mintcream', 'Mistyrose', 'Moccasin', 'Navajowhite', 'Navy', 'Oldlace', 'Olive', 'Olivedrab', 'Orange', 'Orangered', 'Orchid', 'Palegoldenrod', 'Palegreen', 'Paleturquoise', 'Palevioletred', 'Papayawhip', 'Peachpuff', 'Peru', 'Pink', 'Plum', 'Powderblue', 'Purple', 'Red', 'Rosybrown', 'Royalblue', 'Saddlebrown', 'Salmon', 'Sandybrown', 'Seagreen', 'Seashell', 'Sienna', 'Silver', 'Skyblue', 'Slateblue', 'Slategray', 'Slategrey', 'Snow', 'Springgreen', 'Steelblue', 'Tan', 'Teal', 'Thistle', 'Tomato', 'Turquoise', 'Violet', 'Wheat', 'White', 'Whitesmoke', 'Yellow', 'Yellowgreen']
themes_available = ['Aliceblue', 'Antiquewhite', 'Aqua', 'Aquamarine', 'Azure', 'Beige', 'Bisque', 'Black', 'Blanchedalmond', 'Blue', 'Blueviolet', 'Brown', 'Burlywood', 'Cadetblue', 'Chartreuse', 'Chocolate', 'Coral', 'Cornflowerblue', 'Cornsilk', 'Crimson', 'Cyan', 'Darkblue', 'Darkcyan', 'Darkgoldenrod', 'Darkgray', 'Darkgrey', 'Darkgreen', 'Darkkhaki', 'Darkmagenta', 'Darkolivegreen', 'Darkorange', 'Darkorchid', 'Darkred', 'Darksalmon', 'Darkseagreen', 'Darkslateblue', 'Darkslategray', 'Darkslategrey', 'Darkturquoise', 'Darkviolet', 'Deeppink', 'Deepskyblue', 'Dimgray', 'Dimgrey', 'Dodgerblue', 'Firebrick', 'Floralwhite', 'Forestgreen', 'Fuchsia', 'Gainsboro', 'Ghostwhite', 'Gold', 'Goldenrod', 'Gray', 'Grey', 'Green', 'Greenyellow', 'Honeydew', 'Hotpink', 'Indianred', 'Indigo', 'Ivory', 'Khaki', 'Lavender', 'Lavenderblush', 'Lawngreen', 'Lemonchiffon', 'Lightblue', 'Lightcoral', 'Lightcyan', 'Lightgoldenrodyellow', 'Lightgreen', 'Lightgray', 'Lightgrey', 'Lightpink', 'Lightsalmon', 'Lightseagreen', 'Lightskyblue', 'Lightslategray', 'Lightslategrey', 'Lightsteelblue', 'Lightyellow', 'Lime', 'Limegreen', 'Linen', 'Magenta', 'Maroon', 'Mediumaquamarine', 'Mediumblue', 'Mediumorchid', 'Mediumpurple', 'Mediumseagreen', 'Mediumslateblue', 'Mediumspringgreen', 'Mediumturquoise', 'Mediumvioletred', 'Midnightblue', 'Mintcream', 'Mistyrose', 'Moccasin', 'Navajowhite', 'Navy', 'Oldlace', 'Olive', 'Olivedrab', 'Orange', 'Orangered', 'Orchid', 'Palegoldenrod', 'Palegreen', 'Paleturquoise', 'Palevioletred', 'Papayawhip', 'Peachpuff', 'Peru', 'Pink', 'Plum', 'Powderblue', 'Purple', 'Red', 'Rosybrown', 'Royalblue', 'Saddlebrown', 'Salmon', 'Sandybrown', 'Seagreen', 'Seashell', 'Sienna', 'Silver', 'Skyblue', 'Slateblue', 'Slategray', 'Slategrey', 'Snow', 'Springgreen', 'Steelblue', 'Tan', 'Teal', 'Thistle', 'Tomato', 'Turquoise', 'Violet', 'Wheat', 'White', 'Whitesmoke', 'Yellow',
'Yellowgreen']
# import time
# from datetime import date,datetime
# print(datetime.fromtimestamp(1716412399))
# print(time.daylight,date.max,date.min)

View File

@@ -9,16 +9,20 @@ from pytube import YouTube
from kivy.loader import _ThreadPool
from kivy.clock import Clock
from kivy.cache import Cache
from datetime import date
from datetime import date,datetime
Cache.register("anime")
today = date.today()
now = datetime.now()
user_data = JsonStore("user_data.json")
my_list = user_data.get("my_list")["list"] # returns a list of anime ids
yt_cache = JsonStore("yt_cache.json")
today = date.today()
yt_stream_links = yt_cache.get("yt_stream_links")[f"{today}"]
yt_stream_links = []
name_of_yt_cache = f"{today}{0 if now.hour>=12 else 1}"
if yt_streams:=yt_cache.get("yt_stream_links").get(name_of_yt_cache):
yt_stream_links = yt_streams
if yt_stream_links:
for link in yt_stream_links:
@@ -82,7 +86,7 @@ class MediaCardDataLoader(object):
# sleep(0.5)
data = preview_image,video_stream_url
yt_stream_links.append((yt_watch_url,data))
yt_cache.put("yt_stream_links",**{f"{today}":yt_stream_links})
yt_cache.put("yt_stream_links",**{f"{name_of_yt_cache}":yt_stream_links})
except:
data = preview_image,None
return data

View File

@@ -87,7 +87,7 @@ class SearchScreenView(BaseScreenView):
def update_pagination(self,pagination_info):
self.search_results_pagination.current_page =self.current_page = pagination_info["currentPage"]
self.search_results_pagination.total_pages = self.total_pages = pagination_info["total"]
self.search_results_pagination.total_pages = self.total_pages = max(int(pagination_info["total"]/30),1)
self.has_next_page = pagination_info["hasNextPage"]
def next_page(self):

View File

@@ -15,28 +15,29 @@
MDNavigationRailFabButton:
icon: "home"
on_release:
on_press:
root.screen.manager_screens.current = "home screen"
CommonNavigationRailItem:
icon: "magnify"
text: "Search"
on_release:
on_press:
root.screen.manager_screens.current = "search screen"
CommonNavigationRailItem:
icon: "bookmark" #if root.screen.manager_screens.current=="my list screen" else "bookmark-outline"
text: "Bookmark"
on_release:
on_press:
root.screen.manager_screens.current = "my list screen"
CommonNavigationRailItem:
icon: "library"
text: "Library"
on_release:
on_press:
root.screen.manager_screens.current = "anime screen"
CommonNavigationRailItem:
icon: "cog"
text: "settings"
on_press:app.open_settings()
CommonNavigationRailItem:
icon: "bug"
text: "debug"

View File

@@ -1,4 +1,5 @@
# from kivy.config import Config
from kivy.config import Config,ConfigParser
# Config.set('kivy', 'window_icon', "logo.ico")
# Config.write()
import os
@@ -13,26 +14,33 @@ from queue import Queue
from threading import Thread
import plyer
from kivymd.app import MDApp
from kivy.uix.settings import SettingsWithSidebar,Settings
from kivy.uix.screenmanager import ScreenManager,FadeTransition
from kivy.clock import Clock
from kivy.storage.jsonstore import JsonStore
from datetime import date
from datetime import date,datetime
from subprocess import Popen
from View.screens import screens
import time
from Utility import themes_available
user_data = JsonStore("user_data.json")
today = date.today()
now = datetime.now()
if not(user_data.exists("my_list")):
user_data.put("my_list",list=[])
yt_cache = JsonStore("yt_cache.json")
links_cache_name= f"{today}{0 if now.hour>=12 else 1}"
if not(yt_cache.exists("yt_stream_links")):
yt_cache.put("yt_stream_links",**{f"{today}":[]})
elif not( yt_cache.get("yt_stream_links").get(f"{today}")):
yt_cache.put("yt_stream_links",**{f"{today}":[]})
yt_cache.put("yt_stream_links",**{f"{links_cache_name}":[]})
elif not( yt_cache.get("yt_stream_links").get(f"{links_cache_name}")):
yt_cache.put("yt_stream_links",**{f"{links_cache_name}":[]})
from View.screens import screens
# plyer.
class AniXStreamApp(MDApp):
queue = Queue()
animdl_streaming_subprocess:Popen|None = None
@@ -57,7 +65,13 @@ class AniXStreamApp(MDApp):
self.worker_thread.start()
def build(self) -> ScreenManager:
self.settings_cls = SettingsWithSidebar
self.generate_application_screens()
if config:=self.config:
if theme_color:=config.get("Preferences","theme_color"):
self.theme_cls.primary_palette = theme_color
if theme_style:=config.get("Preferences","theme_style"):
self.theme_cls.theme_style = theme_style
self.anime_screen = self.manager_screens.get_screen("anime screen")
self.search_screen = self.manager_screens.get_screen("search screen")
return self.manager_screens
@@ -73,7 +87,30 @@ class AniXStreamApp(MDApp):
view.manager_screens = self.manager_screens
view.name = name_screen
self.manager_screens.add_widget(view)
# others
def build_config(self, config):
config.setdefaults('Preferences', {
'theme_color': 'Cyan',
"theme_style": "Dark",
"downloads_dir":"."
})
def build_settings(self,settings:Settings):
settings.add_json_panel("Settings",self.config,"settings.json")
def on_config_change(self, config, section, key, value):
if section=="Preferences":
match key:
case "theme_color":
if value in themes_available:
self.theme_cls.primary_palette = value
else:
config.set("Preferences","theme_color","Cyan")
config.write()
case "theme_style":
self.theme_cls.theme_style = value
def search_for_anime(self,search_field,**kwargs):
if self.manager_screens.current != "search screen":
self.manager_screens.current = "search screen"
@@ -98,4 +135,6 @@ class AniXStreamApp(MDApp):
self.queue.put(stream_func)
if __name__ == "__main__":
# try:
AniXStreamApp().run()
# except: