예제 #1
0
        public static bool TryGetMusicInfo(Tag tag, out The163KeyStruct KeyStruct)
        {
            if (tag is null)
            {
                throw new ArgumentNullException(nameof(tag));
            }

            KeyStruct = new The163KeyStruct();
            string the163Key = tag.Comment;

            if (!Is163KeyCandidate(the163Key))
            {
                the163Key = tag.Description;
            }
            if (!Is163KeyCandidate(the163Key))
            {
                return(false);
            }
            try
            {
                TryGetMusicInfo(the163Key, out KeyStruct);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
예제 #2
0
 public static bool TryGetMusicInfo(string the163Key, out The163KeyStruct KeyStruct)
 {
     if (string.IsNullOrEmpty(the163Key))
     {
         throw new ArgumentNullException(nameof(the163Key));
     }
     KeyStruct = new The163KeyStruct();
     try
     {
         the163Key = the163Key.Substring(22);
         byte[] byt163Key = Convert.FromBase64String(the163Key);
         using (var cryptoTransform = _aes.CreateDecryptor())
             byt163Key = cryptoTransform.TransformFinalBlock(byt163Key, 0, byt163Key.Length);
         KeyStruct = JsonConvert.DeserializeObject <The163KeyStruct>(Encoding.UTF8.GetString(byt163Key).Substring(6));
     }
     catch
     {
         return(false);
     }
     return(true);
 }
예제 #3
0
        /// <summary>
        /// 尝试设置163音乐信息到文件
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="trackId"></param>
        /// <returns></returns>
        public static bool TrySetMusicInfo(Tag tag, NCPlayItem pi)
        {
            if (tag is null)
            {
                throw new ArgumentNullException(nameof(tag));
            }

            try
            {
                var key = new The163KeyStruct()
                {
                    album     = pi.Album.name,
                    albumId   = int.Parse(pi.Album.id),
                    albumPic  = pi.Album.cover,
                    bitrate   = pi.bitrate,
                    artist    = null,
                    duration  = pi.LengthInMilliseconds,
                    musicId   = int.Parse(pi.sid),
                    musicName = pi.songname
                };
                key.artist = pi.Artist.Select(t => new List <object>()
                {
                    t.name, int.Parse(t.id)
                }).ToList();
                string enc            = "music:" + JsonConvert.SerializeObject(key);
                byte[] toEncryptArray = Encoding.UTF8.GetBytes(enc);
                byte[] resultArray;
                using (var cryptoTransform = _aes.CreateEncryptor())
                {
                    resultArray = cryptoTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                }
                tag.Comment = "163 key(Don't modify):" + Convert.ToBase64String(resultArray, 0, resultArray.Length);
            }
            catch
            {
                return(false);
            }
            return(true);
        }