Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two issues with translations and condition construction #38

Closed
thof opened this issue Mar 1, 2015 · 13 comments
Closed

Two issues with translations and condition construction #38

thof opened this issue Mar 1, 2015 · 13 comments

Comments

@thof
Copy link

thof commented Mar 1, 2015

I found two issues:

  1. Translations: I'm using Manjaro with Polish locale and command pacmd list-sink-inputs actually returns on my system muted: tak or muted: nie ("tak" for "yes" and "nie" for "no") and as far as I can see you have hardcoded "yes" and "no" in pulsesink_mute method :) Currently I have no universal solution yet but I believe that we should read values for "yes" and "no" from system properties.
  2. For me condition construction is_ad = self.current_song != self.dbus.get_song_artist() + u" \u2013 " + self.dbus.get_song_title() doesn't work. I had to change it to
dbus_info = self.dbus.get_song_artist() + u" \u2013 " + self.dbus.get_song_title()
is_ad = self.current_song != dbus_info

in order to get it to work. I don't have experience in coding in Python so I cannot explain it but this is what I found under Python debugger.

@gmdfalk
Copy link
Owner

gmdfalk commented Mar 1, 2015

Thanks, i'll have a look at the translation issue soon. I don't know what the pulse devs were thinking when they used strings to represent the mute state. Maybe there's a way to get a boolean instead.

What you are saying about the equality check would mean that your python version compiles that code to different bytecode than mine, if i'm not mistaken. Are you sure that's the exact statement that failed?

Anyway, thanks for the issue report, i'll have a bit more time the coming weeks to fix some blockify issues.

@thof
Copy link
Author

thof commented Mar 11, 2015

Sorry for the long wait.

Regarding translations problem I think we can use the following approach:

import locale
import gettext

current_locale, encoding = locale.getdefaultlocale() # current_locale = 'pl_PL' in my case
pulseaudio_domain = 'pulseaudio'
localedir = gettext.find(pulseaudio_domain, languages=[current_locale])
localedir = localedir[:localedir.find('locale/')]+'locale' # not the best code
locale = gettext.translation(pulseaudio_domain, localedir=localedir, languages=[current_locale])
locale.install()
muted_true = _('yes')
muted_false = _('no')
print muted_true # tak
print muted_false # nie

The problem with equality check is strange. I'm quite sure that was an issue under debugger but now I cannot reproduce it so let's assume that was just my mistake.

@gmdfalk
Copy link
Owner

gmdfalk commented Mar 15, 2015

Hey,

thanks, that could certainly work. I have to admit though, i'm not a big fan of adding options, there are too many as it is.

What is the output of LANG=en_US.UTF-8 pacmd list-sink-inputs on your system?

gmdfalk pushed a commit that referenced this issue Mar 15, 2015
Fixed 3 issues: #36,#38, #39
New options:
substring_search (boolean, set to True if you want to be able to block
"Bloodhound Gang - Ivan Eth Nioj" with "Ivan". Risk for fals e
positives)
pacmd_muted_value (string, the localized value for "yes", needed to
parse the pacmd list-sink-inputs output correctly)
@gmdfalk
Copy link
Owner

gmdfalk commented Mar 15, 2015

Nevermind that last question about the LANG env variable. I simply added an option to blockify.ini called pacmd_muted_value. Set it to tak and let me know if it works.
Regards

@Feltzer
Copy link

Feltzer commented Mar 16, 2015

Have you tried using LC_ALL? We ran into the same localization issues on Spotify-AdKiller and setting this env variable worked for us.

@gmdfalk
Copy link
Owner

gmdfalk commented Mar 17, 2015

@Feltzer
Thanks for the hint. I read up on LC_ALL and in this instance it should be preferrable.

@thof
Could you try LC_ALL, too? Ideally, i'd like to know which, if any, of these commands produce english values for the muted key in the list-sink-inputs output.

LANG=en_US pacmd list-sink-inputs
LC_ALL=en_US pacmd list-sink-inputs
LC_ALL=C pacmd list-sink-inputs

Right now, LC_ALL=en_US is forced internally and temporarily for pacmd calls. But if that doesn't work i could revert to an option in blockify.ini where you can specify the "yes"-value explicitly.

@thof
Copy link
Author

thof commented Mar 18, 2015

Unfortunately none of these commands work, i.e. each of them returns values in Polish.

@gmdfalk
Copy link
Owner

gmdfalk commented Mar 18, 2015

I see. I will readd the option then. Check again in 15 minutes.

@thof
Copy link
Author

thof commented Oct 3, 2015

It seems that since Pulseaudio 7.0 only two values (yes and no) are fixed for "muted" property regardless of locale. Unfortunately this change breaks blockify on my system. Therefore I think that you should disable method install_locale.

@gmdfalk
Copy link
Owner

gmdfalk commented Oct 3, 2015

Are you sure this is what's breaking blockify for you?

If that's the case, it'd be a drag because pulseaudio 7.0 won't be available on all distributions for a while. If i were to fix your issue by assuming muted is always "yes" or "no", I'd break blockify for those with localized systems until they can upgrade to pulseaudio 7.0.

A quick fix for now would be to change
self.pulse_unmuted_value = unmuted_value in blockify.py to self.pulse_unmuted_value = "no".

I'd still like some confirmation on this issue. As soon as I have that, i'm sure there's a way to fix it without breaking backward compatibility. Worst case scenario, I'll have to check the pulseaudio version.

Regards

P.S.: Next time, I'd prefer if you opened a new issue and simply reference this one. It has been closed for more than half a year, after all. Less confusion, more visibility.

@gmdfalk gmdfalk reopened this Oct 3, 2015
@thof
Copy link
Author

thof commented Oct 3, 2015

I just downgraded pulseaudio and libpulse to 6.0 and I can confirm what I wrote in my previous post.

I think that checking PA version is not such a bad idea. Sample code that would handle this issue (initialize_pulse_unmuted_value):

pa_ver = subprocess.check_output("pulseaudio --version | awk '{print $2}'", shell=True)
if int(pa_ver[0]) < 7:
                self.install_locale()
                # Translate 'no' to the system locale.
                unmuted_value = _(unmuted_value)

@gmdfalk
Copy link
Owner

gmdfalk commented Oct 3, 2015

Thanks for checking and thanks for the code snippet.
Just a hint: You can sign up for Hacktoberfest, submit the pull request and be 1/5 for your cheesy T-Shirt ;). Ideally, you'd cherry-pick it from master to spotify-beta but that'd be the cherry on top.

Otherwise, I'll implement this tomorrow. I'm not a big fan of sketchy dependencies like checking for versions but at this point, blockify is a collection of hacks so we might as well add one more.

Regards

gmdfalk pushed a commit that referenced this issue Oct 5, 2015
Blockify now automatically tries to reconnect to Spotify if it was
restarted. It also suspends operation if Spotify is not running.

38: pulseaudio localization
58: periodically check for spotify process
gmdfalk pushed a commit that referenced this issue Oct 5, 2015
@gmdfalk
Copy link
Owner

gmdfalk commented Oct 5, 2015

Should be fixed on both master and spotify-beta

@gmdfalk gmdfalk closed this as completed Oct 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants