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

Google search (needed also for azlyrics and genius) is not working in Europe #53

Open
DmitrySandalov opened this issue Jan 27, 2025 · 1 comment

Comments

@DmitrySandalov
Copy link
Contributor

Thanks for the tool.

I'm using lyrics-in-terminal==1.7.0 with the cycle-source option enabled.

When I start lyrics, it attempts to use different sources but eventually crashes with the following exception:

Unexpected exception occurred. (<class 'KeyError'>, KeyError('azlyrics'), <traceback object at 0x77dca0d92f40>) 'azlyrics'

Upon debugging, I found that the issue occurs in util.py when the application attempts to fetch Google search HTML:

def get_html(url, header=HEADER, cookies=COOKIES) -> str | Tuple[str, Exception]:
    ''' returns html text from given url
    '''
    try:
        resp = requests.get(url, headers=header)

Instead of the expected content, it receives a cookie consent banner:

Image

To bypass this, I manually approved the consent in my browser, extracted the SOCS cookie, and updated the lyrics code as follows:

util.py

HEADER = {
    'User-Agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch'
}
COOKIES = {
    'SOCS': 'CAESHAgBEhJnd3NfMjAyNTAxMjMtMF9SQzEaAnN2IAEaBgiAmdu8Bg'
}
<...>

def get_html(url, header=HEADER, cookies=COOKIES) -> str | Tuple[str, Exception]:
    ''' returns html text from given url
    '''
    try:
        resp = requests.get(url, headers=header, cookies=cookies)

However, I then encountered a screen instructing to enable JavaScript to continue searching:

Image

Since both azlyrics and genius depend on the initial HTML from Google, lyrics cannot find links in the received None HTML.

I tried various User-Agent strings with/without cookie 'CONSENT': 'PENDING+987' but couldn't resolve the issue.

To reproduce the issue, ensure that the IP address is located in Europe.

@DmitrySandalov
Copy link
Contributor Author

I created a fork that utilizes the Genius API.

To install:

pip install git+https://github.com/DmitrySandalov/lyrics-in-terminal@Use-Genius-API-(third-party-dependency)-instead-of-parsing-HTML

@Jugran What are your thoughts on using the API instead of HTML parsing?

Feel free to use my code.

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

1 participant