java 读取歌词并自动排序

   java 读取歌词并自动排序

========>支持歌词文件类型
1.例子:

[00:42]而我只是其中一个
[00:46][02:07]爱要越错越勇
[00:50][02:11]爱要肯定执着
[00:54][02:15]每一个单身的人得看透
[00:58][02:19]想爱就别怕伤痛
[01:04][02:26][03:26]找一个最爱的深爱的想爱的亲爱的人

2.例子:

[02:13.30]梦缠绵 情悠远哎
[02:19.31]啦…
[02:27.71]西湖的水 我的泪
[02:32.90]我情愿和你化做一团火焰
[02:36.80]啊…
[02:53.74]千年等一回 等一回啊
[03:02.44]千年等一回 我无悔啊


    public List ParsingLyric(File file){

        List lyric=new ArrayList();
        if(file.exists()){
            FileReader fileReader=null;
            BufferedReader reader=null;
            try {
                fileReader=new FileReader(file);
                reader=new BufferedReader(fileReader);
                String txt="";
                String reg="\\[(\\d{2}:\\d{2}\\.\\d{2})\\]|\\[\\d{2}:\\d{2}\\]";
                while((txt=reader.readLine())!=null){
                    if(txt.contains("[ti:")) {       // 歌曲信息
                        lyric.add("歌曲信息: "+txt.substring(txt.lastIndexOf(":")+1,txt.length()-1));
                    }else if (txt.contains("[ar:")) {// 歌手信息
                        lyric.add("歌手信息: "+txt.substring(txt.lastIndexOf(":")+1,txt.length()-1));
                    }else if (txt.contains("[al:")) {// 专辑信息
                        lyric.add("专辑信息: "+txt.substring(txt.lastIndexOf(":")+1,txt.length()-1));
                    }else if (txt.contains("[wl:")) {// 歌词作家
                        lyric.add("歌词作家: "+txt.substring(txt.lastIndexOf(":")+1,txt.length()-1));
                    }else if (txt.contains("[wm:")) {// 歌曲作家
                        lyric.add("歌曲作家: "+txt.substring(txt.lastIndexOf(":")+1,txt.length()-1));
                    }else if (txt.contains("[al:")) {// 歌词制作
                        lyric.add("歌词制作: "+txt.substring(txt.lastIndexOf(":")+1,txt.length()-1));
                    }
                    Pattern pattern=Pattern.compile(reg);
                    Matcher matcher=pattern.matcher(txt);
                    while(matcher.find()){
                        lyric.add(matcher.group(0).substring(1,matcher.group(0).lastIndexOf("]")).trim()+txt.substring(txt.lastIndexOf("]")+1).trim());
                    }
                }
                //reg="^\\d+$";
                for(int i=0;i
                    if(Pattern.matches("^\\d+$",lyric.get(i).substring(0,2))){
                        if(Pattern.matches("^\\d{2}:\\d{2}\\.\\d{1}$",lyric.get(i).substring(0,7))){
                            for(int j=0;j
                                if(Pattern.matches("^\\d+$",lyric.get(j).substring(0, 2))){
                                    if(Double.parseDouble(lyric.get(i).substring(0, 2))
                                        String temp=lyric.get(i);
                                        lyric.set(i, lyric.get(j));
                                        lyric.set(j, temp);
                                    }
                                    if(Double.parseDouble(lyric.get(i).substring(0, 2))==Double.parseDouble(lyric.get(j).substring(0, 2)) && Double.parseDouble(lyric.get(i).substring(3,8))
                                        String temp=lyric.get(i);
                                        lyric.set(i, lyric.get(j));
                                        lyric.set(j, temp);
                                    }
                                }
                            }
                        }else if(Pattern.matches("^\\d{2}:\\d{2}$",lyric.get(i).substring(0,5))){
                            for(int j=0;j
                                if(Pattern.matches("^\\d+$",lyric.get(j).substring(0, 2))){
                                    if(Integer.parseInt(lyric.get(i).substring(0, 2))
                                        String temp=lyric.get(i);
                                        lyric.set(i, lyric.get(j));
                                        lyric.set(j, temp);
                                    }
                                    if(Integer.parseInt(lyric.get(i).substring(0, 2))==Integer.parseInt(lyric.get(j).substring(0, 2)) && Integer.parseInt(lyric.get(i).substring(3,5))
                                        String temp=lyric.get(i);
                                        lyric.set(i, lyric.get(j));
                                        lyric.set(j, temp);
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                if(fileReader!=null){
                    try {
                        fileReader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if(reader!=null){
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }else{
            lyric=null;
        }    

        for(String s:lyric){
            System.out.println(s);
        }
        return lyric;
    }


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部