Esempio n. 1
0
        /// <summary>
        /// 从豆瓣获取歌词
        /// </summary>
        /// <param name="song">歌曲</param>
        /// <returns>歌词</returns>
        protected static Lyrics GetDoubanLyrics(Song song)
        {
            Parameters parameters = new Parameters();

            parameters["song_id"] = song.SongID;
            var url     = ConnectionBase.ConstructUrlWithParameters("http://music.douban.com/api/song/info", parameters);
            var conn    = new ConnectionBase();
            var content = conn.Get(url);

            if (string.IsNullOrEmpty(content))
            {
                return(null);
            }

            var songInfo = JsonHelper.Deserialize <SongInfo>(content);

            if (songInfo == null || string.IsNullOrEmpty(songInfo.Lyric))
            {
                return(null);
            }

            try
            {
                return(new Lyrics(songInfo.Lyric));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(null);
            }
        }
Esempio n. 2
0
        public List <ImPlayer.FM.Models.SearchResult> RemoteSearch(string keywords, int pageIndex)
        {
            Parameters parameters = new Parameters();

            parameters["start"]       = ((pageIndex - 1) * 15).ToString();
            parameters["search_text"] = keywords;
            string url = ConnectionBase.ConstructUrlWithParameters("http://music.douban.com/subject_search", parameters);

            ConnectionBase connection = new ConnectionBase(true);
            string         file       = string.Empty;

            try
            {
                file = connection.Get(url);
            }
            catch (Exception ex)
            {
                file = new ConnectionBase().Get("http://music.douban.com");
                file = new ConnectionBase().Get(url);
            }

            var searhResult = GetSearchItems(file);
            var previous    = GetPreviousPageLink(file);
            var next        = GetNextPageLink(file);

            return(searhResult.ToList());
        }
Esempio n. 3
0
        /// <summary>
        /// 根据频道和歌曲,得到歌曲列表
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="song"></param>
        /// <param name="type">n-New</param>
        /// <returns></returns>
        public List <Models.Song> GetSongList(Models.Channel channel, string type = "n")
        {
            Parameters parameters = new Parameters();

            parameters["channel"]  = channel.ID;
            parameters["from"]     = "mainsite";
            parameters["pt"]       = "0.0";
            parameters["kbps"]     = "128";
            parameters["formats"]  = "aac";
            parameters["alt"]      = "json";
            parameters["app_name"] = "radio_iphone";

            parameters["apikey"]      = "02646d3fb69a52ff072d47bf23cef8fd";
            parameters["client"]      = "s%3Amobile%7Cy%3AiOS%2010.2%7Cf%3A115%7Cd%3Ab88146214e19b8a8244c9bc0e2789da68955234d%7Ce%3AiPhone7%2C1%7Cm%3Aappstore";
            parameters["client_id"]   = "02646d3fb69a52ff072d47bf23cef8fd";
            parameters["icon_cate"]   = "xlarge";
            parameters["udid"]        = "b88146214e19b8a8244c9bc0e2789da68955234d";
            parameters["douban_udid"] = "b635779c65b816b13b330b68921c0f8edc049590";
            parameters["version"]     = "115";
            parameters["type"]        = type;
            parameters["channel"]     = channel.ID;

            string url = ConnectionBase.ConstructUrlWithParameters("https://api.douban.com/v2/fm/playlist", parameters);
            //string url = ConnectionBase.ConstructUrlWithParameters("https://douban.fm/j/v2/user_info?avatar_size=large", null);
            //获取列表
            string json         = new ConnectionBase().Get(url);
            var    playlistInfo = Framework.Common.Helpers.JsonHelper.Deserialize <Models.PlaylistInfo>(json);

            //将小图更换为大图
            foreach (var s in playlistInfo.SongList)
            {
                s.Picture = new Uri(s.Picture.ToString().Replace("/mpic/", "/lpic/").Replace("//otho.", "//img3."));
            }

            //去广告
            playlistInfo.SongList.RemoveAll(s => s.IsAd);

            return(playlistInfo.SongList);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取歌词
        /// </summary>
        /// <param name="artist">表演者</param>
        /// <param name="title">标题</param>
        public static Lyrics GetLyrics(string artist, string title)
        {
            if (string.IsNullOrEmpty(artist) && string.IsNullOrEmpty(title))
            {
                return(null);
            }
            if (title.ToLower().Contains("instrumental"))
            {
                return(null);
            }

            //获取所有可能的歌词
            Parameters parameters = new Parameters();

            parameters["Artist"] = Encode(artist);
            parameters["Title"]  = Encode(title);
            parameters["Flag"]   = "2";

            foreach (var server in servers)
            {
                string url  = ConnectionBase.ConstructUrlWithParameters("http://" + server + "/dll/lyricsvr.dll?sh", parameters);
                string file = new ConnectionBase().Get(url);

                //分析返回的XML文件
                LyricsResult result = null;
                try
                {
                    using (MemoryStream stream = new MemoryStream())
                        using (StreamWriter writer = new StreamWriter(stream))
                        {
                            writer.Write(file);
                            writer.Flush();
                            XmlSerializer serializer = new XmlSerializer(typeof(LyricsResult));
                            stream.Position = 0;
                            result          = (LyricsResult)serializer.Deserialize(stream);
                        }
                }
                catch { }
                if (result == null || result.Count == 0)
                {
                    continue;
                }

                //选出最合适的歌词文件
                LyricsItem selected = result[0];
                double     dist     = double.MaxValue;
                string     lArtist  = artist.ToLower();
                string     lTitle   = title.ToLower();
                foreach (var item in result)
                {
                    string iArtist = item.Artist.ToLower();
                    string iTitle  = item.Title.ToLower();
                    if (lArtist == iArtist && lTitle == iTitle)
                    {
                        selected = item;
                        break;
                    }
                    else if (lArtist.Length < 100 && lTitle.Length < 100 && iArtist.Length < 100 && iTitle.Length < 100)
                    {
                        int    dist1 = Distance(lArtist, iArtist);
                        int    dist2 = Distance(lTitle, iTitle);
                        double temp  = ((double)(dist1 + dist2)) / (lArtist.Length + lTitle.Length);
                        if (temp < dist)
                        {
                            dist     = temp;
                            selected = item;
                        }
                    }
                }

                //下载歌词文件
                Parameters parameters2 = new Parameters();
                parameters2["Id"]   = selected.Id.ToString();
                parameters2["Code"] = VerifyCode(selected.Artist, selected.Title, selected.Id);
                string url2  = ConnectionBase.ConstructUrlWithParameters("http://" + server + "/dll/lyricsvr.dll?dl", parameters2);
                string file2 = new ConnectionBase().Get(url2);

                //生成Lyrics的实例
                if (string.IsNullOrEmpty(file2))
                {
                    continue;
                }
                try
                {
                    return(new Lyrics(file2));
                }
                catch
                {
                    continue;
                }
            }

            return(null);
        }