Skip to content

Commit

Permalink
switch yapf to 100 columns (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
aw-was-here committed Jun 3, 2023
1 parent 1d372a6 commit 8972525
Show file tree
Hide file tree
Showing 71 changed files with 1,207 additions and 2,184 deletions.
3 changes: 0 additions & 3 deletions .yapfignore

This file was deleted.

3 changes: 1 addition & 2 deletions NowPlaying.spec
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ for execname, execpy in executables.items():
binaries=[],
datas=[('nowplaying/resources/*', 'resources/'),
('nowplaying/templates/*', 'templates/')],
hiddenimports=ARTEXTRAS_MODULES + INPUT_MODULES +
RECOGNITION_MODULES,
hiddenimports=ARTEXTRAS_MODULES + INPUT_MODULES + RECOGNITION_MODULES,
hookspath=[('nowplaying/__pyinstaller')],
runtime_hooks=[],
excludes=[],
Expand Down
13 changes: 4 additions & 9 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def bootstrap(getroot): # pylint: disable=redefined-outer-name
with tempfile.TemporaryDirectory() as newpath:
bundledir = pathlib.Path(getroot).joinpath('nowplaying')
nowplaying.bootstrap.set_qt_names(domain=DOMAIN, appname='testsuite')
config = nowplaying.config.ConfigFile(bundledir=bundledir,
logpath=newpath,
testmode=True)
config = nowplaying.config.ConfigFile(bundledir=bundledir, logpath=newpath, testmode=True)
config.cparser.setValue('acoustidmb/enabled', False)
config.cparser.sync()
yield config
Expand All @@ -81,20 +79,17 @@ def clear_old_testsuite():
qsettingsformat = QSettings.NativeFormat

nowplaying.bootstrap.set_qt_names(appname='testsuite')
config = QSettings(qsettingsformat, QSettings.SystemScope,
QCoreApplication.organizationName(),
config = QSettings(qsettingsformat, QSettings.SystemScope, QCoreApplication.organizationName(),
QCoreApplication.applicationName())
config.clear()
config.sync()

cachedir = pathlib.Path(
QStandardPaths.standardLocations(QStandardPaths.CacheLocation)[0])
cachedir = pathlib.Path(QStandardPaths.standardLocations(QStandardPaths.CacheLocation)[0])
if 'testsuite' in cachedir.name and cachedir.exists():
logging.info('Removing %s', cachedir)
shutil.rmtree(cachedir)

config = QSettings(qsettingsformat, QSettings.UserScope,
QCoreApplication.organizationName(),
config = QSettings(qsettingsformat, QSettings.UserScope, QCoreApplication.organizationName(),
QCoreApplication.applicationName())
config.clear()
config.sync()
Expand Down
6 changes: 2 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def get_release_data():

extlinks = {
'stabledownloadlink':
(f'{basedownload}/{stablerelease}/NowPlaying-{stablerelease}-%s.zip',
'%s'),
'rcdownloadlink':
(f'{basedownload}/{rcrelease}/NowPlaying-{rcrelease}-%s.zip', '%s')
(f'{basedownload}/{stablerelease}/NowPlaying-{stablerelease}-%s.zip', '%s'),
'rcdownloadlink': (f'{basedownload}/{rcrelease}/NowPlaying-{rcrelease}-%s.zip', '%s')
}
3 changes: 1 addition & 2 deletions nowplaying/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def actualmain(beam=False): # pragma: no cover
if not nowplaying.bootstrap.verify_python_version():
sys.exit(1)

config = nowplaying.config.ConfigFile(logpath=logpath,
bundledir=bundledir)
config = nowplaying.config.ConfigFile(logpath=logpath, bundledir=bundledir)
logging.getLogger().setLevel(config.loglevel)
logging.captureWarnings(True)
logging.debug('Using pidfile %s/%s', pid.piddir, pid.pidname)
Expand Down
4 changes: 1 addition & 3 deletions nowplaying/artistextras/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def calculate_delay(self):
''' determine a reasonable, minimal delay '''

try:
delay = self.config.cparser.value('settings/delay',
type=float,
defaultValue=10.0)
delay = self.config.cparser.value('settings/delay', type=float, defaultValue=10.0)
except ValueError:
delay = 10.0

Expand Down
46 changes: 17 additions & 29 deletions nowplaying/artistextras/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def __init__(self, config=None, qsettings=None):

def _find_discogs_releaselist(self, metadata):
try:
logging.debug('Fetching %s - %s', metadata['artist'],
metadata['album'])
logging.debug('Fetching %s - %s', metadata['artist'], metadata['album'])
resultlist = self.client.search(metadata['album'],
artist=metadata['artist'],
type='title').page(1)
Expand All @@ -44,8 +43,8 @@ def _find_discogs_releaselist(self, metadata):
return None

return next(
(result.artists[0] for result in resultlist if isinstance(
result, nowplaying.vendor.discogs_client.models.Release)),
(result.artists[0] for result in resultlist
if isinstance(result, nowplaying.vendor.discogs_client.models.Release)),
None,
)

Expand All @@ -54,23 +53,21 @@ def download(self, metadata=None, imagecache=None): # pylint: disable=too-many-

apikey = self.config.cparser.value('discogs/apikey')

if not apikey or not self.config.cparser.value('discogs/enabled',
type=bool):
if not apikey or not self.config.cparser.value('discogs/enabled', type=bool):
return None

# discogs basically works by search for a combination of
# artist and album so we need both
if not metadata or not metadata.get('artist') or not metadata.get(
'album'):
if not metadata or not metadata.get('artist') or not metadata.get('album'):
logging.debug('artist or album is empty, skipping')
return None

oldartist = metadata['artist']

if not self.client:
delay = self.calculate_delay()
self.client = nowplaying.vendor.discogs_client.Client(
f'whatsnowplaying/{self.version}', user_token=apikey)
self.client = nowplaying.vendor.discogs_client.Client(f'whatsnowplaying/{self.version}',
user_token=apikey)
self.client.set_timeout(connect=delay, read=delay)

artistresultlist = self._find_discogs_releaselist(metadata)
Expand Down Expand Up @@ -100,28 +97,23 @@ def download(self, metadata=None, imagecache=None): # pylint: disable=too-many-
metadata['artistfanarturls'] = []

for record in artistresultlist.images:
if record['type'] == 'primary' and record.get(
'uri150') and self.config.cparser.value(
'discogs/thumbnails', type=bool):
if record['type'] == 'primary' and record.get('uri150') and self.config.cparser.value(
'discogs/thumbnails', type=bool):
imagecache.fill_queue(config=self.config,
artist=oldartist,
imagetype='artistthumb',
urllist=[record['uri150']])

if record['type'] == 'secondary' and record.get(
'uri') and self.config.cparser.value(
'discogs/fanart', type=bool
) and record['uri'] not in metadata['artistfanarturls']:
if record['type'] == 'secondary' and record.get('uri') and self.config.cparser.value(
'discogs/fanart',
type=bool) and record['uri'] not in metadata['artistfanarturls']:
metadata['artistfanarturls'].append(record['uri'])

return metadata

def providerinfo(self): # pylint: disable=no-self-use
''' return list of what is provided by this plug-in '''
return [
'artistlongbio', 'artistthumbraw', 'discogs-artistfanarturls',
'artistwebsites'
]
return ['artistlongbio', 'artistthumbraw', 'discogs-artistfanarturls', 'artistwebsites']

def connect_settingsui(self, qwidget, uihelp):
''' pass '''
Expand All @@ -132,24 +124,20 @@ def load_settingsui(self, qwidget):
qwidget.discogs_checkbox.setChecked(True)
else:
qwidget.discogs_checkbox.setChecked(False)
qwidget.apikey_lineedit.setText(
self.config.cparser.value('discogs/apikey'))
qwidget.apikey_lineedit.setText(self.config.cparser.value('discogs/apikey'))

for field in ['bio', 'fanart', 'thumbnails', 'websites']:
func = getattr(qwidget, f'{field}_checkbox')
func.setChecked(
self.config.cparser.value(f'discogs/{field}', type=bool))
func.setChecked(self.config.cparser.value(f'discogs/{field}', type=bool))

def verify_settingsui(self, qwidget):
''' pass '''

def save_settingsui(self, qwidget):
''' take the settings page and save it '''

self.config.cparser.setValue('discogs/enabled',
qwidget.discogs_checkbox.isChecked())
self.config.cparser.setValue('discogs/apikey',
qwidget.apikey_lineedit.text())
self.config.cparser.setValue('discogs/enabled', qwidget.discogs_checkbox.isChecked())
self.config.cparser.setValue('discogs/apikey', qwidget.apikey_lineedit.text())

for field in ['bio', 'fanart', 'thumbnails', 'websites']:
func = getattr(qwidget, f'{field}_checkbox')
Expand Down
61 changes: 20 additions & 41 deletions nowplaying/artistextras/fanarttv.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def _fetch(self, apikey, artistid):
try:
baseurl = f'http://webservice.fanart.tv/v3/music/{artistid}'
logging.debug('fanarttv: calling %s', baseurl)
artistrequest = requests.get(f'{baseurl}?api_key={apikey}',
timeout=delay)
artistrequest = requests.get(f'{baseurl}?api_key={apikey}', timeout=delay)
except (
requests.exceptions.ReadTimeout, # pragma: no cover
urllib3.exceptions.ReadTimeoutError,
Expand All @@ -47,8 +46,7 @@ def download(self, metadata=None, imagecache=None): # pylint: disable=too-many-
''' download the extra data '''

apikey = self.config.cparser.value('fanarttv/apikey')
if not apikey or not self.config.cparser.value('fanarttv/enabled',
type=bool):
if not apikey or not self.config.cparser.value('fanarttv/enabled', type=bool):
return None

if not metadata or not metadata.get('artist'):
Expand All @@ -63,28 +61,23 @@ def download(self, metadata=None, imagecache=None): # pylint: disable=too-many-
return None

fnstr = nowplaying.utils.normalize(metadata['artist'])
logging.debug('got musicbrainzartistid: %s',
metadata['musicbrainzartistid'])
logging.debug('got musicbrainzartistid: %s', metadata['musicbrainzartistid'])
for artistid in metadata['musicbrainzartistid']:
artistrequest = self._fetch(apikey, artistid)
if not artistrequest:
return None

artist = artistrequest.json()

if artist.get('name') and nowplaying.utils.normalize(
artist['name']) in fnstr:
if artist.get('name') and nowplaying.utils.normalize(artist['name']) in fnstr:
logging.debug("fanarttv Trusting : %s", artist['name'])
else:
logging.debug("fanarttv Not trusting: %s vs %s",
artist.get('name'), fnstr)
logging.debug("fanarttv Not trusting: %s vs %s", artist.get('name'), fnstr)
continue

if artist.get('musicbanner') and self.config.cparser.value(
'fanarttv/banners', type=bool):
banner = sorted(artist['musicbanner'],
key=lambda x: x['likes'],
reverse=True)
if artist.get('musicbanner') and self.config.cparser.value('fanarttv/banners',
type=bool):
banner = sorted(artist['musicbanner'], key=lambda x: x['likes'], reverse=True)
imagecache.fill_queue(config=self.config,
artist=metadata['artist'],
imagetype='artistbanner',
Expand All @@ -93,32 +86,25 @@ def download(self, metadata=None, imagecache=None): # pylint: disable=too-many-
if self.config.cparser.value('fanarttv/logos', type=bool):
logo = None
if artist.get('hdmusiclogo'):
logo = sorted(artist['hdmusiclogo'],
key=lambda x: x['likes'],
reverse=True)
logo = sorted(artist['hdmusiclogo'], key=lambda x: x['likes'], reverse=True)
elif artist.get('musiclogo'):
logo = sorted(artist['musiclogo'],
key=lambda x: x['likes'],
reverse=True)
logo = sorted(artist['musiclogo'], key=lambda x: x['likes'], reverse=True)
if logo:
imagecache.fill_queue(config=self.config,
artist=metadata['artist'],
imagetype='artistlogo',
urllist=[x['url'] for x in logo])

if artist.get('artistthumb') and self.config.cparser.value(
'fanarttv/thumbnails', type=bool):
thumbnail = sorted(artist['artistthumb'],
key=lambda x: x['likes'],
reverse=True)
if artist.get('artistthumb') and self.config.cparser.value('fanarttv/thumbnails',
type=bool):
thumbnail = sorted(artist['artistthumb'], key=lambda x: x['likes'], reverse=True)
imagecache.fill_queue(config=self.config,
artist=metadata['artist'],
imagetype='artistthumb',
urllist=[x['url'] for x in thumbnail])

if self.config.cparser.value(
'fanarttv/fanart',
type=bool) and artist.get('artistbackground'):
if self.config.cparser.value('fanarttv/fanart',
type=bool) and artist.get('artistbackground'):
for image in artist['artistbackground']:
if not metadata.get('artistfanarturls'):
metadata['artistfanarturls'] = []
Expand All @@ -128,10 +114,7 @@ def download(self, metadata=None, imagecache=None): # pylint: disable=too-many-

def providerinfo(self): # pylint: disable=no-self-use
''' return list of what is provided by this plug-in '''
return [
'artistbannerraw', 'artistlogoraw', 'artistthumbraw',
'fanarttv-artistfanarturls'
]
return ['artistbannerraw', 'artistlogoraw', 'artistthumbraw', 'fanarttv-artistfanarturls']

def connect_settingsui(self, qwidget, uihelp):
''' pass '''
Expand All @@ -142,24 +125,20 @@ def load_settingsui(self, qwidget):
qwidget.fanarttv_checkbox.setChecked(True)
else:
qwidget.fanarttv_checkbox.setChecked(False)
qwidget.apikey_lineedit.setText(
self.config.cparser.value('fanarttv/apikey'))
qwidget.apikey_lineedit.setText(self.config.cparser.value('fanarttv/apikey'))

for field in ['banners', 'logos', 'fanart', 'thumbnails']:
func = getattr(qwidget, f'{field}_checkbox')
func.setChecked(
self.config.cparser.value(f'fanarttv/{field}', type=bool))
func.setChecked(self.config.cparser.value(f'fanarttv/{field}', type=bool))

def verify_settingsui(self, qwidget):
''' pass '''

def save_settingsui(self, qwidget):
''' take the settings page and save it '''

self.config.cparser.setValue('fanarttv/enabled',
qwidget.fanarttv_checkbox.isChecked())
self.config.cparser.setValue('fanarttv/apikey',
qwidget.apikey_lineedit.text())
self.config.cparser.setValue('fanarttv/enabled', qwidget.fanarttv_checkbox.isChecked())
self.config.cparser.setValue('fanarttv/apikey', qwidget.apikey_lineedit.text())

for field in ['banners', 'logos', 'fanart', 'thumbnails']:
func = getattr(qwidget, f'{field}_checkbox')
Expand Down
Loading

0 comments on commit 8972525

Please sign in to comment.