vlcsync icon indicating copy to clipboard operation
vlcsync copied to clipboard

Issue: Invalid literal for some Locales

Open gonsolo opened this issue 9 months ago • 8 comments

I started two vlc instances, then try to sync with vlcsync, but the following error occurs:

Cannot connect to 127.0.0.42:40101 (pid=12437) socket, cause: invalid literal for int() with base 10: '256,0'. Skipping. Enable debug for more info. See --help.

gonsolo avatar Mar 10 '25 10:03 gonsolo

The following hack works:

diff --git a/vlcsync/vlc.py b/vlcsync/vlc.py
index 552f29a..ad95d43 100644
--- a/vlcsync/vlc.py
+++ b/vlcsync/vlc.py
@@ -46,6 +46,8 @@ class Vlc:
     def volume(self) -> Optional[int]:
         vol = self.vlc_conn.cmd("volume")
         if vol.strip() != '':
+            locale.setlocale(locale.LC_ALL, locale.getlocale())
+            vol = locale.atof(vol)
             return int(vol)
         else:
             return None

gonsolo avatar Mar 10 '25 10:03 gonsolo

Thanks for contribution!

ok. Your first assumption was split(','), now locale. Why locale? We read output from another app (vlc) with another Locale AFIAK? How locale affected output from tcp socket?

IDK what mean each number here '256,0'. It just fraction of volume? Just on my machines it always integer.

Can you test? Just connect to vlc, change volume and see what volume returns.

➜ telnet 127.0.0.42 46489 #You port here from vlcsyc
Trying 127.0.0.42...
Connected to 127.0.0.42.
Escape character is '^]'.
VLC media player 3.0.9.2 Vetinari
Command Line Interface initialized. Type `help' for help.
> volume
0
> volume
120
>  

My always int as you see.

I assume put just:

>>> int(float(vol.replace(",",'.')))

Dirty but we cover all cases.

What OS and vlc version did you use?

mrkeuz avatar Apr 14 '25 01:04 mrkeuz

ok. Your first assumption was split(','), now locale. Why locale? We read output from another app (vlc) with another Locale AFIAK? How locale affected output from tcp socket?

My LANG is de_DE.UTF-8, your is probably C.

IDK what mean each number here '256,0'. It just fraction of volume? Just on my machines it always integer.

It's probably a float.

Can you test? Just connect to vlc, change volume and see what volume returns.

Trying ::1...
Connected to localhost.
Escape character is '^]'.
VLC media player 3.0.21 Vetinari
Password: 
Welcome, Master
> volume
0,0

Dirty but we cover all cases.

I'd prefer a proper solution.

What OS and vlc version did you use?

Latest Arch, vlc 3.0.21.

gonsolo avatar Apr 17 '25 17:04 gonsolo

I'd prefer a proper solution.

ok. Agree. Will try to test with different locales.

Thanks for testing! 🚀

mrkeuz avatar Apr 17 '25 21:04 mrkeuz

In the end reproduced issue locally. Yes it float. Decide just support both formats. I don't want to rely on to locale.

Motivation: Just imagine if vlc and vlcsync run with different locales. By some reason. I cannot get from vlc locale. At least it technically hard in cross-platform. So simple - allow multi-format. Will work in all imagined cases.

Cheers!

mrkeuz avatar Apr 20 '25 05:04 mrkeuz

https://en.wikipedia.org/wiki/Decimal_separator does list a small number of other decimal separators such as · and '.

I don't know if any of these alternative decimal separators are ever used by VLC, but to accommodate all possible uses cases you could create a function which identifies any non-numeric character and treats it as a decimal point. This would be fine so long as there is no thousand separator.

VLC's common.lua just uses tostring(n):gsub(",", ".", 1) as part of tostring() function for decimals number using a dot as decimal separator "regardless of the system locale". That implies that the VLC developers worked on the basis that VLC will not be producing any decimal separator other than , or ..

Et0h avatar Apr 25 '25 12:04 Et0h

@Et0h

other decimal separators such as · and '.

Good point.

but to accommodate all possible uses cases

OK. I will think about how it can be implemented more carefully. And what we can do with this. As you say we can get only thousand delimiters for Int and it can be only one. In this case non-digit cannot be considered as decimal delimiter.

mrkeuz avatar Apr 25 '25 17:04 mrkeuz

WIP: Must support all locales, NOT only '.',','

mrkeuz avatar May 05 '25 03:05 mrkeuz