Skip to content

Commit

Permalink
More edge case fixes (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
aw-was-here committed Jun 8, 2023
1 parent eda6260 commit bb228d8
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 35 deletions.
13 changes: 7 additions & 6 deletions nowplaying/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__( # pylint: disable=too-many-arguments

self.iconfile = self.find_icon_file()
self.uidir = self.find_ui_file()
self.lastloaddate = None
self.lastloaddate = 0
self.setlistdir = None
self.striprelist = []

Expand Down Expand Up @@ -384,13 +384,14 @@ def getsetlistdir(self):

def getregexlist(self):
''' get the regex title filter '''
if not self.striprelist or self.lastloaddate < self.cparser.value('settings/lastsavedate'):
try:
try:
if self.lastloaddate == 0 or self.lastloaddate < self.cparser.value(
'settings/lastsavedate', type=int):
self.striprelist = [
re.compile(self.cparser.value(configitem))
for configitem in self.cparser.allKeys() if 'regex_filter/' in configitem
]
self.lastloaddate = self.cparser.value('settings/lastsavedate')
except re.error as error:
logging.error('Filter error with \'%s\': %s', error.pattern, error.msg)
self.lastloaddate = self.cparser.value('settings/lastsavedate', type=int)
except re.error as error:
logging.error('Filter error with \'%s\': %s', error.pattern, error.msg)
return self.striprelist
8 changes: 6 additions & 2 deletions nowplaying/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def setupsql(self):
def create_setlist(config=None, databasefile=None):
''' create the setlist '''

if not config or not databasefile:
logging.debug("config=%s / databasefile=%s", config is None, databasefile)
return

datestr = time.strftime("%Y%m%d-%H%M%S")
setlistpath = pathlib.Path(config.getsetlistdir())
logging.debug('setlistpath = %s', setlistpath)
Expand All @@ -354,8 +358,8 @@ def create_setlist(config=None, databasefile=None):
previoustrack.reverse()

setlistfn = setlistpath.joinpath(f'{datestr}.md')
max_artist_size = max(len(t.get('artist')) for t in previoustrack)
max_title_size = max(len(t.get('title')) for t in previoustrack)
max_artist_size = max(len(trk.get('artist', '')) for trk in previoustrack)
max_title_size = max(len(trk.get('title', '')) for trk in previoustrack)

max_artist_size = max(max_artist_size, len('ARTIST'))
max_title_size = max(max_title_size, len('TITLE'))
Expand Down
2 changes: 1 addition & 1 deletion nowplaying/imagecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def image_dl(self, imagedict):
threading.current_thread().name = 'ICFollower'
logging.getLogger('requests_cache').setLevel(logging.CRITICAL + 1)
logging.getLogger('aiosqlite').setLevel(logging.CRITICAL + 1)
session = requests_cache.CachedSession(self.httpcachefile)
session = requests_cache.CachedSession(str(self.httpcachefile))
cachekey = str(uuid.uuid4())

logging.debug("Downloading %s %s", cachekey, imagedict['url'])
Expand Down
6 changes: 4 additions & 2 deletions nowplaying/inputs/m3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ def _parse_extvdj(self, inputline):
vdjline = inputline.replace('#EXTVDJ:', '')

try:
metadata['title'] = EXTVDJ_TITLE_RE.match(vdjline).group(1)
if line := EXTVDJ_TITLE_RE.match(vdjline):
metadata['title'] = line.group(1)
except AttributeError:
pass

try:
metadata['artist'] = EXTVDJ_ARTIST_RE.match(vdjline).group(1)
if line := EXTVDJ_ARTIST_RE.match(vdjline):
metadata['artist'] = line.group(1)
except AttributeError:
pass

Expand Down
5 changes: 2 additions & 3 deletions nowplaying/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# pylint: disable=invalid-name
''' support for musicbrainz '''

import os
import sys

import logging
import logging.config
import logging.handlers
import os
import sys

import musicbrainzngs

Expand Down
3 changes: 2 additions & 1 deletion nowplaying/processes/trackpoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ async def stop(self):
''' stop trackpoll thread gracefully '''
logging.debug('Stopping trackpoll')
self.stopevent.set()
if self.icprocess:
if self.imagecache:
logging.debug('stopping imagecache')
self.imagecache.stop_process()
if self.icprocess:
logging.debug('joining imagecache')
self.icprocess.join()
if self.input:
Expand Down
63 changes: 43 additions & 20 deletions nowplaying/settingsui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class SettingsUI(QWidget): # pylint: disable=too-many-public-methods, too-many-
def __init__(self, tray, beam):

self.config = nowplaying.config.ConfigFile(beam=beam)
if not self.config:
logging.error('FATAL ERROR: Cannot get configuration!')
raise RuntimeError("Cannot get configuration")
self.tray = tray
super().__init__()
self.qtui = None
Expand All @@ -49,7 +52,8 @@ def __init__(self, tray, beam):
self.load_qtui()
if not self.config.iconfile:
self.tray.cleanquit()
self.qtui.setWindowIcon(QIcon(str(self.config.iconfile)))
if self.qtui:
self.qtui.setWindowIcon(QIcon(str(self.config.iconfile)))

def post_tray_init(self):
''' after the systemtray is fully loaded, do this '''
Expand Down Expand Up @@ -345,12 +349,12 @@ def _upd_win_quirks(self):
self.widgets['quirks'].slash_toback.setChecked(False)
self.widgets['quirks'].slash_toforward.setChecked(False)

if slashmode == 'toforward':
elif slashmode == 'toforward':
self.widgets['quirks'].slash_nochange.setChecked(False)
self.widgets['quirks'].slash_toback.setChecked(False)
self.widgets['quirks'].slash_toforward.setChecked(True)

if slashmode == 'toback':
elif slashmode == 'toback':
self.widgets['quirks'].slash_nochange.setChecked(False)
self.widgets['quirks'].slash_toback.setChecked(True)
self.widgets['quirks'].slash_toforward.setChecked(False)
Expand All @@ -364,16 +368,18 @@ def disable_web(self):
self.upd_win()
self.widgets['webserver'].enable_checkbox.setChecked(False)
self.upd_conf()
self.errormessage.showMessage('HTTP Server settings are invalid. Bad port?')
if self.errormessage:
self.errormessage.showMessage('HTTP Server settings are invalid. Bad port?')

def disable_obsws(self):
''' if the OBS WebSocket gets in trouble, this gets called '''
self.upd_win()
self.widgets['obsws'].enable_checkbox.setChecked(False)
self.upd_conf()
self.upd_win()
self.errormessage.showMessage(
'OBS WebServer settings are invalid. Bad port? Wrong password?')
if self.errormessage:
self.errormessage.showMessage(
'OBS WebServer settings are invalid. Bad port? Wrong password?')

def upd_conf(self):
''' update the configuration '''
Expand Down Expand Up @@ -599,7 +605,7 @@ def on_artistextras_clearcache_button(self):
return

cachedbfilepath = pathlib.Path(cachedbfile)
if cachedbfilepath.exists() and 'imagecache' in str(cachedbfile):
if cachedbfilepath.exists() and 'imagecache' in cachedbfile:
logging.debug('Deleting %s', cachedbfilepath)
cachedbfilepath.unlink()

Expand All @@ -616,23 +622,27 @@ def on_beamstatus_refresh_button(self):
@Slot()
def on_text_template_button(self):
''' file template button clicked action '''
self.uihelp.template_picker_lineedit(self.widgets['textoutput'].texttemplate_lineedit)
if self.uihelp:
self.uihelp.template_picker_lineedit(self.widgets['textoutput'].texttemplate_lineedit)

@Slot()
def on_discordbot_template_button(self):
''' discordbot template button clicked action '''
self.uihelp.template_picker_lineedit(self.widgets['discordbot'].template_lineedit)
if self.uihelp:
self.uihelp.template_picker_lineedit(self.widgets['discordbot'].template_lineedit)

@Slot()
def on_obsws_template_button(self):
''' obsws template button clicked action '''
self.uihelp.template_picker_lineedit(self.widgets['obsws'].template_lineedit)
if self.uihelp:
self.uihelp.template_picker_lineedit(self.widgets['obsws'].template_lineedit)

@Slot()
def on_html_template_button(self):
''' html template button clicked action '''
self.uihelp.template_picker_lineedit(self.widgets['webserver'].template_lineedit,
limit='*.htm *.html')
if self.uihelp:
self.uihelp.template_picker_lineedit(self.widgets['webserver'].template_lineedit,
limit='*.htm *.html')

def _filter_regex_load(self, regex=None):
''' setup the filter table '''
Expand Down Expand Up @@ -693,7 +703,8 @@ def on_cancel_button(self):
if self.tray:
self.tray.settings_action.setEnabled(True)
self.upd_win()
self.qtui.close()
if self.qtui:
self.qtui.close()

if not self.config.cparser.value('settings/input',
defaultValue=None) or not self.config.initialized:
Expand All @@ -714,14 +725,21 @@ def on_save_button(self):
if curbutton := self.widgets['source'].sourcelist.currentItem():
inputtext = curbutton.text().lower()

if not inputtext:
if self.errormessage:
self.errormessage.showMessage('No source has been chosen')
return

try:
self.config.plugins_verify_settingsui(inputtext, self.widgets)
except PluginVerifyError as error:
self.errormessage.showMessage(error.message)
if self.errormessage:
self.errormessage.showMessage(error.message)
return

if not self.widgets['source'].sourcelist.currentItem():
self.errormessage.showMessage('File to write is required')
if self.errormessage:
self.errormessage.showMessage('File to write is required')
return

if not self.config.cparser.value('control/beam', type=bool):
Expand All @@ -736,7 +754,8 @@ def on_save_button(self):
try:
self.settingsclasses[key].verify(self.widgets[key])
except PluginVerifyError as error:
self.errormessage.showMessage(error.message)
if self.errormessage:
self.errormessage.showMessage(error.message)
return

self.config.unpause()
Expand All @@ -751,17 +770,20 @@ def show(self):
if self.tray:
self.tray.settings_action.setEnabled(False)
self.upd_win()
self.qtui.show()
self.qtui.setFocus()
if self.qtui:
self.qtui.show()
self.qtui.setFocus()

def close(self):
''' close the system tray '''
self.tray.settings_action.setEnabled(True)
self.qtui.hide()
if self.qtui:
self.qtui.hide()

def exit(self):
''' exit the tray '''
self.qtui.close()
if self.qtui:
self.qtui.close()


def about_version_text(config, qwidget):
Expand All @@ -784,5 +806,6 @@ def load_widget_ui(config, name):
qwidget = loader.load(ui_file)
except RuntimeError as error:
logging.warning('Unable to load the UI for %s: %s', name, error)
return None
ui_file.close()
return qwidget

0 comments on commit bb228d8

Please sign in to comment.