Exemple #1
0
        /// <summary>
        /// 获取分享音乐信息
        /// </summary>
        /// <param name="song">歌曲</param>
        /// <param name="channel">频道(或者DJ节目)</param>
        /// <returns></returns>
        internal static ShareSongInfo GetInfo(Song song, Channel channel)
        {
            string     songName    = song.Title;
            string     channelName = channel.Name;;
            string     url         = null;
            Parameters parameters  = new Parameters();

            parameters["cid"] = channel.IsRedHeart ? Channel.PersonalId : channel.Id;
            if (!song.IsAd)
            {
                parameters["start"] = song.SongId + "g" + song.SSId + "g" + channel.Id;
                //url = "http://douban.fm/?start=" + song.SongId + "g" + song.SSId + "g" + channel.Id + "&cid=" + channel.Id;
            }
            else
            {
                parameters["daid"] = song.SongId;
                //url = "http://douban.fm/?daid=" + song.SongId + "&cid=" + channel.Id;
            }
            if (channel.IsSpecial)
            {
                parameters["context"] = channel.Context;
                //url += "&context=" + channel.Context;
            }
            url = ConnectionBase.ConstructUrlWithParameters("http://douban.fm/", parameters);

            return(new ShareSongInfo(songName, song.Artist, channelName, url, song.Picture));
        }
Exemple #2
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 content = new ConnectionBase().Get(url);

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

            var songInfo = Json.JsonHelper.FromJson <Json.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);
            }
        }
        /// <summary>
        /// 搜索百度音乐
        /// </summary>
        /// <param name="keyword">关键词</param>
        private static void BaiduMusicSearch(string keyword)
        {
            Parameters parameters = new Parameters();

            parameters["key"] = keyword;
            string url = ConnectionBase.ConstructUrlWithParameters("http://music.baidu.com/search", parameters);

            UrlHelper.OpenLink(url);
        }
Exemple #4
0
        /// <summary>
        /// 搜索
        /// </summary>
        /// <param name="text">搜索文本</param>
        /// <param name="start">Start值</param>
        void Search()
        {
            if (IsSearchFinished == false)
            {
                return;
            }
            SearchResult     = null;
            IsSearchFinished = false;
            PreviousPageLink = null;
            NextPageLink     = null;
            ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
            {
                //构造链接
                Parameters parameters     = new Parameters();
                parameters["start"]       = ((_page - 1) * 15).ToString();
                parameters["search_text"] = _searchText;
                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)
                {
                    Debug.WriteLine(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);
                Dispatcher.Invoke(new Action(() =>
                {
                    SearchResult     = searhResult;
                    PreviousPageLink = previous;
                    NextPageLink     = next;
                    IsSearchFinished = true;
                }));
            }));
        }
