LRC Lyrics Parser 0.0.2.0

Source: Internet
Author: User
1. Class Diagram


2. Source code List
/**
* FileName: Lrcanalyst.java
* Environment: Gnu/linux Ubuntu 7.04 + Eclipse 3.2 + JDK 1.6
* Function: Parse the main driver of LRC lyrics file
* Version: 0.0.2.0
* Author: 88250
* Date: 2007.4.27
* e-Mail & mdn:dl88250@gmail.com
* qq:845765
*/

Import Javax.swing.JFrame;

/**
* Test Lyrics Analysis Results
*/
public class Lrcanalyst
{
Public Lrcanalyst ()
{
JFrame frame = new JFrame ("LRC srcoll");

Frame.setbounds (600, 300, 400, 200);
Frame.setresizable (FALSE);
Frame.setdefaultcloseoperation (Jframe.exit_on_close);

Lrcscrollpane pane = new Lrcscrollpane ();
Frame.getcontentpane (). Add (pane);
Frame.setvisible (TRUE);
Pane.scroll ();
}

/**
* Main program Entry point
*
* @param args
* Command line arguments, no use here, for <code>null</code>
*/
public static void Main (string[] args)
{
New Lrcanalyst ();
}
}

/**
* FileName: Lrcanalystbase.java
* Environment: Gnu/linux Ubuntu 7.04 + Eclipse 3.2 + JDK 1.6
* Function: Parse LRC lyrics file
* Version: 0.0.2.0
* Author: 88250
* Date: 2007.4.22
* e-Mail & mdn:dl88250@gmail.com
* qq:845765
*/

Import java.io. * ;
Import Java.util. * ;

/**
* Lyrics Interpretation class, for the LRC lyrics file parsing
*/
public class Lrcanalystbase
{
/**
* LRC File Buffer
*/
private static Vector lyrics;

/**
* Formatted lyrics time and index, format reference Timeandindex class
*/
private static Vector Lrctimevalandindex;
/**
* Returns the index container for saving lyrics time and corresponding lyrics
* @return Lrctimeandindex time tag and lyrics index
*/
Public Vector Getlrctimevalandindex ()
{
return lrctimevalandindex;
}

/**
* The actual content of the lyrics
*/
private static Vector lyrciscontent;

/**
* The container that returns the actual content of the lyrics
* @return Lyrics actual content lyrciscontent
*/
Public Vector getlrccontent ()
{
return lyrciscontent;
}
/**
* Length of the time label, used to differentiate the time label format
*
* @see Private float Computetimetag (String timestr) method
*/
private int timetaglength;

/**
* True lyrics content begins with the offset of the beginning of the LRC text
*/
private int reallyrcisstartoffset;

/**
* Return the True lyrics content start to the offset of the beginning of the LRC text
* @return Offset
*/
public int Getreallrcstartoffset ()
{
return reallyrcisstartoffset;
}

/**
* Whether or not to determine the format of the lyrics tag, determine the words are <code>true</code>, otherwise it is <code>false</code>
* @see Private float Computetimetag (String timestr) method
*/
Private Boolean Isconfirmtimetagleng;

/**
* Default builder for lyric parser <br>
* Initialize lyrics file buffer fields
*/
Public Lrcanalystbase ()
{
Lyrics = new Vector ();
Lrctimevalandindex = new Vector ();
Lyrciscontent = new Vector ();
timetaglength = 0;
Isconfirmtimetagleng = false;
Reallyrcisstartoffset = 0;
}

/**
* Read text file content by line
* @param fileName
* File path and filename
* @throws IOException
*/
public void ReadFile (String fileName)
{
Try
{
InputStream r = new FileInputStream (fileName);
Bytearrayoutputstream byteout = new Bytearrayoutputstream ();
byte tmp[] = new byte [1024];
BYTE context[];

R.read (TMP);
Byteout.write (TMP);
context = Byteout.tobytearray ();
String str = new String (Context, "GBK"); Solve the problem of Chinese characters
String lyrcistext[] = Str.split ("");

for (int i = 0; i < lyrcistext.length i + +)
{
Lyrics.add (Lyrcistext[i]);
}
}
catch (IOException E)
{
E.printstacktrace ();
}
}

/**
* Show read all contents of LRC to console
*/
public void Displaylrccontent ()
{
for (int i = 0; i < lyrics.size (); i + +)
{
System.out.println (Lyrics.get (i));
}
}

/**
* Parse the lyrics file contents from the file buffer lyrics vector and save the results of the parsing <br>
* Resolution Method: <br>
* Step0. Split one line of content with '] ' to string[] <br>
* Step1. See if each row in the 3rd char is ': ' <br>
* Step2. See if the 6th char in each row is '. ' <br>
* Step3. Determines the line of lyrics, determines the format used for the LRC <br>
* <b> Note: At present, the format of the time tag is two, respectively, the length of 8 and 5 of the </b> <br>
* Step4. Loop until the lyrics buffer is over <br>
* <b> NOTE: This algorithm may have serious defects <b>
*
* @see about the time label format, refer to Timetag class
*/
public void Parselyrics ()
{
for (int i = 0; i < lyrics.size (); i + +)
{
String alinelyrics = (string) lyrics.get (i);
string[] PARTSLRC = Alinelyrics.split ("]");

Char Flag1 = 0;
Char flag2 = 0;
if (! Alinelyrics.isempty ())
{//Many people who make LRC files are not responsible for the format!!!!
Flag1 = Alinelyrics.charat (1);
Flag2 = Alinelyrics.charat (3);
}

if ((Alinelyrics.length () > 3)
&& (Flag1 >= && flag1 <= 57)//is the number
&& (': ' = = Flag2)]
{//OK for lyrics content line
if (! Isconfirmtimetagleng && alinelyrics.length () > 9)
{
if (Alinelyrics.charat (9) = = '])
{//Time label format with length 8
Timetaglength = 8;
}
else if (Alinelyrics.charat (6) = = '])
{//Time label format with length 5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.