change instance delimiter to "."

Rather than ".instance".

fixes #198
This commit is contained in:
Tony Crisci
2020-11-04 11:10:19 -05:00
parent 2fdbb1ad5e
commit d0a59e22de
6 changed files with 29 additions and 26 deletions

View File

@@ -134,7 +134,7 @@ PlayerctlSource pctl_bus_type_to_source(GBusType bus_type) {
PlayerctlPlayerName *pctl_player_name_new(const gchar *instance, PlayerctlSource source) {
PlayerctlPlayerName *player_name = g_slice_new(PlayerctlPlayerName);
gchar **split = g_strsplit(instance, ".instance", 2);
gchar **split = g_strsplit(instance, ".", 2);
player_name->name = g_strdup(split[0]);
g_strfreev(split);
player_name->instance = g_strdup(instance);
@@ -162,9 +162,8 @@ gint pctl_player_name_string_instance_compare(const gchar *name, const gchar *in
}
gboolean exact_match = (g_strcmp0(name, instance) == 0);
gboolean instance_match =
!exact_match && (g_str_has_prefix(instance, name) &&
g_str_has_prefix(instance + strlen(name), ".instance"));
gboolean instance_match = !exact_match && (g_str_has_prefix(instance, name) &&
g_str_has_prefix(instance + strlen(name), "."));
if (exact_match || instance_match) {
return 0;

View File

@@ -951,9 +951,9 @@ static gboolean playerctl_player_initable_init(GInitable *initable, GCancellable
return FALSE;
}
/* org.mpris.MediaPlayer2.{NAME}[.instance{NUM}] */
/* org.mpris.MediaPlayer2.{NAME}[.{INSTANCE}] */
int offset = strlen(MPRIS_PREFIX);
gchar **split = g_strsplit(bus_name + offset, ".instance", 2);
gchar **split = g_strsplit(bus_name + offset, ".", 2);
g_free(player->priv->player_name);
player->priv->player_name = g_strdup(split[0]);
g_strfreev(split);

View File

@@ -33,7 +33,7 @@ class PlayerctlProcess:
break
asyncio.get_event_loop().create_task(reader(proc.stdout))
# asyncio.get_event_loop().create_task(printer(proc.stderr))
asyncio.get_event_loop().create_task(printer(proc.stderr))
def running(self):
return self.proc.returncode is None

View File

@@ -21,7 +21,7 @@ async def test_commands(bus_address):
def get_called(cmd):
return getattr(mpris, f'{cmd.replace("-", "_")}_called')
playerctl = PlayerctlCli(bus_address)
playerctl = PlayerctlCli(bus_address, debug=True)
results = await asyncio.gather(*(playerctl.run(f'-p commands {cmd}')
for cmd in commands + setters))

View File

@@ -75,39 +75,43 @@ class MetadataTest:
@pytest.mark.asyncio
async def test_format(bus_address):
[mpris] = await setup_mpris('format-test', bus_address=bus_address)
TITLE = 'A Title'
ARTIST = 'An Artist'
ALBUM = 'An Album'
title = 'A Title'
artist = 'An Artist'
album = 'An Album'
player_name = 'format-test'
player_instance = f'{player_name}.instance123'
[mpris] = await setup_mpris(player_instance, bus_address=bus_address)
mpris.metadata = {
'xesam:title': Variant('s', TITLE),
'xesam:artist': Variant('as', [ARTIST]),
'xesam:title': Variant('s', title),
'xesam:artist': Variant('as', [artist]),
'xesam:escapeme': Variant('s', '<hi>'),
'xesam:album': Variant('s', ALBUM),
'xesam:album': Variant('s', album),
'mpris:length': Variant('x', 100000)
}
mpris.volume = 2.0
await mpris.ping()
playerctl = PlayerctlCli(bus_address)
test = MetadataTest(playerctl)
test.add('{{artist}} - {{title}}', f'{ARTIST} - {TITLE}')
test.add('{{artist}} - {{title}}', f'{artist} - {title}')
test.add("{{markup_escape(xesam:escapeme)}}", "&lt;hi&gt;")
test.add("{{lc(artist)}}", ARTIST.lower())
test.add("{{uc(title)}}", TITLE.upper())
test.add("{{uc(lc(title))}}", TITLE.upper())
test.add("{{lc(artist)}}", artist.lower())
test.add("{{uc(title)}}", title.upper())
test.add("{{uc(lc(title))}}", title.upper())
test.add('{{uc("Hi")}}', "HI")
test.add("{{mpris:length}}", "100000")
test.add(
'@{{ uc( "hi" ) }} - {{uc( lc( "HO" ) ) }} . {{lc( uc( title ) ) }}@',
f'@HI - HO . {TITLE.lower()}@')
test.add("{{default(xesam:missing, artist)}}", ARTIST)
test.add("{{default(title, artist)}}", TITLE)
f'@HI - HO . {title.lower()}@')
test.add("{{default(xesam:missing, artist)}}", artist)
test.add("{{default(title, artist)}}", title)
test.add('{{default("", "ok")}}', 'ok')
test.add('{{default("ok", "not")}}', 'ok')
test.add(' {{lc(album)}} ', ALBUM.lower())
test.add(' {{lc(album)}} ', album.lower())
test.add('{{playerName}} - {{playerInstance}}',
f'{player_name} - {player_instance}')
await test.run()

View File

@@ -28,13 +28,13 @@ def selector(bus_address):
@pytest.mark.asyncio
async def test_selection(bus_address):
s1 = 'selection1'
s1i = 'selection1.instance123'
s1i = 'selection1.i_123'
s2 = 'selection2'
s3 = 'selection3'
m4 = 'selection4'
m5 = 'selection5'
m6 = 'selection6'
s6i = 'selection6.instance2'
s6i = 'selection6.i_2'
any_player = '%any'
mpris_players = await setup_mpris(s1,