示例#1
0
        /// <summary>
        /// 获取初始兆赫
        /// </summary>
        /// <returns>返回初始兆赫</returns>
        public ChannelEntity GetInitChannel()
        {
            string           getData   = WebConnection.GetCommand("http://douban.fm/j/explore/hot_channels?start=0&limit=1");
            GetChannelResult getResult = GetChannelResult.Json2Object(getData);

            return(getResult.Data.Channels[0]);
        }
示例#2
0
        /// <summary>
        /// 判断是否已经登录豆瓣FM
        /// </summary>
        /// <returns>-1:网络连接出错 0:未登录 1:已登录</returns>
        public int HasLogined()
        {
            string getData = WebConnection.GetCommand(@"http://douban.fm/");

            if (string.IsNullOrEmpty(getData))
            {
                return(-1);
            }
            Match match = Regex.Match(getData, @"豆瓣", RegexOptions.IgnoreCase);

            if (match == null || string.IsNullOrEmpty(match.Groups[0].Value))
            {
                return(-1);
            }
            match = Regex.Match(getData, "http://www.douban.com/accounts/login");
            //System.Diagnostics.Debug.WriteLine(match.Groups[0].Value);
            if (!string.IsNullOrEmpty(match.Groups[0].Value))
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
示例#3
0
        /// <summary>
        /// 更新验证码
        /// </summary>
        /// <returns>返回验证码的Url</returns>
        public string UpdateCaptcha()
        {
            string data = WebConnection.GetCommand("http://douban.fm/j/new_captcha");

            if (!string.IsNullOrEmpty(data))
            {
                captchaID = data.Trim('\"');
                return(string.Format(@"http://douban.fm/misc/captcha?size=m&id={0}", captchaID));
            }
            else
            {
                return(string.Empty);
            }
        }
示例#4
0
        /// <summary>
        /// 获取兆赫列表
        /// </summary>
        /// <param name="url">Url</param>
        private void GetChannels(string url)
        {
            channelInfo = null;
            string           getData   = WebConnection.GetCommand(url);
            GetChannelResult getResult = GetChannelResult.Json2Object(getData);

            if (getResult == null || getResult.Status == false)
            {
                isChanneLoadFailed = true;
            }
            else
            {
                channelInfo      = getResult.Data;
                isChannelChanged = true;
            }
        }
示例#5
0
 /// <summary>
 /// 获取歌曲歌手的更多信息
 /// </summary>
 /// <param name="songID">歌曲的ID号</param>
 /// <returns>MoreInfo对象</returns>
 private static MoreInfoEntity GetMoreInfo(string songID)
 {
     try
     {
         string         getData  = WebConnection.GetCommand(string.Format(@"http://music.douban.com/api/song/info?song_id={0}", songID));
         MoreInfoEntity moreInfo = MoreInfoEntity.Json2Object(getData);
         if (moreInfo == null)
         {
             return(null);
         }
         return(moreInfo);
     }
     catch
     {
         return(null);
     }
 }
示例#6
0
        /// <summary>
        /// 获取播放列表
        /// </summary>
        /// <param name="operationType">操作代码,字符串:n-新播放列表,p-加载更多,r-红心,u-取消红心,b-不再播放,s-跳过,e-自然结束</param>
        /// <param name="currentsongID">歌曲ID号</param>
        /// <param name="currentSongPT">加红心时歌曲进度(单位:0.1秒)</param>
        /// <returns>播放列表对象,自然结束时不返回字符串,因此为null</returns>
        private GetPlaylistResult GetNormalPlayList(string operationType = "n", string currentsongID = "", double currentSongPT = 0.0)
        {
            string getData = string.Empty;
            Random random  = new Random();

            byte[] bytes = new byte[8];
            random.NextBytes(bytes);
            string r = (BitConverter.ToUInt64(bytes, 0) % 0xFFFFFFFFFF).ToString("x10");

            getData = WebConnection.GetCommand(string.Format("http://douban.fm/j/mine/playlist?type={0}&sid={1}&channel=0&pt={2}&pb=64&from=mainsite&r={3}", operationType, currentsongID, currentSongPT, r));
            if (string.IsNullOrEmpty(getData))
            {
                return(null);
            }
            GetPlaylistResult result = GetPlaylistResult.Json2Object(getData);

            return(result);
        }
示例#7
0
        /// <summary>
        /// 获取新播放列表(仅歌手兆赫和专辑兆赫)
        /// </summary>
        /// <param name="type">兆赫类型:1-歌手兆赫 2-专辑兆赫 其他-搜索兆赫</param>
        /// <param name="singerName">歌手名</param>
        /// <param name="albumName">专辑名</param>
        /// <param name="keyword">关键字</param>
        /// <returns>SearchedSongResult对象</returns>
        private SearchedSongResult GetNewPlayList(int type, string singerName, string albumName, string keyword)
        {
            string getData = string.Empty;

            if (type == 1)
            {
                getData = WebConnection.GetCommand(string.Format(@"http://douban.fm/j/open_channel/creation/search?keyword={0}&cate=singer&limit={1}", singerName, loadCount));
            }
            else if (type == 2)
            {
                getData = WebConnection.GetCommand(string.Format(@"http://douban.fm/j/open_channel/creation/search?keyword={0}&cate=album&limit={1}", albumName, loadCount));
            }
            else
            {
                getData = WebConnection.GetCommand(string.Format(@"http://douban.fm/j/open_channel/creation/search?keyword={0}&cate=misc&limit={1}", keyword, loadCount));
            }
            if (string.IsNullOrEmpty(getData))
            {
                isPlayListLoadFailed = true;
                return(null);
            }
            return(SearchedSongResult.Json2Object(getData));
        }
示例#8
0
 /// <summary>
 /// 登出豆瓣账户
 /// </summary>
 public void Logout()
 {
     WebConnection.GetCommand(string.Format(@"http://douban.fm/partner/logout?source=radio&ck={0}&no_login=y", result.User.CK));
     WebConnection.ClearCookie();
     SaveUserInfo(string.Empty);
 }