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 *pctl_player_name_new(const gchar *instance, PlayerctlSource source) {
PlayerctlPlayerName *player_name = g_slice_new(PlayerctlPlayerName); 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]); player_name->name = g_strdup(split[0]);
g_strfreev(split); g_strfreev(split);
player_name->instance = g_strdup(instance); 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 exact_match = (g_strcmp0(name, instance) == 0);
gboolean instance_match = gboolean instance_match = !exact_match && (g_str_has_prefix(instance, name) &&
!exact_match && (g_str_has_prefix(instance, name) && g_str_has_prefix(instance + strlen(name), "."));
g_str_has_prefix(instance + strlen(name), ".instance"));
if (exact_match || instance_match) { if (exact_match || instance_match) {
return 0; return 0;

View File

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

View File

@@ -33,7 +33,7 @@ class PlayerctlProcess:
break break
asyncio.get_event_loop().create_task(reader(proc.stdout)) 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): def running(self):
return self.proc.returncode is None return self.proc.returncode is None

View File

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

View File

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

View File

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