Skip to content

Commit

Permalink
change instance delimiter to "."
Browse files Browse the repository at this point in the history
Rather than ".instance".

fixes #198
  • Loading branch information
acrisci committed Nov 4, 2020
1 parent 2fdbb1a commit d0a59e2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
7 changes: 3 additions & 4 deletions playerctl/playerctl-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions playerctl/playerctl-player.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/playerctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def printer(stream):
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
Expand Down
2 changes: 1 addition & 1 deletion test/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
36 changes: 20 additions & 16 deletions test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,43 @@ async def run(self):

@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()

Expand Down
4 changes: 2 additions & 2 deletions test/test_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ async def select_many(*players):
@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,
Expand Down

1 comment on commit d0a59e2

@xPMo
Copy link
Contributor

@xPMo xPMo commented on d0a59e2 Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please sign in to comment.