<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    聚合 管理  

    Blog Stats

    News

    我使用新博客啦:
    http://www.linjunhai.com/
    大家到我的新博客上看看吧!

    隨筆分類(28)

    文章分類(4)

    隨筆檔案(53)

    文章檔案(4)

    相冊

    相關鏈接


    林俊海的博客

    超級大菜鳥,每天要自強!

    最近要搞這個,百度一下,發現有 php 版本的代碼,搞來翻譯一下。

    package org.iscripts.services;

    import java.io.IOException;
    import java.io.StringReader;
    import java.io.UnsupportedEncodingException;

    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.Element;
    import org.dom4j.Node;
    import org.dom4j.io.SAXReader;
    import org.iscripts.common.net.HttpGet;

    /**
    @author 混混(<b>ialvin.cn</b>) 廣東·普寧·里湖
    */
    public class LrcGet {
      
    public static void main(String[] args) throws Exception {
        System.out.println(query(
    "你把愛情給了誰""王強"));
      }

      
    public static String query(String title, String artist)
          
    throws DocumentException, NumberFormatException, IOException {
        String URL 
    = "http://ttlrcct.qianqian.com/dll/lyricsvr.dll?sh?Artist={ar}&Title={ti}&Flags=0";
        URL 
    = URL.replace("{ar}", encode(artist))
            .replace(
    "{ti}", encode(title));
        String result 
    = "";
        
    try {
          result 
    = HttpGet.get(URL);
        } 
    catch (Exception e) {
          e.printStackTrace();
        }
        
    // 需要 dom4j-1.6.1.jar , 使用可參考 dom4j 手冊
        Document doc = new SAXReader().read(new StringReader(result));
        
    // XML中可能包含多個匹配結果,我們只取一個
        Node n = doc.selectSingleNode("/result/lrc");
        
    if (n == null)
          
    return null;
        Element e 
    = (Element) n;
        result 
    = e.attributeValue("id");
        artist 
    = e.attributeValue("artist");
        title 
    = e.attributeValue("title");

        URL 
    = "http://ttlrcct2.qianqian.com/dll/lyricsvr.dll?dl?Id={id}&Code={code}";
        URL 
    = URL.replace("{id}", result).replace("{code}",
            verifyCode(artist, title, Integer.parseInt(result, 
    10)));
        
    return HttpGet.get(URL);
      }

      
    public static String verifyCode(String artist, String title, int lrcId)
          
    throws UnsupportedEncodingException {
        
    byte[] bytes = (artist + title).getBytes("UTF-8");
        
    int[] song = new int[bytes.length];
        
    for (int i = 0; i < bytes.length; i++)
          song[i] 
    = bytes[i] & 0xff;
        
    int intVal1 = 0, intVal2 = 0, intVal3 = 0;
        intVal1 
    = (lrcId & 0xFF00>> 8;
        
    if ((lrcId & 0xFF0000== 0) {
          intVal3 
    = 0xFF & ~intVal1;
        } 
    else {
          intVal3 
    = 0xFF & ((lrcId & 0x00FF0000>> 16);
        }
        intVal3 
    = intVal3 | ((0xFF & lrcId) << 8);
        intVal3 
    = intVal3 << 8;
        intVal3 
    = intVal3 | (0xFF & intVal1);
        intVal3 
    = intVal3 << 8;
        
    if ((lrcId & 0xFF000000== 0) {
          intVal3 
    = intVal3 | (0xFF & (~lrcId));
        } 
    else {
          intVal3 
    = intVal3 | (0xFF & (lrcId >> 24));
        }
        
    int uBound = bytes.length - 1;
        
    while (uBound >= 0) {
          
    int c = song[uBound];
          
    if (c >= 0x80)
            c 
    = c - 0x100;
          intVal1 
    = c + intVal2;
          intVal2 
    = intVal2 << (uBound % 2 + 4);
          intVal2 
    = intVal1 + intVal2;
          uBound 
    -= 1;
        }
        uBound 
    = 0;
        intVal1 
    = 0;
        
    while (uBound <= bytes.length - 1) {
          
    int c = song[uBound];
          
    if (c >= 128)
            c 
    = c - 256;
          
    int intVal4 = c + intVal1;
          intVal1 
    = intVal1 << (uBound % 2 + 3);
          intVal1 
    = intVal1 + intVal4;
          uBound 
    += 1;
        }
        
    int intVal5 = intVal2 ^ intVal3;
        intVal5 
    = intVal5 + (intVal1 | lrcId);
        intVal5 
    = intVal5 * (intVal1 | intVal3);
        intVal5 
    = intVal5 * (intVal2 ^ lrcId);
        
    return String.valueOf(intVal5);
      }

      
    private static String encode(String value) {
        
    if (value == null)
          value 
    = "";
        value 
    = value.replace(" """).replace("'""").toLowerCase();
        
    byte[] bytes = null;
        
    try {
          bytes 
    = value.getBytes("UTF-16LE");
        } 
    catch (UnsupportedEncodingException e) {
          e.printStackTrace();
          bytes 
    = value.getBytes();
        }
        
    return stringify(bytes);
      }

      
    final private static char[] digit = { '0''1''2''3''4''5''6',
          
    '7''8''9''A''B''C''D''E''F' };

      
    private static String stringify(byte[] bytes) {
        
    char[] str = new char[2];
        StringBuilder builder 
    = new StringBuilder();
        
    for (byte byteValue : bytes) {
          str[
    0= digit[(byteValue >>> 4& 0X0F];
          str[
    1= digit[byteValue & 0X0F];
          builder.append(str);
        }
        
    return builder.toString();
      }
    }

     其中 HttpGet.get(.....) 方法是 HTTP 抓取的功能,參考:
    http://www.iscripts.org/forum.php?mod=viewthread&tid=84

    ASP版的千千靜聽 LRC 歌詞查詢 請點這里

    原文鏈接:http://www.iscripts.org/forum.php?mod=viewthread&tid=85

     

     

     

    posted on 2011-05-02 16:50 林俊海 閱讀(1613) 評論(4)  編輯  收藏 所屬分類: JAVA天地

    評論

    # re: 從千千靜聽的歌詞服務器查詢音樂的 LRC 歌詞 [Java][未登錄] 2012-05-15 10:47 w
    請問org.iscripts.common.net.HttpGet;是什么事包?自己寫的還是網上下的?請發一份到1833664364@qq.com  回復  更多評論
      

    # re: 從千千靜聽的歌詞服務器查詢音樂的 LRC 歌詞 [Java] 2012-05-15 10:49 林俊海
    HttpGet 看這里
    http://www.iscripts.org/forum.php?mod=viewthread&tid=84

    @w
      回復  更多評論
      

    # re: 從千千靜聽的歌詞服務器查詢音樂的 LRC 歌詞 [Java][未登錄] 2012-05-15 13:10 w
    看到了,謝謝分享。  回復  更多評論
      

    # re: 從千千靜聽的歌詞服務器查詢音樂的 LRC 歌詞 [Java] 2014-01-10 18:17 兩天
    怎么用?。?br>
    寫成jS文件不顯示呢?  回復  更多評論
      

    主站蜘蛛池模板: 一本岛高清v不卡免费一三区| a级片免费在线播放| 国产免费久久精品99re丫y| 国产一精品一AV一免费| 人成午夜免费视频在线观看| 亚洲美女精品视频| 在线免费观看亚洲| 国产成人亚洲合集青青草原精品 | 日韩国产精品亚洲а∨天堂免| 免费精品人在线二线三线区别| 日韩精品电影一区亚洲| 亚洲av无码一区二区乱子伦as | www亚洲精品少妇裸乳一区二区| 亚洲精品国产精品| 18禁美女裸体免费网站| 老色鬼久久亚洲AV综合| 免费一级做a爰片久久毛片潮| 亚洲精品国产精品乱码不卡| 亚洲天堂免费在线| 国产乱子伦精品免费无码专区| 色吊丝免费观看网站| 亚洲人成人77777网站| 国产亚洲精品免费| 亚洲一区二区精品视频| 精品国产亚洲AV麻豆 | 免费中文字幕在线观看| 久久久精品国产亚洲成人满18免费网站| 亚洲色婷婷一区二区三区| 巨波霸乳在线永久免费视频| 亚洲中文无码亚洲人成影院| 亚洲国产精品成人一区| APP在线免费观看视频| 伊人久久亚洲综合影院首页| 亚洲精品视频免费观看| 18禁男女爽爽爽午夜网站免费| 亚洲AV无码一区二区三区网址| 亚洲中文久久精品无码ww16| 永久免费无码日韩视频| 免费一级毛片正在播放| 搡女人免费免费视频观看| 亚洲 欧洲 日韩 综合在线|