Added pypresence discord function

This commit is contained in:
Gand0rf
2024-12-02 19:08:51 -05:00
parent 30fa9851dd
commit ccad2435b0
3 changed files with 35 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ class Config(object):
"default_media_list_tracking": "None",
"downloads_dir": USER_VIDEOS_DIR,
"disable_mpv_popen": "True",
"discord": "False",
"episode_complete_at": "80",
"ffmpegthumbnailer_seek_time": "-1",
"force_forward_tracking": "true",
@@ -112,6 +113,9 @@ class Config(object):
self.disable_mpv_popen = self.configparser.getboolean(
"stream", "disable_mpv_popen"
)
self.discord = self.configparser.getboolean(
"general", "discord"
)
self.downloads_dir = self.configparser.get("general", "downloads_dir")
self.episode_complete_at = self.configparser.getint(
"stream", "episode_complete_at"
@@ -437,6 +441,12 @@ use_persistent_provider_store = {self.use_persistent_provider_store}
# 0 will disable recent anime tracking
recent = {self.recent}
config.py
# enable or disable discord activity updater
# if you want to enable it, please follow the lnik below to register the app with discord account
# https://discord.com/oauth2/authorize?client_id=1292070065583165512
discord = {self.discord}
[stream]
# the quality of the stream [1080,720,480,360]

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
import os
import random
import threading
from typing import TYPE_CHECKING
from click import clear
@@ -14,6 +15,7 @@ from yt_dlp.utils import sanitize_filename
from ...anilist import AniList
from ...constants import USER_CONFIG_PATH
from ...libs.discord import discord
from ...libs.fzf import fzf
from ...libs.rofi import Rofi
from ...Utility.data import anime_normalizer
@@ -54,6 +56,8 @@ def calculate_percentage_completion(start_time, end_time):
except Exception:
return 0
def discord_updater(show,episode,switch):
discord.discord_connect(show,episode,switch)
def media_player_controls(
config: "Config", fastanime_runtime_state: "FastAnimeRuntimeState"
@@ -510,6 +514,12 @@ def provider_anime_episode_servers_menu(
"[bold magenta] Episode: [/]",
current_episode_number,
)
# update discord activity for user
if config.discord == True:
switch = threading.Event()
discord_proc = threading.Thread(target=discord_updater, args=(provider_anime_title,current_episode_number,switch))
discord_proc.start()
# try to get the timestamp you left off from if available
start_time = config.watch_history.get(str(anime_id_anilist), {}).get(
"episode_stopped_at", "0"
@@ -592,6 +602,10 @@ def provider_anime_episode_servers_menu(
)
print("Finished at: ", stop_time)
# stop discord activity updater
if config.discord == True:
switch.set()
# update_watch_history
# this will try to update the episode to be the next episode if delta has reached a specific threshhold
# this update will only apply locally

View File

@@ -0,0 +1,11 @@
from pypresence import Presence
import time
def discord_connect(show, episode, switch):
presence = Presence(client_id = '1292070065583165512')
if not switch.is_set():
presence.update(
details = show,
state = "Watching "+episode
)
time.sleep(10)