Exemple #1
0
        public albumInfo extractAlbumInfo(string albumUrl)
        {
            string    respHtml  = "";
            albumInfo albumInfo = new albumInfo();

            albumInfo.url = albumUrl;

            respHtml = crl.getUrlRespHtml(albumUrl, stHtmlCharset);

            //http://www.songtaste.com/album/570665
            //<h1 class="h1user">嘟藥婞麸</h1>
            //<p class="mid_tit">文文收藏 聆听纯音<p>

            //http://www.songtaste.com/album/481886
            //<h1 class="h1user">//+Tu.Ren"娜蒂亚"</h1>
            //<p class="mid_tit">娜蒂亚回归ST赞歌<p>

            string mid_tit;

            if (crl.extractSingleStr(@"<p\s+?class=""mid_tit"">(?<mid_tit>.+?)<p>", respHtml, out mid_tit))
            {
                albumInfo.name = crl.removeInvChrInPath(mid_tit);
            }

            string h1user;

            if (crl.extractSingleStr(@"<h1\s+?class=""h1user"">(?<h1user>.+?)</h1>", respHtml, out h1user))
            {
                albumInfo.author = crl.removeInvChrInPath(h1user);
            }

            return(albumInfo);
        }
Exemple #2
0
        public String baiduTranslate(String strToTranslate, String fromLanguage, String toLanguage)
        {
            String translatedStr     = "";
            String encodedStr        = HttpUtility.UrlEncode(strToTranslate);
            String baiduTransBaseUrl = "http://openapi.baidu.com/public/2.0/bmt/translate?client_id=YEBdxswo4u7Oe21Y2LYcfz9I&q=";
            String baiduTransUrl     = baiduTransBaseUrl;

            baiduTransUrl += encodedStr;
            baiduTransUrl += "&from=" + fromLanguage; // source   language
            baiduTransUrl += "&to=" + toLanguage;     // to       language
            crifanLib cri = new crifanLib();          //使用crifanlib库

            try
            {
                String   transRetHtml = cri.getUrlRespHtml(baiduTransUrl);
                String[] str          = transRetHtml.Split(new String[] { "\"dst\"" }, StringSplitOptions.RemoveEmptyEntries);
                cri.extractSingleStr(":\"(.+?)\"}]}", str[1], out translatedStr);
                translatedStr = System.Text.RegularExpressions.Regex.Unescape(translatedStr);//解码escape形式的Unicode,即将反斜杠u加上数字的字符

                //获得fromLanguage语言
                int    index = transRetHtml.IndexOf("\",\"to\"");
                String fl    = transRetHtml.Substring(9, index - 9);
                tts  = "http://tts.baidu.com/text2audio?lan=" + fl;
                tts += "&ie=UTF-8&text=" + encodedStr;
            }

            catch { }
            return(translatedStr);
        }
Exemple #3
0
        public string googleTranslate(String strToTranslate, String fromLanguage, String toLanguage)
        {
            String translatedStr      = "";
            String encodedStr         = HttpUtility.UrlEncode(strToTranslate);
            String googleTransBaseUrl = "http://translate.google.cn/translate_a/single?client=t";
            String googleTransUrl     = googleTransBaseUrl;

            googleTransUrl += "&sl=" + fromLanguage; // source   language
            googleTransUrl += "&tl=" + toLanguage;   // to       language
            googleTransUrl += "&hl=zh-CN&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&q=";
            googleTransUrl += encodedStr;
            crifanLib cri = new crifanLib();        //使用crifanlib库

            try
            {
                String transRetHtml = cri.getUrlRespHtml(googleTransUrl);
                int    index1       = transRetHtml.IndexOf("\",,,");
                String str1         = transRetHtml.Substring(0, index1);
                int    index2       = str1.IndexOf(",[,,");
                if (index2 > 0)
                {
                    str1 = str1.Substring(3, index2 - 3);
                }
                else
                {
                    str1 = str1.Substring(3, str1.Length - 3);
                }
                String[] str = str1.Split(new String[] { "],[" }, StringSplitOptions.RemoveEmptyEntries);
                String   ss  = "";
                foreach (String s in str)
                {
                    if (cri.extractSingleStr("\"(.+?)\",\".+?\"", s, out ss))
                    {
                        translatedStr += ss;
                    }
                }

                String fl   = "en";
                String str2 = transRetHtml.Substring(index1 - 7, 8);
                cri.extractSingleStr("\"(.+?)\"", str2, out fl);
                tts  = "http://translate.google.cn/translate_tts?ie=UTF-8&tl=" + fl;
                tts += "&total=1&prev=input&q=";
            }
            catch { }
            return(translatedStr);
        }