Skip to content

Commit

Permalink
Fix play to download, dependency and config migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
casualsnek committed Apr 27, 2023
1 parent 5f7453a commit b262672
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
18 changes: 13 additions & 5 deletions otsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, cfg_path=None):
self.platform = platform.system()
self.ext_ = ".exe" if self.platform == "Windows" else ""
self.version = 0.5
print('OTS Version : ', self.version)
self.__template_data = {
"version": 0.5,
"max_threads": 1,
Expand Down Expand Up @@ -50,6 +51,8 @@ def __init__(self, cfg_path=None):
with open(self.__cfg_path, "w") as cf:
cf.write(json.dumps(self.__template_data, indent=4))
self.__config = self.__template_data
self.__run_migration()
print('Config version: ', self.__config['version'])
os.makedirs(self.get("download_root"), exist_ok=True)
os.makedirs(os.path.dirname(self.get("log_file")), exist_ok=True)

Expand Down Expand Up @@ -104,20 +107,25 @@ def __run_migration(self):
while self.get('version') < self.version:
# Migrate v0.4 to v0.5
if self.get('version') == 0.4:
print('Curent Config version : ', 0.4)
accounts = self.__config['accounts'].copy()
new_accounts = []
for account in accounts:
# Assign UUID
acc_uuid = uuid.uuid4()
acc_uuid = str(uuid.uuid4())
session_dir = os.path.join(os.path.expanduser('~'), '.cache', 'casualOnTheSpot', 'sessions')
new_accounts.append([account[0], account[1], account[2], acc_uuid])
# Move saved sessions
os.rename(
os.path.join(session_dir, f"{account[0]}_GUZpotifylogin.json"),
os.path.join(session_dir, f"ots_login_{acc_uuid}.json")
)
try:
os.rename(
os.path.join(session_dir, f"{account[0]}_GUZpotifylogin.json"),
os.path.join(session_dir, f"ots_login_{acc_uuid}.json")
)
except:
print('Sessions could not be moved')
self.set_('accounts', new_accounts)
self.set_('version', 0.5)
print('Config migrated to version : ', 0.5)
self.update()


Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ librespot==0.0.8
music-tag==0.4.3
mutagen==1.46.0
packaging==23.1
Pillow==9.5.0
protobuf==3.20.1
pycryptodomex==3.17
PyOgg==0.6.14a1
PyQt5==5.15.9
PyQt5-Qt5==5.15.2
PyQt5-sip==12.12.1
PyQt5-stubs==5.15.6.0
pyxdg==0.28
requests==2.28.2
show-in-file-manager==1.1.4
Expand Down
14 changes: 11 additions & 3 deletions worker/media.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import queue
import time
from PyQt5.QtCore import QObject, pyqtSignal
from urllib3.exceptions import NewConnectionError, MaxRetryError

from otsconfig import config
from runtimedata import session_pool, get_logger
from utils.utils import get_now_playing_local
from utils.utils import get_now_playing_local, re_init_session

logger = get_logger("worker.media")

Expand All @@ -17,7 +20,8 @@ def run(self):
logger.info('Media watcher thread is running....')
while not self.__stop:
try:
session = session_pool[config.get("parsing_acc_sn") - 1]
selected_uuid = config.get('accounts')[config.get('parsing_acc_sn') - 1][3]
session = session_pool[selected_uuid]
spotify_url = get_now_playing_local(session)
spotify_url = spotify_url.strip() if spotify_url is not None else ""
if spotify_url != '' and spotify_url != self.last_url:
Expand All @@ -28,9 +32,13 @@ def run(self):
except FileNotFoundError:
logger.error('Background monitor failed ! Playerctl not installed')
break
except IndexError:
except (IndexError, KeyError):
logger.warning("Sessions not available yet !")
time.sleep(5)
except (OSError, queue.Empty, MaxRetryError, NewConnectionError, ConnectionError):
# Internet disconnected ?
logger.error('Search failed Connection error ! Trying to re init parsing account session ! ')
re_init_session(session_pool, selected_uuid, wait_connectivity=True, timeout=30)
self.finished.emit()

def stop(self):
Expand Down

0 comments on commit b262672

Please sign in to comment.