L
Loppan45
Guest
I’m trying to make a plugin that gathers synced lyrics for my music collection (if anyone knows of an already existing plugin that does this please let me know!). I’ve found an already existing python script which I was hoping to simply port as a plugin, but it’s built using requests and I can’t for the love of me understand how I’d go about changing it.
the (i think) only script that needs changing is base.py though some other scripts which interact with this one may of course also need changing.
The bridge between syncedlyrics and picard that I (chatGPT) have managed to write if that would be interesting:
If you think I’m stupid, I probably am because this is my first ever time doing anything in python (and programming in general) so any and all tips is greatly appreciated.
1 post - 1 participant
Read full topic
Continue reading...
the (i think) only script that needs changing is base.py though some other scripts which interact with this one may of course also need changing.
Code:
import sys
import os
plugin_dir = os.path.dirname(os.path.abspath(__file__))
syncedlyrics_dir = os.path.join(plugin_dir, "requests")
sys.path.append(plugin_dir)
import requests
from typing import Optional
class LRCProvider:
"""
Base class for all of the synced (LRC format) lyrics providers.
"""
session = requests.Session()
def __init__(self) -> None:
self.session.headers.update(
{
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
}
)
def get_lrc_by_id(self, track_id: str) -> Optional[str]:
"""
Returns the synced lyrics of the song in [LRC](https://en.wikipedia.org/wiki/LRC_(file_format)) format if found.
### Arguments
- track_id: The ID of the track defined in the provider database. e.g. Spotify/Deezer track ID
"""
raise NotImplementedError
def get_lrc(self, search_term: str) -> Optional[str]:
"""
Returns the synced lyrics of the song in [LRC](https://en.wikipedia.org/wiki/LRC_(file_format)) format if found.
"""
raise NotImplementedError
The bridge between syncedlyrics and picard that I (chatGPT) have managed to write if that would be interesting:
Code:
import sys
import os
import picard
from picard.metadata import register_track_metadata_processor
plugin_dir = os.path.dirname(os.path.abspath(__file__))
syncedlyrics_dir = os.path.join(plugin_dir, "syncedlyrics")
sys.path.append(plugin_dir)
from syncedlyrics import search
class SyncedLyricsPlugin(picard.plugins.Plugin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def add_synced_lyrics_tag(self, metadata):
# Search for synchronized lyrics using syncedlyrics module
lyrics = search(f"{metadata['title']} {metadata['artist']}") # Switched artist and track
if lyrics:
# Add synchronized lyrics tag
metadata['syncedlyrics'] = lyrics
class SyncedLyricsTrackMetadataProcessor(picard.plugins.TrackMetadataProcessor):
def __init__(self):
super().__init__()
def process_metadata(self, metadata, track, release):
plugin = SyncedLyricsPlugin()
plugin.add_synced_lyrics_tag(metadata)
return metadata
picard.plugins.register_file_processor(SyncedLyricsPlugin)
If you think I’m stupid, I probably am because this is my first ever time doing anything in python (and programming in general) so any and all tips is greatly appreciated.
1 post - 1 participant
Read full topic
Continue reading...