QMPlay2 icon indicating copy to clipboard operation
QMPlay2 copied to clipboard

YouTube search results show up translated (into French)?!

Open RJVB opened this issue 2 years ago • 12 comments

I don't know when this started, but since a few days I'm noticing that the titles of a good part of YouTube search results are translated - into French in my case. The info panel does show the original title.

My entire system is set to use English (except for LC_ADDRESS, LC_MONETARY and LC_TELEPHONE), including QMPlay2. So I'm guessing this is Google's doing, or else maybe yt-dlp. Whatever it is, I don't really appreciate getting translated results, so it'd be nice to figure out what's going on and how to circumvent it.

RJVB avatar Feb 19 '22 00:02 RJVB

I don't know, maybe your French IP address is detected in Google?

zaps166 avatar Feb 21 '22 18:02 zaps166

I don't know, maybe your French IP address is detected in Google?

That's what I'm afraid of too, but I don't get this "service" when I use a browser (even when I'm NOT logged).

An example: search for 8GI24uW1YTA . That's a US video entitled "VOX PATHFINDER 10 Guitar Combo Amplifier DEMO and REVIEW", yet in the search list it shows as "VOX PATHFINDER 10 DÉMO et REVUE de l'amplicateur combo pour guitare". A proper translation, but misleading because it suggests a French video.

I suppose there must be a way to tell Google to return only non-translated titles, or maybe they are already included in the search results?

RJVB avatar Feb 21 '22 20:02 RJVB

The mystery thickens.

Here's a test search (from my recent history :)): https://www.youtube.com/results?search_query=art%20tube%20mp

When I open it in a browser I get non-translated results, even when I'm not logged into my YT account (and the URL doesn't change). In QMPlay2 I get most if not all titles translated into French.

Evidently this is from the same machine.

RJVB avatar Mar 22 '22 12:03 RJVB

Use private mode, be sure you don't have any cookies in web browser. You can also track HTTP headers sent by web browser and QMPlay2 and compare.

zaps166 avatar Mar 22 '22 15:03 zaps166

You can also track HTTP headers sent by web browser and QMPlay2 and compare.

If I ever did that I forgot how :-/

Anyway, I have a hunch that this is in fact linked to the preferred language setting in the browser. And I found out that there are a number of search parameters that you can pass on to the YT API, including a language preference with the hl parameter. Annoyingly there's no "just give me whatever language the author used" setting but &hl=en seems to do almost that in practice. If I add this to the URL generated by `getYtUrl() I still get the original French titles if I use a French search pattern.

https://serpapi.com/google-languages

A bit curious if you ask me that they translate French to English if I don't ask for that, but NOT if I DO ask for it... I guess I better not complain ;)

RJVB avatar Mar 22 '22 16:03 RJVB

So...

As I thought, when I do this in Youtube::search():

            searchReply = net.start(getYtUrl(title, m_sortByIdx), QByteArray(), "Accept-Language: en\r\nCookie: \r\n");

I get the results as I'd like.

Idem when instead I do this in the NetworkReplyPriv ctor:

        m_rawHeaders(rawHeaders + QByteArrayLiteral("Accept-Language: en\r\n")),

That looks to be the most central/low-level location where one could set a default preferred language.

If the global settings are available at this level one could use the language setting made through the settings dialog here, instead of hardwiring a language or using an additional preference. If you can give me a few hints on how to do this I'll look into making a PR, if you like.

I thought you'd have to PREpend the language setting so that another setting already made via rawHeaders would override the default, but it appears that the 1st time the header occurs takes precedence (so you have to APpend the default).

RJVB avatar Mar 23 '22 14:03 RJVB

Me again ^^

It was quite simple actually:

diff --git a/src/qmplay2/NetworkAccess.cpp b/src/qmplay2/NetworkAccess.cpp
index 4cf405e73af5e6b57e480d3e6033d745aaedbe3e..4b43ce0d6138181737deaaa30d9f122235403eaa 100644
--- a/src/qmplay2/NetworkAccess.cpp
+++ b/src/qmplay2/NetworkAccess.cpp
@@ -65,7 +65,7 @@ public:
         m_networkReply(networkReply),
         m_url(url),
         m_postData(postData),
-        m_rawHeaders(rawHeaders),
+        m_rawHeaders(rawHeaders + "Accept-Language: " + QMPlay2Core.getLanguage().toLatin1() + "\r\n" ),
         m_customUserAgent(params.customUserAgent),
         m_maxSize(params.maxSize),
         m_retries(params.retries),

So simple that a PR seems overkill, in fact O:-)

RJVB avatar Mar 23 '22 18:03 RJVB

It means web browser enforces the language, otherwise Google detects your IP address (QMPlay2 case)?

zaps166 avatar Mar 25 '22 21:03 zaps166

It means web browser enforces the language, otherwise Google detects your IP address (QMPlay2 case)?

Yes, it looks like that.

I suppose you saw my proposed solution, which includes the user's language preference with any and all web/html requests. I can't think of any examples where you would not want that (if it's not possible to disable automatic translation).

RJVB avatar Mar 26 '22 00:03 RJVB

I'm not sure if it's a good idea to get UI text language here. Example: I use English, but I like Polish results. Maybe use OS localization or add to YouTube settings?

zaps166 avatar Apr 01 '22 16:04 zaps166

I was expecting that people would prefer to use a single language if they have the choice but sure, you could add an option to select the language (and let it default to the interface language?). Using the OS settings would be more appropriate for the GUI language, IMHO.

The question then becomes, what other features use the function that I modified? IOW, do you add a language setting for "internet search queries" or should there be one that's specific to YouTube?

RJVB avatar Apr 01 '22 20:04 RJVB

Looking at the headers sent via Firefox's Network monitor widget, I see

Accept-Language: en-GB,en;q=0.7,en-US;q=0.3

which corresponds to the language preference settings I have in my browser. How do I add this to the request made via QMPlay2 (and do you know if this can be shortened to just a single language, without the "q" parameter since I assume we don't want to implement an API to select a language preference hierarchy)?

RJVB avatar Oct 11 '22 08:10 RJVB