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

[Feature Request] Can you add an option to set the default lyrics source for Japan? #243

Closed
krono244 opened this issue Jul 13, 2024 · 7 comments · Fixed by #247
Closed

Comments

@krono244
Copy link

krono244 commented Jul 13, 2024

The default lyrics sources in Japan are not Musixmatch, Genius, or LRCLIB, so I often have trouble finding the lyrics I need. In Japan, the default source is PetitLyrics(プチリリ). Could you add an option to retrieve lyrics from PetitLyrics(プチリリ)? I would appreciate your consideration.

@asdfzxcvbn
Copy link
Collaborator

only if someone interested in it opens a PR

@asdfzxcvbn asdfzxcvbn closed this as not planned Won't fix, can't repro, duplicate, stale Jul 14, 2024
@yodaluca23
Copy link
Contributor

yodaluca23 commented Jul 14, 2024

So there's no official API, so reverse engineering is required.
I have some work on this, problem is I'm stuck...

Inspecting network requests, lyrics are gotten from https://petitlyrics.com/com/get_lyrics.ajax (encoded in base64) you can use the following cURL command
This seems to be the same format, regardless if logged in or not...

curl --request POST \
  --url https://petitlyrics.com/com/get_lyrics.ajax \
  --header 'Accept-Encoding: gzip, deflate, br' \
  --header 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  --header 'Cookie: COOKIE' \
  --header 'X-CSRF-Token: CSRFTOKEN' \
  --header 'X-Requested-With: XMLHttpRequest' \
  --data lyrics_id=LYRICSID

So, X-CSRF-Token is easy, for some reason, it can just be extracted from here https://petitlyrics.com/lib/pl-lib.js
LYRICSID is the ID of the song example https://petitlyrics.com/lyrics/3553432 > 3553432
The problem, and where I'm stuck is COOKIE.... You must send the request with the Cookie header obviously, cookies expire, so we can't just have the user extract one and use it... so we would have to have a way to fetch one... I have no idea how...
Not to mention I haven't even started reverse engineering the song search page... https://petitlyrics.com/search_lyrics

Also, some useful stuff I found:
https://github.com/icoxfog417/music_hack_day_onpasha/blob/master/api/petitlyrics.py
https://itsumen.com/kashi-bookmarklet/
https://itsumen.com/posts/2022-04-20-01/
https://greasyfork.org/en/scripts/2326-kasi-plain-text-lyrics-%E6%AD%8C%E8%A9%9E%E3%82%B3%E3%83%94%E3%83%BC-%E7%B4%94%E6%96%87%E6%9C%AC%E6%AD%8C%E8%A9%9E/code
https://greasyfork.org/en/scripts/40461-copy-lyrics-from-%E3%83%97%E3%83%81%E3%83%AA%E3%83%AA-%E6%AD%8C%E8%A9%9E%E3%82%BF%E3%82%A4%E3%83%A0/code

I am trying to see if the app is the same, the problem is its not available in US on iOS, and I don't have an Android so I have to use an emulator, but then the app doesn't trust the MITMProxy CA cert... augggghhh...

@yodaluca23
Copy link
Contributor

yodaluca23 commented Jul 15, 2024

Ok, Good News! For the cookie, you only need the PLSESSION cookie for it to succeed! This cookie is received without JS from the site, meaning we can get it simply by loading the website and then looking at our cookies!

Also https://petitlyrics.com/lib/pl-lib.js is unique to that cookie, so you need them to match each other for the request to succeed, knowing all of this I made a proof of concept Python Script (Python since I am far more comfortable with it than anything else...)
https://gist.github.com/yodaluca23/3958c29c2986841067324dd84258987b/948f2a36fd18776d0fc82e98d97bbba9c765fadc

It can access the website to be issued the cookie, and extract it. Using that same session extract X-CSRF-Token from the pl-lib.js, so that they match each other. Then perform the POST request, parse the JSON, decode the base64, and print each lyric. I will now work on reverse engineering the search function, convert it all to Swift, and try implementing it.

@yodaluca23
Copy link
Contributor

So I had to do some hacky things because the search request sends back a full webpage, so it has to scrape it with regex, hopefully, they don't update their site often (by the looks of it they don't) but I got it working, it does work with Genius FallBack too. They do apparently have time synced in their app, but I couldn't get it to work with MITMProxy, to see how it's done, I may add it in the future if I can figure it out.
Debs: https://github.com/yodaluca23/EeveeSpotify/actions/runs/9933936314
PR: #247

@krono244
Copy link
Author

Thank you for all the trial and error. I hope that feature will be implemented someday.

@asdfzxcvbn asdfzxcvbn reopened this Jul 15, 2024
@yodaluca23
Copy link
Contributor

@krono244 @whoeevee @asdfzxcvbn
I changed it to use the App's API, so it supports time-synced lyrics now, and doesn't need any hacky ways of extracting the best-matched song, cookies, or CSRF token!
#247 (comment)
Debs: https://github.com/whoeevee/EeveeSpotify/actions/runs/9963711566?pr=247

@whoeevee
Copy link
Owner

implemented with 4e6bf27
check out https://github.com/whoeevee/EeveeSpotify/actions/runs/9964968172

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

Successfully merging a pull request may close this issue.

4 participants