Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 1587

Bugs & Feature Suggestions • Re: [Friendly Resource] If PlayerType=Lyrics needs an update, LRCLIB can be used

$
0
0
I may take a deeper look at this [...] and maybe come up with a rudimentar sample code
Yes, I'm still very interested in this. [...] I really appreciate all the help I'm receiving on this one. :D
Alright, as promised, here's the - not yet fully polished - sample that demonstrates displaying the synced lyrics, the automatic (when playing) and manual (when stopped or paused) scrolling, as well as the karaoke highlighting of the currently played lyrics line:

Code:

[Variables]BackgroundW=400BackgroundH=600StrokeWidth=2CornerRadius=10Margin=10BackgroundColor=0,0,0,128StrokeColor=255,128,0,255InfoColor0=255,128,128,255InfoColor1=128,128,255,255InfoColor2=128,255,128,255InfoColor3=255,128,255,255ControlColor0=255,255,128,255ControlColor1=128,255,255,255ControlColor2=128,255,255,255ControlColor3=255,255,128,255LyricsColor=192,192,192,255KaraokeColor=255,255,255,255FontEffectColor=0,0,0,255FontColor=255,255,255,255FontFace=Monotype CorsivaFontSize=16StringEffect=ShadowFontPerc=0.75BarHPerc=0.80BarSolid=128,128,128,255BarColor=0,255,0,255ControlNum=4ControlGap=50Prev=[\x23EE]Stop=[\x23F9]Play=[\x23F5]Next=[\x23ED]Pause=[\x23F8]BoxColor=0,0,0,128Player=WinampOffset=0LineH=0Lines=0Line=0[Rainmeter]Update=1000AccurateText=1DynamicWindowSize=1---Measures---[Status]Group=PlayerGroupMeasure=NowPlayingPlayerName=#Player#PlayerType=StatusRegExpSubstitute=1Substitute="^0$":"Closed","^1$":"Open"TrackChangeAction=[!SetVariable Offset 0][!CommandMeasure SyncedLyrics "Update"][State]Group=PlayerGroupMeasure=NowPlayingPlayerName=[Status]PlayerType=StateRegExpSubstitute=1Substitute="^0$":"Stopped","^1$":"Playing","^2$":"Paused"IfCondition=(State=1)IfTrueAction=[!SetOption Play Text "#Pause#"]IfFalseAction=[!SetOption Play Text "#Play#"][Artist]Group=PlayerGroupMeasure=NowPlayingPlayerName=[Status]PlayerType=ArtistRegExpSubstitute=1Substitute="^$":"No Artist"[Album]Group=PlayerGroupMeasure=NowPlayingPlayerName=[Status]PlayerType=AlbumRegExpSubstitute=1Substitute="^$":"No Album"[Title]Group=PlayerGroupMeasure=NowPlayingPlayerName=[Status]PlayerType=TitleRegExpSubstitute=1Substitute="^$":"No Title"[Duration]Group=PlayerGroupMeasure=NowPlayingPlayerName=[Status]PlayerType=Duration[Position]Group=PlayerGroupMeasure=NowPlayingPlayerName=[Status]PlayerType=PositionOnChangeAction=[!UpdateMeasureGroup LinesGroup][Progress]Group=PlayerGroupMeasure=NowPlayingPlayerName=[Status]PlayerType=Progress[SyncedLyrics]Measure=WebParser;URL=file://#@#Madonna - Material Girl (original).json;URL=file://#@#Eminem - My Name Is (original).jsonURL=https://lrclib.net/api/get?artist_name=[&Artist]&album_name=[&Album]&track_name=[&Title]&duration=[&Duration:]UserAgent=Rainmeter 4.5.18 (https://github.com/rainmeter)RegExp=(?siU)[{,]"syncedLyrics":"(.*)"[,}]StringIndex=1;Debug=2UpdateRate=-1RegExpSubstitute=1Substitute='(?sU)\\"':'"',"(?sU)\\n":"#CRLF#"FinishAction=[!UpdateMeasureGroup LinesGroup]IfMatch=(?siU)\[\x005B][Position].+\RIfMatchAction=[!SetOption LyricsText "InlineSetting" "Color | #KaraokeColor#"][!SetOption LyricsText "InlinePattern" "(?siU)\[\x005B][Position].+\R"];IfNotMatchAction=[]IfMatchMode=1DynamicVariables=1[Lines]Group=LinesGroupMeasure=StringString=[SyncedLyrics]UpdateDivider=-1RegExpSubstitute=1Substitute="(?siU).+(?:\R|$)":"+1","(?siU)^(.*)$":"0\1","\\\d+":""OnUpdateAction=[!SetVariable Lines ([Lines])][!SetVariable LineH ([LyricsText:H]/([#Lines]=0?1:[#Lines]))]DynamicVariables=1[Line]Group=LinesGroupMeasure=StringString=[SyncedLyrics]UpdateDivider=-1RegExpSubstitute=1Substitute="(?siU)^(?|(.*)\[\x005B][Position].+(?:\R|$).*|((?:.+(?:\R|$)){#Line#}).*)$":"\1","\\\d+":"","(?siU).+(?:\R|$)":"+1","(?siU)^(.*)$":"0\1","\\\d+":""OnUpdateAction=[!SetVariable Line ([Position:]=0?0:[Line])][!SetVariable Offset ([#LineH]*[#Line])][!UpdateMeter *][!Redraw]DynamicVariables=1---Styles---[Texts]FontEffectColor=#FontEffectColor#FontColor=#FontColor#FontFace=#FontFace#FontSize=#FontSize#AntiAlias=1StringEffect=#StringEffect#---Meter---[Background]Meter=ShapeShape=Rectangle (#StrokeWidth#/2),(#StrokeWidth#/2),(#BackgroundW#-#StrokeWidth#),(#BackgroundH#-#StrokeWidth#),(#CornerRadius#),(#CornerRadius#) | Fill Color #BackgroundColor# | Stroke Color #StrokeColor# | StrokeWidth #StrokeWidth#UpdateDivider=-1[Information]Meter=StringMeterStyle=TextsStringAlign=CenterX=(#BackgroundW#/2)Y=(#Margin#)W=(#BackgroundW#-#Margin#*2)InlineSetting=Color | #InfoColor0#InlinePattern=^(?:\N*\R){0}(\N*)InlineSetting2=Color | #InfoColor1#InlinePattern2=^(?:\N*\R){1}(\N*)InlineSetting3=Color | #InfoColor2#InlinePattern3=^(?:\N*\R){2}(\N*)InlineSetting4=Color | #InfoColor3#InlinePattern4=^(?:\N*\R){3}(\N*)MeasureName=ArtistMeasureName2=AlbumMeasureName3=TitleMeasureName4=DurationMeasureName5=PositionMeasureName6=ProgressMeasureName7=StatusMeasureName8=StateText=%1#CRLF#%2#CRLF#%3#CRLF#%5 of %4 (%6%) - Player is %7 & %8DynamicVariables=1[ProgressBar]Meter=BarMeasureName=ProgressX=(#Margin#)Y=(#Margin#/2)RW=(#BackgroundW#-#Margin#*2)H=(#FontSize#*#BarHPerc#)BarColor=#BarColor#SolidColor=#BarSolid#BarOrientation=HorizontalLeftMouseDownAction=[!CommandMeasure Progress "SetPosition $MouseX:%$"][!UpdateMeasureGroup PlayerGroup][!UpdateMeter *][!Redraw]DynamicVariables=1[Prev]Meter=StringMeterStyle=TextsX=(#BackgroundW#/2-#ControlGap#/2*(#ControlNum#-1))Y=(#Margin#/2)RStringAlign=CenterFontColor=#ControlColor0#Text=#Prev#LeftMouseUpAction=[!CommandMeasure Status "Previous"][!UpdateMeasureGroup PlayerGroup][!UpdateMeter *][!Redraw][Stop]Meter=StringMeterStyle=TextsX=(#ControlGap#)rY=(0)rStringAlign=CenterFontColor=#ControlColor1#Text=#Stop#LeftMouseUpAction=[!CommandMeasure Status "Stop"][!UpdateMeasureGroup PlayerGroup][!UpdateMeter *][!Redraw][Play]Meter=StringMeterStyle=TextsX=(#ControlGap#)rY=(0)rStringAlign=CenterFontColor=#ControlColor2#Text=#Play#LeftMouseUpAction=[!CommandMeasure Status "PlayPause"][!UpdateMeasureGroup PlayerGroup][!UpdateMeter *][!Redraw][Next]Meter=StringMeterStyle=TextsX=(#ControlGap#)rY=(0)rStringAlign=CenterFontColor=#ControlColor3#Text=#Next#LeftMouseUpAction=[!CommandMeasure Status "Next"][!UpdateMeasureGroup PlayerGroup][!UpdateMeter *][!Redraw][LyricsBox]Meter=ImageX=(#Margin#)Y=(#Margin#/2)RW=(#BackgroundW#-#Margin#*2)H=(#BackgroundH#-[LyricsBox:Y]-#Margin#)SolidColor=#BoxColor#UpdateDivider=-1DynamicVariables=1[LyricsContainer]Meter=ImageX=([LyricsBox:X])Y=([LyricsBox:Y])W=([LyricsBox:W])H=([LyricsBox:H])SolidColor=0,0,0,255UpdateDivider=-1MouseScrollUpAction=[!SetVariable Offset (Clamp(#Offset#-#LineH#,0,Clamp([LyricsText:H]-[LyricsContainer:H],0,[LyricsText:H])))][!UpdateMeter LyricsContainer][!UpdateMeter LyricsText][!Redraw]MouseScrollDownAction=[!SetVariable Offset (Clamp(#Offset#+#LineH#,0,Clamp([LyricsText:H]-[LyricsContainer:H],0,[LyricsText:H])))][!UpdateMeter LyricsContainer][!UpdateMeter LyricsText][!Redraw]DynamicVariables=1[LyricsText]Container=LyricsContainerMeter=StringMeterStyle=TextsStringAlign=CenterFontColor=#LyricsColor#FontSize=(#FontSize#*#FontPerc#)X=([LyricsBox:W]/2)Y=(-Clamp(#Offset#,0,Clamp([LyricsText:H]-[LyricsContainer:H],0,[LyricsText:H])))W=([LyricsBox:W])MeasureName=SyncedLyricsText=%1DynamicVariables=1
Desktop_2024_08_08_20_32_42_103-ezgif.com-optimize.gif
It almost certainly has a few "bugs" or things I didn't bother to make perfect, but it's enough to get the general idea. It uses NowPlaying (not WebNowPlaying!) as the plugin and Winamp (not Spotify!) as the player, since that's what I use and could test, so it's entirely up to you - or anyone interested - to adapt it to another plugin or less supported player. In some areas, this might be a little challenge, for example replicating the TrackChangeAction option in NowPlaying, which WebNowPlaying doesn't yet have (here, concatenating the artist, track and duration in a String measure and comparing the outcome with the previous outcome of the same measure that was stored in a variable during the previous update of the measure could be one way to do it).

Regarding the commented lines from the code:
- I used the Debug=2 option in the [SyncedLyrics] measure to save the site's response on two test tracks, renamed and moved the file(s) accordingly, and parsed them as local files in the URL option in order to avoid excessively polling the site during the building and testing phase of the skin (this is wise to do both as a general rule when working with WebParser and also whenever working with sites that might block or ban you for using them too frequently)
- the IfNotMatchAction is left in case you want to do something else when the currently played line is not found in the lyrics text, since in this implementation both the scrolling (the ((?:.+(?:\R|$)){#Line#}).* part in the branch reset from [Line]) and the highlighting (the IfMatchAction) intentionally stay on the last #Line# value until another [Position] value is found in the lyrics string; this is done because otherwise (like the highlighting variant from the code here) the highlight will only stay on the currently played line for the duration of one [Position] update, i.e. just one second, which might not be enough time if the lyrics line is or lasts longer (it sometimes is inconvenient though, like when stopping the current track)

Obviously, you don't have to use this sample going forward, you could just add the needed things from it to the Mjdelro skin you're using. I do recommend testing stuff in this sample first though, simply because it's easier and it already works. Yes, you can use measures (like the [MeasureCountTotalLines], [MeasureCountCurrentLine] or [MeasureLineHeight] in the code from your previous reply) instead of variables (like the #Lines#, #Line# or #LineH# in the code from this sample) to store the said numerical values, I only used the latter cause it's more compact and takes less space in the code (I like one measure solutions). ;-)

Feel free to ask if you don't understand something - although judging by the quite correct way you already started to implement stuff in the past replies, I'm pretty sure you won't have many problems (besides occasional obstacles due to less Rainmeter experience) getting the principles in this code.

Statistics: Posted by Yincognito — Today, 7:22 pm



Viewing all articles
Browse latest Browse all 1587

Trending Articles