Update heuristics for getting artist/title from filename
This commit is contained in:
parent
b1a7dba986
commit
a1c66f33b5
@ -5,6 +5,14 @@ from i3pystatus.core.util import TimeWrapper
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_artist_title(input):
|
||||||
|
for sep in ('-', ' - '):
|
||||||
|
split = input.split(sep)
|
||||||
|
if len(split) == 2:
|
||||||
|
return split[0], split[1]
|
||||||
|
# fallback
|
||||||
|
return (input.split('-') + [''] * 2)[:2]
|
||||||
|
|
||||||
class Cmus(IntervalModule):
|
class Cmus(IntervalModule):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -16,7 +24,7 @@ class Cmus(IntervalModule):
|
|||||||
'color'
|
'color'
|
||||||
)
|
)
|
||||||
color = "#909090"
|
color = "#909090"
|
||||||
format = "{status} {song_elapsed}/{song_length} {artist}-{title}"
|
format = "{status} {song_elapsed}/{song_length} {artist} - {title}"
|
||||||
status_text = ''
|
status_text = ''
|
||||||
interval = 1
|
interval = 1
|
||||||
status = {
|
status = {
|
||||||
@ -68,14 +76,15 @@ class Cmus(IntervalModule):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fdict['stream']:
|
if fdict['stream']:
|
||||||
fdict['artist'], fdict['title'] = (
|
fdict['artist'], fdict['title'] = _extract_artist_title(fdict['stream'])
|
||||||
fdict['stream'].split('-') + [''] * 2)[:2]
|
|
||||||
|
|
||||||
elif not fdict['title']:
|
elif not fdict['title']:
|
||||||
_, filename = os.path.split(fdict['file'])
|
_, filename = os.path.split(fdict['file'])
|
||||||
filebase, _ = os.path.splitext(filename)
|
filebase, _ = os.path.splitext(filename)
|
||||||
fdict['artist'], fdict['title'] = (
|
fdict['artist'], fdict['title'] = _extract_artist_title(filebase)
|
||||||
filebase.split('-') + [''] * 2)[:2]
|
|
||||||
|
fdict['title'] = fdict['title'].strip()
|
||||||
|
fdict['artist'] = fdict['artist'].strip()
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": formatp(self.format, **fdict),
|
"full_text": formatp(self.format, **fdict),
|
||||||
|
Loading…
Reference in New Issue
Block a user