Exemple #5
0
        /// <summary>
        /// 获取分享链接
        /// </summary>
        public string GetShareLink()
        {
            if (Site == null)
            {
                throw new Exception("没有设定分享网站。");
            }
            Parameters parameters = new Parameters(true);
            string     url        = null;

            switch (Site)
            {
            case Sites.None:
                throw new InvalidOperationException("复制网址模式不能获取分享链接");

            //break;
            case Sites.Douban:
                parameters["name"]   = _songInfo.SongName;
                parameters["href"]   = _songInfo.Url;
                parameters["image"]  = _songInfo.CoverUrl;
                parameters["text"]   = "";
                parameters["desc"]   = GetShareTextPartTwo(_songInfo.ChannelName);
                parameters["apikey"] = "0c2e1df44f97c4eb248a59dceec74ec1";
                url = ConnectionBase.ConstructUrlWithParameters("http://shuo.douban.com/!service/share", parameters);
                break;

            case Sites.Weibo:
                parameters["appkey"]  = "1075899032";
                parameters["url"]     = _songInfo.Url;
                parameters["title"]   = TextWithoutSource;
                parameters["content"] = "utf-8";
                parameters["pic"]     = _songInfo.CoverUrl;
                url = ConnectionBase.ConstructUrlWithParameters("http://service.t.sina.com.cn/share/share.php", parameters);
                break;

            case Sites.Msn:
                parameters["url"]        = _songInfo.Url;
                parameters["title"]      = Text;
                parameters["screenshot"] = _songInfo.CoverUrl;
                url = ConnectionBase.ConstructUrlWithParameters("http://profile.live.com/badge", parameters);
                break;

            case Sites.Kaixin:
                parameters["rurl"]     = _songInfo.Url;
                parameters["rcontent"] = "";
                parameters["rtitle"]   = Text;
                url = ConnectionBase.ConstructUrlWithParameters("http://www.kaixin001.com/repaste/bshare.php", parameters);
                break;

            case Sites.Renren:
                parameters["resourceUrl"] = _songInfo.Url;
                parameters["title"]       = GetShareTextPartOne(_songInfo.SongName, _songInfo.ArtistName);;
                parameters["pic"]         = _songInfo.CoverUrl;
                parameters["description"] = GetShareTextPartTwo(_songInfo.ChannelName);
                parameters["charset"]     = "utf-8";
                url = ConnectionBase.ConstructUrlWithParameters("http://widget.renren.com/dialog/share", parameters);
                break;

            case Sites.TencentWeibo:
                parameters["url"]    = _songInfo.Url;
                parameters["title"]  = Text;
                parameters["site"]   = "http://www.kfstorm.com/doubanfm";
                parameters["pic"]    = _songInfo.CoverUrl;
                parameters["appkey"] = "801098586";
                url = ConnectionBase.ConstructUrlWithParameters("http://v.t.qq.com/share/share.php", parameters);
                break;

            case Sites.Fanfou:
                parameters["u"] = _songInfo.Url;
                parameters["t"] = Text;
                parameters["s"] = "bm";
                url             = ConnectionBase.ConstructUrlWithParameters("http://fanfou.com/sharer", parameters);
                break;

            case Sites.Facebook:
                parameters["u"] = _songInfo.Url;
                parameters["t"] = Text;
                url             = ConnectionBase.ConstructUrlWithParameters("http://www.facebook.com/sharer.php", parameters);
                break;

            case Sites.Twitter:
                parameters["status"] = Text + " " + _songInfo.Url;
                url = ConnectionBase.ConstructUrlWithParameters("http://twitter.com/home", parameters);
                break;

            case Sites.Qzone:
                parameters["url"]   = _songInfo.Url;
                parameters["title"] = Text;
                url = ConnectionBase.ConstructUrlWithParameters("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey", parameters);
                break;

            default:
                break;
            }
            return(url);
        }
Exemple #6
0
        /// <summary>
        /// 获取播放列表
        /// </summary>
        /// <param name="playerState">播放器状态</param>
        /// <param name="operationType">操作类型</param>
        /// <returns>
        /// 播放列表
        /// </returns>
        internal static PlayList GetPlayList(Player.PlayerState playerState, string operationType)
        {
            //构造链接
            Parameters parameters = new Parameters();

            parameters["app_name"] = "radio";
            parameters["version"]  = "100";
            parameters["user_id"]  = playerState.CurrentUser.UserID;
            parameters["token"]    = playerState.CurrentUser.Token;
            parameters["expire"]   = playerState.CurrentUser.Expire;
            parameters["from"]     = "mainsite";
            parameters["context"]  = playerState.CurrentChannel.Context;
            parameters["sid"]      = playerState.CurrentSong != null ? playerState.CurrentSong.SongId : null;
            parameters["channel"]  = playerState.CurrentChannel.Id;
            parameters["type"]     = operationType;
            random.NextBytes(bytes);
            parameters["r"] = (BitConverter.ToUInt64(bytes, 0) % 0xFFFFFFFFFF).ToString("x10");

            if (playerState.CurrentUser.IsPro)
            {
                string kbps = null;
                switch (playerState.CurrentUser.ProRate)
                {
                case ProRate.Kbps64:
                    kbps = "64";
                    break;

                case ProRate.Kbps128:
                    kbps = "128";
                    break;

                case ProRate.Kbps192:
                    kbps = "192";
                    break;

                default:
                    break;
                }
                parameters["kbps"] = kbps;
            }

            string url = ConnectionBase.ConstructUrlWithParameters(ConfigurationManager.AppSettings["PlayList.BaseUrl"], parameters);

            //获取列表
            string json         = new ConnectionBase().Get(url, @"application/json, text/javascript, */*; q=0.01", @"http://douban.fm");
            var    jsonPlayList = Json.JsonHelper.FromJson <Json.PlayList>(json);

            if (jsonPlayList != null && jsonPlayList.r)
            {
                RaiseGetPlayListFailedEvent(json);
            }
            PlayList pl = new PlayList(jsonPlayList);

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

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

            return(pl);
        }
        /// <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);
        }