-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # app.py # setup.py
- Loading branch information
Showing
6 changed files
with
165 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,110 @@ | ||
import subprocess | ||
import time | ||
from typing import TYPE_CHECKING | ||
|
||
from api.discord_presence import DiscordPresence | ||
from api.kodi import Kodi | ||
from updater import Updater | ||
from util.config import Configurations | ||
from util.system_tray import SysTray | ||
from util.web_interface import WebInterface | ||
|
||
running = True | ||
if TYPE_CHECKING: | ||
pass | ||
|
||
|
||
class App: | ||
play_icon = '\u25B6' | ||
pause_icon = '\u275A\u275A' | ||
running = True | ||
update_rate = 1 | ||
|
||
def __init__(self, configuration): | ||
self._config = configuration | ||
|
||
def stop(self): | ||
""" | ||
Stop the application from running. | ||
""" | ||
self.running = False | ||
|
||
def get_kodi_connection(self): | ||
""" | ||
Returns a new Kodi connection with recent configurations. | ||
:return: new Kodi instance | ||
:rtype: Kodi | ||
""" | ||
return Kodi(self._config.kodi_ip, self._config.kodi_port, self._config.kodi_username, | ||
self._config.kodi_password) | ||
|
||
def update_discord(self, discord: DiscordPresence, play_info: dict): | ||
""" | ||
Updates the Discord Rich Presence display. | ||
:param discord: Discord connection. | ||
:type discord: DiscordPresence | ||
:param play_info: Information about the movie/show. | ||
:type play_info: dict | ||
""" | ||
if play_info.get('title') is not None: | ||
discord.connect() | ||
icon = '{icon}'.format(icon=self.play_icon if play_info['playing'] else self.pause_icon) | ||
time_format = '{time[0]}:{time[1]:02d}:{time[2]:02d}' | ||
formatted_time = time_format.format(time=play_info['current_time']) | ||
formatted_total_time = time_format.format(time=play_info['total_time']) | ||
discord.update_status(details='{title}'.format(**play_info), large_image=play_info['type'], | ||
state='{icon} {time}/{total_time}'.format(icon=icon, time=formatted_time, | ||
total_time=formatted_total_time)) | ||
else: | ||
discord.disconnect() | ||
|
||
def run(self): | ||
""" | ||
Main running thread. | ||
""" | ||
discord = DiscordPresence(self._config.client_id) | ||
kodi = self.get_kodi_connection() | ||
while self.running: | ||
time.sleep(self.update_rate) | ||
if config.new_settings: | ||
kodi = self.get_kodi_connection() | ||
config.new_settings = False | ||
elif self.update_rate > 1: | ||
kodi = self.get_kodi_connection() # refresh settings, since it was put on timeout | ||
kodi_info = kodi.get_currently_playing_item() | ||
if not kodi_info['failed_connection']: | ||
self.update_rate = 1 | ||
self.update_discord(discord, kodi_info) | ||
else: | ||
self.update_rate = 30 | ||
|
||
|
||
if __name__ == '__main__': | ||
updater = Updater() | ||
if updater.is_there_an_update(): | ||
try: | ||
subprocess.Popen(['KoDiscord-updater.exe'], creationflags=subprocess.CREATE_NEW_CONSOLE) | ||
except FileNotFoundError: | ||
pass | ||
else: | ||
config = Configurations() | ||
kodiscord = App(config) | ||
sys_tray = SysTray(kodiscord, config) | ||
sys_tray.start() | ||
web = WebInterface(config) | ||
web.start() | ||
kodiscord.run() | ||
import json | ||
import subprocess | ||
import time | ||
from typing import TYPE_CHECKING | ||
|
||
from api.discord_presence import DiscordPresence | ||
from api.kodi import Kodi | ||
from updater import Updater | ||
from util.config import Configurations | ||
from util.system_tray import SysTray | ||
from util.web_interface import WebInterface | ||
|
||
running = True | ||
if TYPE_CHECKING: | ||
import datetime | ||
|
||
|
||
class App: | ||
play_icon = '\u25B6' | ||
pause_icon = '\u275A\u275A' | ||
running = True | ||
update_rate = 1 | ||
last_state = '{}' | ||
|
||
def __init__(self, configuration): | ||
self._config = configuration | ||
|
||
def stop(self): | ||
""" | ||
Stop the application from running. | ||
""" | ||
self.running = False | ||
|
||
def get_kodi_connection(self): | ||
""" | ||
Returns a new Kodi connection with recent configurations. | ||
:return: new Kodi instance | ||
:rtype: Kodi | ||
""" | ||
return Kodi(self._config.kodi_ip, self._config.kodi_port, self._config.kodi_username, | ||
self._config.kodi_password) | ||
|
||
def update_discord(self, discord: DiscordPresence, play_info: dict, remaining_time: 'datetime.timedelta' = None): | ||
""" | ||
Updates the Discord Rich Presence display. | ||
:param remaining_time: The remaining time timedelta if paused. | ||
:type remaining_time: datetime.timedelta | ||
:param discord: Discord connection. | ||
:type discord: DiscordPresence | ||
:param play_info: Information about the movie/show. | ||
:type play_info: dict | ||
""" | ||
if play_info.get('title') is not None: | ||
discord.connect() | ||
if play_info['playing']: | ||
icon = self.play_icon | ||
state = None | ||
end = play_info['end_time'] | ||
else: | ||
icon = self.pause_icon | ||
state = '{time_remaining} left'.format(icon=icon, time_remaining=time.strftime('%H:%M:%S', time.gmtime( | ||
remaining_time.seconds | ||
))) | ||
end = None | ||
discord.update_status(details='{icon} {title}'.format(icon=icon, **play_info), | ||
large_image=play_info['type'], | ||
state=state, end=end) | ||
else: | ||
discord.disconnect() | ||
|
||
def run(self): | ||
""" | ||
Main running thread. | ||
""" | ||
discord = DiscordPresence(self._config.client_id) | ||
kodi = self.get_kodi_connection() | ||
while self.running: | ||
time.sleep(self.update_rate) | ||
if config.new_settings: | ||
kodi = self.get_kodi_connection() | ||
config.new_settings = False | ||
elif self.update_rate > 1: | ||
kodi = self.get_kodi_connection() # refresh settings, since it was put on timeout | ||
kodi_info = kodi.get_currently_playing_item() | ||
if not kodi_info['failed_connection']: | ||
remaining_time = kodi_info.pop('remaining_time') | ||
kodi_info_json = json.dumps(kodi_info) | ||
if self.last_state != kodi_info_json: | ||
if json.loads(self.last_state).get('playing') != json.loads(kodi_info_json).get('playing'): | ||
self.update_discord(discord, kodi_info, remaining_time) | ||
self.last_state = kodi_info_json | ||
|
||
|
||
if __name__ == '__main__': | ||
updater = Updater() | ||
if updater.is_there_an_update(): | ||
try: | ||
subprocess.Popen(['KoDiscord-updater.exe'], creationflags=subprocess.CREATE_NEW_CONSOLE) | ||
except FileNotFoundError: | ||
pass | ||
else: | ||
config = Configurations() | ||
kodiscord = App(config) | ||
sys_tray = SysTray(kodiscord, config) | ||
sys_tray.start() | ||
web = WebInterface(config) | ||
web.start() | ||
kodiscord.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import os.path | ||
from pathlib import Path | ||
|
||
from cx_Freeze import setup, Executable | ||
|
||
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__)) | ||
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6') | ||
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6') | ||
|
||
base = 'Win32GUI' | ||
|
||
kodiscord = Executable('app.py', base=base, icon='kodi-icon.ico', targetName="KoDiscord.exe") | ||
updater = Executable('updater.py', base=None, icon='kodi-icon.ico', targetName='KoDiscord-updater.exe') | ||
|
||
executables = [kodiscord, updater] | ||
|
||
packages = ['asyncio', 'idna', 'pypresence', 'requests', 'threading', 'typing', 'pystray', 'PIL', 'pkg_resources'] | ||
options = { | ||
'build_exe': { | ||
'packages': packages, | ||
'include_files': ['kodi-icon.ico', 'LICENSE', 'config.json', 'web', 'version', 'updater.bat'], | ||
'include_msvcr': True | ||
}, | ||
} | ||
version = Path('version').read_text().strip() | ||
|
||
setup( | ||
name="KoDiscord", | ||
options=options, | ||
version=version, | ||
author='Richard Hajdu', | ||
author_email='tuskone16@gmail.com', | ||
url='https://github.com/Tusky/KoDiscord', | ||
description='Sends your currently watched Movie or TV Show from Kodi to discord.', | ||
executables=executables | ||
) | ||
import os.path | ||
from pathlib import Path | ||
|
||
from cx_Freeze import setup, Executable | ||
|
||
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__)) | ||
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6') | ||
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6') | ||
|
||
base = 'Win32GUI' | ||
|
||
kodiscord = Executable('app.py', base=base, icon='kodi-icon.ico', targetName="KoDiscord.exe") | ||
updater = Executable('updater.py', base=None, icon='kodi-icon.ico', targetName='KoDiscord-updater.exe') | ||
|
||
executables = [kodiscord, updater] | ||
|
||
packages = ['asyncio', 'idna', 'pypresence', 'requests', 'threading', 'typing', 'pystray', 'PIL', 'pkg_resources'] | ||
options = { | ||
'build_exe': { | ||
'packages': packages, | ||
'include_files': ['kodi-icon.ico', 'LICENSE', 'web', 'version', 'updater.bat'], | ||
'include_msvcr': True | ||
}, | ||
} | ||
version = Path('version').read_text().strip() | ||
|
||
setup( | ||
name="KoDiscord", | ||
options=options, | ||
version=version, | ||
author='Richard Hajdu', | ||
author_email='tuskone16@gmail.com', | ||
url='https://github.com/Tusky/KoDiscord', | ||
description='Sends your currently watched Movie or TV Show from Kodi to discord.', | ||
executables=executables | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters