Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Need help] Convert LRC to SRT (lyric to subtitle)



  • Please log in to reply
10 replies to this topic
Cattleya
  • Members
  • 90 posts
  • Last active: Sep 13 2013 05:11 AM
  • Joined: 28 Sep 2011

Hi all

I tried to write a script to convert LRC to SRT but no success, because LRC also have an compressed format like that(highlighted text):

[ti:The Day You Went Away]
[ar:M2M]
[al:The Day You Went Away]
[by:HIM]

[00:02.00]歌名:The Day You Went Away
[00:06.00]Artist:M2M
[00:10.00]编辑:HIM
[00:19.66]Well I wonder could it be
[00:23.65]When I was dreaming about you baby
[00:27.24]You were dreaming of me
[00:29.15]Call me crazy,Call me blind
[00:33.72]To still be suffering is stupid after all of this time

[00:39.61][02:26.97]Did I lose my love to someone better
[00:43.31][02:30.36]And does she love you like I do
[00:46.10][02:33.36]I do, you know I really really do
[00:50.29][01:51.46][02:37.44]Well hey,So much I need to say
[00:53.98][01:55.15][02:41.05]Been lonely since the day
[00:56.38][01:57.94][02:43.53]The day you went away
[00:59.67][02:00.93][02:46.63]So sad but true
[01:01.86][02:03.32][02:49.02]For me there's only you
[01:04.26][02:05.52][02:51.61][03:11.97]Been crying since the day
[01:06.75][02:08.31][02:53.71][03:14.46]the day you went away

[01:20.81]I remember date and time
[01:24.92]September twenty second
[01:27.81]Sunday twenty five after nine
[01:30.80]In the doorway with your case
[01:35.30]No longer shouting at each other
[01:38.68]There were tears on our faces
[01:40.88]And we were letting go of something special
[01:44.47]Something we'll never have again
[01:47.56]I know, I guess I really really know
[02:56.90]Why do we never know what we've got till it's gone
[03:01.79]How could I carry on the day you went away
[03:07.08]Cause I've been missing you so much I have to say

Not raw format like:

[00:16.58]We were both young when I first saw you.
[00:20.27]I close my eyes and the flashback starts:
[00:23.94]I'm standing there on a balcony in summer air.
[00:32.63]See the lights, see the party, the ball gowns.
[00:36.38]See you make your way through the crowd
[00:40.00]and say hello;
[00:43.75]Little did I know
[00:48.48]That you were Romeo; you were throwing pebbles,
[00:52.20]And my daddy said, Stay away from Juliet.
[00:56.01]And I was crying on the staircase,
[00:58.73]begging you, 'Please, don't go.'
[01:03.39]And I said,
[01:04.51]Romeo, take me somewhere we can be alone.
[01:08.77]I'll be waiting; all there's left to do is run.
[01:12.79]You'll be the prince and I'll be the princess
[01:16.86]It's a love story - baby just say 'Yes.'
[01:24.91]So I sneak out to the garden to see you.
[01:29.09]We keep quiet 'cause we're dead if they knew.
[01:32.42]So close your eyes; escape this town for a little while.
[01:40.94]'Cause you were Romeo, I was a scarlet letter,
[01:44.64]And my daddy said Stay away from Juliet,
[01:48.37]But you were everything to me; I was begging you, 'Please, don't go,'
[01:55.87]And I said,
[01:57.12]Romeo, take me somewhere we can be alone.
[02:01.20]I'll be waiting; all there's left to do is run.
[02:05.21]You'll be the prince and I'll be the princess
[02:09.29]It's a love story - baby just say 'Yes.'
[02:13.65]Romeo save me; they're tryin' to tell me how to feel.
[02:17.33]This love is difficult, but it's real.
[02:21.54]Don't be afraid; we'll make it out of this mess.
[02:25.47]It's a love story - baby just say 'Yes.'
[02:44.89]I got tired of waiting,
[02:49.33]Wondering if you were ever comin' around.
[02:53.07]My faith in you was fading
[02:57.94]When I met you on the outskirts of town.
[03:01.44]And I said,
[03:02.25]Romeo save me - I've been feeling so alone.
[03:06.34]I keep waiting for you but you never come.
[03:10.37]Is this in my head I don't know what to think-
[03:13.97]He knelt to the ground and pulled out a ring and said,
[03:18.41]Marry me, Juliet. you'll never have to be alone.
[03:22.52]I love you and that's all I really know.
[03:26.52]I talked to your dad, go pick out a white dress;
[03:30.57]It's a love story - baby just say 'Yes.'
[03:38.13]Oh, oh.
[03:46.73]We were both young when I first saw you

I don't know how to solve this problem, anyone help me, please happy.png

I want a script that convert lyric file to subtitle format, like this example (raw format), I used a program named Subconv to convert LRC to SRT:

 

1
00:00:06,000 --> 00:00:08,000
Taylor Swift

2
00:00:08,000 --> 00:00:10,000
LOVE STORY

3
00:00:10,000 --> 00:00:12,000
(3:53)

4
00:00:16,000 --> 00:00:17,000
We were both

5
00:00:17,000 --> 00:00:18,000
young when I

6
00:00:18,000 --> 00:00:19,000
first saw you

7
00:00:19,000 --> 00:00:20,000
I close my eyes

8
00:00:20,000 --> 00:00:21,000
and the

9
00:00:21,000 --> 00:00:22,000
flashback

10
00:00:22,000 --> 00:00:23,000
starts

11
00:00:23,000 --> 00:00:24,000
I'm standing

12
00:00:24,000 --> 00:00:25,000
there

13
00:00:26,000 --> 00:00:27,000
on a

14
00:00:27,000 --> 00:00:28,000
balcony in

15
00:00:28,000 --> 00:00:30,000
summer air

16
00:00:32,000 --> 00:00:33,000
See the lights,

17
00:00:33,000 --> 00:00:34,000
see the party,

18
00:00:34,000 --> 00:00:36,000
the ball gowns

19
00:00:36,000 --> 00:00:37,000
See you make

20
00:00:37,000 --> 00:00:38,000
your way

21
00:00:38,000 --> 00:00:39,000
through the

22
00:00:39,000 --> 00:00:40,000
crowd

23
00:00:40,000 --> 00:00:41,000
And say hello,

24
00:00:43,000 --> 00:00:44,000
little did

25
00:00:44,000 --> 00:00:45,000
I know

26
00:00:48,000 --> 00:00:49,000
That you were

27
00:00:49,000 --> 00:00:50,000
Romeo

28
00:00:50,000 --> 00:00:51,000
You were

29
00:00:51,000 --> 00:00:52,000
throwing pebbles

 

 

But will not work with compressed format (highlighted):

1
00:00:02,000 --> 00:00:06,000
歌名:The Day You Went Away

2
00:00:06,000 --> 00:00:10,000
Artist:M2M

3
00:00:10,000 --> 00:00:19,660
编辑:HIM

4
00:00:19,660 --> 00:00:23,650
Well I wonder could it be

5
00:00:23,650 --> 00:00:27,240
When I was dreaming about you baby

6
00:00:27,240 --> 00:00:29,150
You were dreaming of me

7
00:00:29,150 --> 00:00:33,720
Call me crazy,Call me blind

8
00:00:33,720 --> 00:00:39,610
To still be suffering is stupid after all of this time


9
00:00:39,610 --> 00:00:43,310
[02:26.97]Did I lose my love to someone better

10
00:00:43,310 --> 00:00:46,100
[02:30.36]And does she love you like I do

11
00:00:46,100 --> 00:00:50,290
[02:33.36]I do, you know I really really do

12
00:00:50,290 --> 00:00:53,980
[01:51.46][02:37.44]Well hey,So much I need to say

13
00:00:53,980 --> 00:00:56,380
[01:55.15][02:41.05]Been lonely since the day

14
00:00:56,380 --> 00:00:59,670
[01:57.94][02:43.53]The day you went away

15
00:00:59,670 --> 00:01:01,860
[02:00.93][02:46.63]So sad but true

16
00:01:01,860 --> 00:01:04,260
[02:03.32][02:49.02]For me there's only you

17
00:01:04,260 --> 00:01:06,750
[02:05.52][02:51.61][03:11.97]Been crying since the day

18
00:01:06,750 --> 00:01:20,810
[02:08.31][02:53.71][03:14.46]the day you went away


19
00:01:20,810 --> 00:01:24,920
I remember date and time

20
00:01:24,920 --> 00:01:27,810
September twenty second

21
00:01:27,810 --> 00:01:30,800
Sunday twenty five after nine

22
00:01:30,800 --> 00:01:35,300
In the doorway with your case

23
00:01:35,300 --> 00:01:38,680
No longer shouting at each other

24
00:01:38,680 --> 00:01:40,880
There were tears on our faces

25
00:01:40,880 --> 00:01:44,470
And we were letting go of something special

26
00:01:44,470 --> 00:01:47,560
Something we'll never have again

27
00:01:47,560 --> 00:02:56,900
I know, I guess I really really know

28
00:02:56,900 --> 00:03:01,790
Why do we never know what we've got till it's gone

29
00:03:01,790 --> 00:03:07,080
How could I carry on the day you went away

I found a program (wrote in C language) can convert LRC to SRT cannot work with compressed format of lyric file, and even worse, it's not support Unicode, so it only can convert English lyric to subtitle. It is here, I also have its source code, hope this can help!

Subconv: http://code.google.c....2.zip&can=2&q=
Source code: http://code.google.c...rc.zip&can=2&q=

I really hope someone can help me, I really need a script like that because I want to use my lyric file with this script, this script will display subtitle on screen like Minilyrics program did(but not free at all). I want to use it with my music player to display lyrics on screen. I think it is possible, because Minilyrics program can display both raw and compressed LRC file very well, I think we can use some RegExReplace to do that.

Many thank!



kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

If all you want to do is remove the "[01:55.15]" and similar tags from the file you could do something like this. (I don't think this is what you actually want though. A true conversion from one file type to another would be very elaborate.)

Spoiler

"\[[\d:\.]+\]" in plain English:

\[                      A literal [

[\d:\.]+             One or more of any of the characters within the []    --->       \d any digit, : a colon, \. a literal period.

\]                      A literal ]

 

 

If this is accomplishing what you want, you could create a gui and drop files on it you wish to convert (GuiDropFiles).

I'm no expert, and I can't test it right now, but I think some players available for free will play .lrc files. I think the KMPlayer supports .lrc files.



Cattleya
  • Members
  • 90 posts
  • Last active: Sep 13 2013 05:11 AM
  • Joined: 28 Sep 2011

Hi Kon, thank you for help me :)

 

But that is not exactly what I really want, hard to describe but I hope you and may someone can understand:

 

First, a small example:

 

[00:39.61][02:26.97]Did I lose my love to someone better
[00:43.31][02:30.36]And does she love you like I do

 

How to use a RegEx to make it become:

 

[00:39.61]Did I lose my love to someone better

[02:26.97]Did I lose my love to someone better
[00:43.31]
And does she love you like I do

[02:30.36]And does she love you like I do

 

And then sort it to make it become (I mean sort by lyric time, I think i must sort it first, then I will use RegEx to convert it to SRT format):

 

[00:39.61]Did I lose my love to someone better
[00:43.31]
And does she love you like I do

[02:26.97]Did I lose my love to someone better

[02:30.36]And does she love you like I do

 

And then convert it to SRT format, finally, we have:

 

1
00:00:39,610 --> 00:00:43,310

Did I lose my love to someone better

 

2

00:00:43,310 --> 00:00:46,100
And does she love you like I do

3
00:02:26,970 --> 00:02:30,360

Did I lose my love to someone better

 

4

00:02:30,360 --> 00:02:33,360
And does she love you like I do

 

Just a example, hope someone can understand and help me solve my problem :) Many Thank! :)



Cattleya
  • Members
  • 90 posts
  • Last active: Sep 13 2013 05:11 AM
  • Joined: 28 Sep 2011

Sorry, but I need to bump this topic, I need people help :)



strobo
  • Members
  • 359 posts
  • Last active: Mar 10 2015 08:13 PM
  • Joined: 19 Jun 2012

If subconv works with uncompressed format you only need a "uncompressor" to make things work. This would reduce the missing lines of code by a fair amount, indeed helpers do not even need to know about SRT then.


Regards,
Babba

skwire
  • Moderators
  • 279 posts
  • Last active: Aug 12 2014 05:16 PM
  • Joined: 18 Jan 2006
Here's one method for converting compressed to uncompressed. It uses SKAN's wonderful StrX() function.

Spoiler


Cattleya
  • Members
  • 90 posts
  • Last active: Sep 13 2013 05:11 AM
  • Joined: 28 Sep 2011

Here's one method for converting compressed to uncompressed. It uses SKAN's wonderful StrX() function.

Spoiler

 

Thank you so much, skwire, with your help, I finally did it, here is my compeleted code that convert LRC (lyrics format) to SRT (subtilte format):

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines -1
;ListLines Off
#Hotstring SI ; Recommended for Hotstrings
#SingleInstance Ignore ; Good for all of my scripts
;#Warn  ; Recommended for catching common errors.

SplitPath, A_ScriptName,,,, ScriptName ;Remove extension from A_ScriptName
FileEncoding, UTF-8 ;Should be; CP1252 = ANSI
LoopNumber = 0
myText =
(
[00:02.00]歌名:The Day You Went Away
[00:06.00]Artist:M2M
[00:10.00]编辑:HIM
[00:19.66]Well I wonder could it be
[00:23.65]When I was dreaming about you baby
[00:27.24]You were dreaming of me
[00:29.15]Call me crazy,Call me blind
[00:33.72]To still be suffering is stupid after all of this time
[00:39.61][02:26.97]Did I lose my love to someone better
[00:43.31][02:30.36]And does she love you like I do
[00:46.10][02:33.36]I do, you know I really really do
[00:50.29][01:51.46][02:37.44]Well hey,So much I need to say
[00:53.98][01:55.15][02:41.05]Been lonely since the day
[00:56.38][01:57.94][02:43.53]The day you went away
[00:59.67][02:00.93][02:46.63]So sad but true
[01:01.86][02:03.32][02:49.02]For me there's only you
[01:04.26][02:05.52][02:51.61][03:11.97]Been crying since the day
[01:06.75][02:08.31][02:53.71][03:14.46]the day you went away
[01:20.81]I remember date and time
[01:24.92]September twenty second
[01:27.81]Sunday twenty five after nine
[01:30.80]In the doorway with your case
[01:35.30]No longer shouting at each other
[01:38.68]There were tears on our faces
[01:40.88]And we were letting go of something special
[01:44.47]Something we'll never have again
[01:47.56]I know, I guess I really really know
[02:56.90]Why do we never know what we've got till it's gone
[03:01.79]How could I carry on the day you went away
[03:07.08]Cause I've been missing you so much I have to say
)
 
Loop, Parse, myText, `n, `r
{
If ( A_LoopField != "" )
{
; Get actual lyric portion.
RegExMatch( A_LoopField, ".*](.*)$", Match )
; Crack lines for timing information.
myTime := N := ""
While myTime := StrX( A_LoopField, "[", N, 0, "]", 1, 0, N )
{
myList .= myTime . Match1 . "`n"
}
}
}
 
Sort, myList

Loop, Parse, myList, `n, `r
{
If ( A_LoopField != "" )
{
LoopNumber := LoopNumber + 1
RegExMatch( A_LoopField, "\[[\d:\.]+\]", Match%LoopNumber% ) ;Extract time
RegExMatch( A_LoopField, "(?<=]).+", MatchT%LoopNumber% ) ;Extract text
If LoopNumber > 1
{
LoopNumberP := LoopNumber - 1
StringReplace, Match%LoopNumber%, Match%LoopNumber%, [, 00:
StringReplace, Match%LoopNumber%, Match%LoopNumber%, ], 0
StringReplace, Match%LoopNumber%, Match%LoopNumber%, ., `,
StringReplace, Match%LoopNumberP%, Match%LoopNumberP%, [, 00:
StringReplace, Match%LoopNumberP%, Match%LoopNumberP%, ], 0
StringReplace, Match%LoopNumberP%, Match%LoopNumberP%, ., `,
myFinal .= "`n" . LoopNumberP . "`n" . Match%LoopNumberP% . " --> " . Match%LoopNumber% . "`n" . MatchT%LoopNumberP%
;MsgBox, % Match%N% Match%NP% MatchT%N%
;MsgBox, % Match%NP%
}
}

;myFinal .= A_Index . "`n" . 
;MsgBox, %Match%`n%Match2%`n%Matchx%

}

MsgBox, %myFinal% ; %LoopNumber% %LoopNumberP% 

;myList := RegExReplace(myList, "\[[\d:\.]+\]", "`n")

;MsgBox, % myList
 
; http://www.autohotkey.com/board/topic/47368-strx-auto-parser-for-xml-html/
StrX( H, BS="", BO=0, BT=1, ES="", EO=0, ET=1, ByRef N="" )
{
Return SubStr(H,P:=(((Z:=StrLen(ES))+(X:=StrLen(H))+StrLen(BS)-Z-X)?((T:=InStr(H,BS,0,((BO<0)?(1):(BO))))?(T+BT):(X+1)):(1))
,(N:=P+((Z)?((T:=InStr(H,ES,0,((EO)?(P+1):(0))))?(T-P+Z+(0-ET)):(X+P)):(X)))-P) ; v1.0-196c 21-Nov-2009 www.autohotkey.com/forum/topic51354.html
}

I know that my code, my method is awful, terrible, it use two RegExMatchs to extract time, lyric and six StringReplace to reformat time, but It work, hope someone can help me improve it, I will be very appriciate.

 

And p/s: skwire, Can you allow me to post this LRC2SRT Converter to Autohotkey.com's Script sub-forum ? I really want someone look and improve my code, at this time I think it is not good code at all. You help me wrote 99% of this converter, I think you really are the true author of this converter.

I will convert its format to function format later.



Alpha Bravo
  • Members
  • 1687 posts
  • Last active: Nov 07 2015 03:06 PM
  • Joined: 01 Sep 2011
Loop
	myText := RegExReplace( myText , "`am)(.+)(\[[^]]+\])(\V+)", "$1$3`n$2$3", count )
until !count
Sort, myText
MsgBox % myText


Cattleya
  • Members
  • 90 posts
  • Last active: Sep 13 2013 05:11 AM
  • Joined: 28 Sep 2011
Loop
	myText := RegExReplace( myText , "`am)(.+)(\[[^]]+\])(\V+)", "$1$3`n$2$3", count )
until !count
Sort, myText
MsgBox % myText

Thank you, your code is shorter and powerful, can you help me improve my code from this post, can you look at this line:

Loop, Parse, myList, `n, `r
{
If ( A_LoopField != "" )
{
LoopNumber := LoopNumber + 1
RegExMatch( A_LoopField, "\[[\d:\.]+\]", Match%LoopNumber% ) ;Extract time
RegExMatch( A_LoopField, "(?<=]).+", MatchT%LoopNumber% ) ;Extract text
If LoopNumber > 1
{
LoopNumberP := LoopNumber - 1
StringReplace, Match%LoopNumber%, Match%LoopNumber%, [, 00:
StringReplace, Match%LoopNumber%, Match%LoopNumber%, ], 0
StringReplace, Match%LoopNumber%, Match%LoopNumber%, ., `,
StringReplace, Match%LoopNumberP%, Match%LoopNumberP%, [, 00:
StringReplace, Match%LoopNumberP%, Match%LoopNumberP%, ], 0
StringReplace, Match%LoopNumberP%, Match%LoopNumberP%, ., `,
myFinal .= "`n" . LoopNumberP . "`n" . Match%LoopNumberP% . " --> " . Match%LoopNumber% . "`n" . MatchT%LoopNumberP%
;MsgBox, % Match%N% Match%NP% MatchT%N%
;MsgBox, % Match%NP%
}
}

;myFinal .= A_Index . "`n" . 
;MsgBox, %Match%`n%Match2%`n%Matchx%

}

And help me shorten my code, I think my code is not powerful, it have redudant code but my skill is not allow me to improve it :)

Many thank!



Alpha Bravo
  • Members
  • 1687 posts
  • Last active: Nov 07 2015 03:06 PM
  • Joined: 01 Sep 2011
✓  Best Answer

here you go short and complicated :-)

Loop
	MyList := RegExReplace( MyList , "`am)(.+)(\[[^]]+\])(\V+)", "$1$3`n$2$3", count )
until !count
Sort, MyList

Loop, parse, Mylist, `n, `r
	Mylist := RegExReplace( Mylist , "\[([^]]+)\](\V+)\v+\[([^]]+)\]", A_Index "`n00:$1,000 --> 00:$3,000`n$2`n[$3]",count,1)

Gui, add, edit,w600 r30 , % RegExReplace( Mylist , ".*\K\[\V+")
Gui, show
return


Cattleya
  • Members
  • 90 posts
  • Last active: Sep 13 2013 05:11 AM
  • Joined: 28 Sep 2011

 

here you go short and complicated :-)

Loop
	MyList := RegExReplace( MyList , "`am)(.+)(\[[^]]+\])(\V+)", "$1$3`n$2$3", count )
until !count
Sort, MyList

Loop, parse, Mylist, `n, `r
	Mylist := RegExReplace( Mylist , "\[([^]]+)\](\V+)\v+\[([^]]+)\]", A_Index "`n00:$1,000 --> 00:$3,000`n$2`n[$3]",count,1)

Gui, add, edit,w600 r30 , % RegExReplace( Mylist , ".*\K\[\V+")
Gui, show
return

Thank you, you saved my life :)