Example #1
0
        private static void getAlbumData(ref Album oObj, string ID, out string Errmsg, bool GetItem = false)
        {
            oObj.CoverData = (byte[])HttpHelper.GetOrPost(getCoverUrl(ref oObj), out Errmsg, IsRetByte: true, Retry: 3, Timeout: 5000, Proxy: PROXY);
            oObj.Tracks    = new ObservableCollection <Track>();
            oObj.Videos    = new ObservableCollection <Video>();

            if (GetItem)
            {
                if (oObj.NumberOfVideos <= 0)
                {
                    oObj.Tracks = get <ObservableCollection <Track> >("albums/" + ID + "/tracks", out Errmsg, null, 3, "items");
                }
                else
                {
                    ObservableCollection <object> pArray = getItems <object>("albums/" + ID + "/items", out Errmsg, null, 3);
                    foreach (object item in pArray)
                    {
                        if (JsonHelper.GetValue(item.ToString(), "type") == "track")
                        {
                            oObj.Tracks.Add(JsonHelper.ConverStringToObject <Track>(item.ToString(), "item"));
                        }
                        else
                        {
                            oObj.Videos.Add(JsonHelper.ConverStringToObject <Video>(item.ToString(), "item"));
                        }
                    }
                }
            }
        }
Example #2
0
        public static ObservableCollection <Track> GetAlbumTracks(string sID, bool bGetUrl = false, string sQuality = null, Quality eQuality = Quality.LOSSLESS)
        {
            string sRet = Get("albums/" + sID + "/tracks");

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }

            ObservableCollection <Track> aRet = JsonHelper.ConverStringToObject <ObservableCollection <Track> >(sRet, "items");

            if (bGetUrl)
            {
                if (sQuality == null)
                {
                    sQuality = AIGS.Common.Convert.ConverEnumToString((int)eQuality, typeof(Quality), 0);
                }

                //ThreadHelper ThreadList = new ThreadHelper(1);
                ThreadHelper ThreadList = new ThreadHelper(aRet.Count);
                for (int i = 0; i < aRet.Count; i++)
                {
                    ThreadList.ThreadStartWait(GetStreamUrl, 0, aRet[i], sQuality);
                }
                ThreadList.WaitAll();
            }
            return(aRet);
        }
Example #3
0
        static ObservableCollection <T> getItems <T>(string Path, out string Errmsg, Dictionary <string, string> Paras = null, int RetryNum = 3)
        {
            if (Paras == null)
            {
                Paras = new Dictionary <string, string>();
            }
            Paras.Add("limit", "50");
            Paras.Add("offset", "0");

            int iOffset = 0;
            ObservableCollection <T> pRet = new ObservableCollection <T>();

            while (true)
            {
                string sRet = get(Path, out Errmsg, Paras, RetryNum);
                if (sRet.IsBlank() || Errmsg.IsNotBlank())
                {
                    break;
                }

                ObservableCollection <T> pList = JsonHelper.ConverStringToObject <ObservableCollection <T> >(sRet, "items");
                foreach (var item in pList)
                {
                    pRet.Add(item);
                }
                if (pList.Count() < 50)
                {
                    break;
                }
                iOffset        += pList.Count();
                Paras["offset"] = iOffset.ToString();
            }
            return(pRet);
        }
Example #4
0
        public static Playlist getPlaylist(string ID, out string Errmsg)
        {
            Playlist oObj = get <Playlist>("playlists/" + ID, out Errmsg);

            if (oObj == null)
            {
                return(null);
            }

            oObj.Tracks = new ObservableCollection <Track>();
            oObj.Videos = new ObservableCollection <Video>();
            ObservableCollection <object> pArray = getItems <object>("playlists/" + ID + "/items", out Errmsg, null, 3);

            foreach (object item in pArray)
            {
                if (JsonHelper.GetValue(item.ToString(), "type") == "track")
                {
                    oObj.Tracks.Add(JsonHelper.ConverStringToObject <Track>(item.ToString(), "item"));
                }
                else
                {
                    oObj.Videos.Add(JsonHelper.ConverStringToObject <Video>(item.ToString(), "item"));
                }
            }

            oObj.CoverData = (byte[])HttpHelper.GetOrPost(getCoverUrl(ref oObj), out Errmsg, IsRetByte: true, Retry: 3, Timeout: 5000, Proxy: PROXY);
            return(oObj);
        }
Example #5
0
        public static SearchResult Search(string sQuery, int iLimit, out string Errmsg)
        {
            string sRet = Get("search", out Errmsg, new Dictionary <string, string>()
            {
                { "query", sQuery },
                { "offset", "0" },
                { "limit", iLimit.ToString() },
            });

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }

            SearchResult pRet = new SearchResult();

            pRet.Albums    = JsonHelper.ConverStringToObject <ObservableCollection <Album> >(sRet, "albums", "items");
            pRet.Tracks    = JsonHelper.ConverStringToObject <ObservableCollection <Track> >(sRet, "tracks", "items");
            pRet.Videos    = JsonHelper.ConverStringToObject <ObservableCollection <Video> >(sRet, "videos", "items");
            pRet.Playlists = JsonHelper.ConverStringToObject <ObservableCollection <Playlist> >(sRet, "playlists", "items");
            if (pRet.Albums.Count == 0 && pRet.Tracks.Count == 0 && pRet.Videos.Count == 0)
            {
                return(null);
            }

            pRet.Albums    = pRet.Albums == null ? new ObservableCollection <Album>() : pRet.Albums;
            pRet.Tracks    = pRet.Tracks == null ? new ObservableCollection <Track>() : pRet.Tracks;
            pRet.Videos    = pRet.Videos == null ? new ObservableCollection <Video>() : pRet.Videos;
            pRet.Playlists = pRet.Playlists == null ? new ObservableCollection <Playlist>() : pRet.Playlists;
            return(pRet);
        }
Example #6
0
        public static bool LogIn(string user, string password, out string errmsg)
        {
            errmsg = null;
            string sPhonesessionid = null;

            for (int i = 0; i < 2; i++)
            {
                string sRet = (string)HttpHelper.GetOrPost(URL + "login/username", out errmsg, new Dictionary <string, string>()
                {
                    { "username", user },
                    { "password", password },
                    { "token", i == 0 ? PHONE_TOKEN : TOKEN },
                    { "clientVersion", VERSION },
                    { "clientUniqueKey", GetUID() }
                });
                if (!string.IsNullOrEmpty(errmsg))
                {
                    return(false);
                }
                if (i == 0)
                {
                    sPhonesessionid = JsonHelper.GetValue(sRet, "sessionId");
                }
                else
                {
                    m_User = JsonHelper.ConverStringToObject <Account>(sRet);
                    m_User.SessionID_Phone = sPhonesessionid;
                }
            }

            m_User.User = user;
            m_User.Pwd  = password;
            m_isLogin   = true;
            return(true);
        }
Example #7
0
        public static Album GetAlbum(string sID, out string Errmsg, bool GetTracks = true)
        {
            string sRet = Get("albums/" + sID, out Errmsg);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }
            Album aRet = JsonHelper.ConverStringToObject <Album>(sRet);

            //get cover
            aRet.CoverUrl  = "https://resources.tidal.com/images/" + aRet.Cover.Replace('-', '/') + "/1280x1280.jpg";
            aRet.CoverData = (byte[])HttpHelper.GetOrPost(aRet.CoverUrl, out Errmsg, IsRetByte: true, Timeout: 5000);

            //get tracklist
            if (GetTracks)
            {
                string sRet2 = Get("albums/" + sID + "/tracks", out Errmsg);
                if (string.IsNullOrEmpty(sRet2) || !string.IsNullOrEmpty(Errmsg))
                {
                    return(null);
                }
                aRet.Tracks = JsonHelper.ConverStringToObject <ObservableCollection <Track> >(sRet2, "items");
            }
            else
            {
                aRet.Tracks = new ObservableCollection <Track>();
            }

            return(aRet);
        }
        public static UserSettings Read()
        {
            string       data = FileHelper.Read(Global.PATH_USERSETTINGS);
            UserSettings ret  = JsonHelper.ConverStringToObject <UserSettings>(data);

            if (ret == null)
            {
                return(new UserSettings());
            }
            return(ret);
        }
Example #9
0
        static T get <T>(string Path, out string Errmsg, Dictionary <string, string> Paras = null, int RetryNum = 3, params string[] sKeyName)
        {
            string sRet = get(Path, out Errmsg, Paras, RetryNum);

            if (sRet.IsBlank() || Errmsg.IsNotBlank())
            {
                return(default(T));
            }
            T aRet = JsonHelper.ConverStringToObject <T>(sRet, sKeyName);

            return(aRet);
        }
        public static UserSettings Read()
        {
            string       buf  = FileHelper.Read(Global.PATH_USERSETTINGS);
            string       data = EncryptHelper.Decode(buf, Global.KEY_BASE);
            UserSettings ret  = JsonHelper.ConverStringToObject <UserSettings>(data);

            if (ret == null)
            {
                return(new UserSettings());
            }
            return(ret);
        }
Example #11
0
        public static Video GetVideo(string sID)
        {
            string sRet = Get("videos/" + sID);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }

            Video aRet = JsonHelper.ConverStringToObject <Video>(sRet);

            return(aRet);
        }
Example #12
0
        private static T Get <T>(string Path, out string Errmsg, Dictionary <string, string> Paras = null, int RetryNum = 0)
        {
            string sRet = Get(Path, out Errmsg, Paras, RetryNum);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(default(T));
            }

            T aRet = JsonHelper.ConverStringToObject <T>(sRet);

            return(aRet);
        }
Example #13
0
        public static Track GetTrack(string sID, out string Errmsg)
        {
            string sRet = Get("tracks/" + sID, out Errmsg);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }

            Track aRet = JsonHelper.ConverStringToObject <Track>(sRet);

            return(aRet);
        }
Example #14
0
        public static Track GetTrack(string sID, string sQuality)
        {
            string sRet = Get("tracks/" + sID);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }

            Track aRet = JsonHelper.ConverStringToObject <Track>(sRet);

            aRet.StreamUrl = GetStreamUrl(sID, sQuality);
            return(aRet);
        }
Example #15
0
        public static T ReadWrite <T>(string path, T wObj = default(T))
        {
            string sText;

            if (wObj == null)
            {
                sText = FileHelper.Read(path);
                T rObj = JsonHelper.ConverStringToObject <T>(sText);
                return(rObj);
            }

            sText = JsonHelper.ConverObjectToString <T>(wObj);
            FileHelper.Write(sText, true, path);
            return(default(T));
        }
        public static async Task <ObservableCollection <CoverCard> > GetList()
        {
            try
            {
                Result result = await HttpHelper.GetOrPostAsync("https://cdn.jsdelivr.net/gh/yaronzz/CDN/app/tidal/todaycards.json");

                if (result.sData.IsNotBlank())
                {
                    ObservableCollection <CoverCard> pList = JsonHelper.ConverStringToObject <ObservableCollection <CoverCard> >(result.sData);
                    return(pList);
                }
            }
            catch { }
            return(GetDefaultList());
        }
Example #17
0
        public static StreamUrl GetStreamUrl(string sID, string sQuality, out string Errmsg)
        {
            string sRet = Get("tracks/" + sID + "/streamUrl", out Errmsg, new Dictionary <string, string>()
            {
                { "soundQuality", sQuality }
            }, 3);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }

            StreamUrl aRet = JsonHelper.ConverStringToObject <StreamUrl>(sRet);

            return(aRet);
        }
Example #18
0
        public static Album GetAlbum(string sID, bool bGetTracksUrl = false, string sQuality = null)
        {
            string sRet = Get("albums/" + sID);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }

            Album aRet = JsonHelper.ConverStringToObject <Album>(sRet);

            aRet.CovrUrl   = "https://resources.tidal.com/images/" + aRet.Cover.Replace('-', '/') + "/1280x1280.jpg";
            aRet.CoverData = (byte[])HttpHelper.GetOrPost(aRet.CovrUrl, IsRetByte: true, Timeout: 5000);
            aRet.Tracks    = GetAlbumTracks(sID, bGetTracksUrl, sQuality);
            return(aRet);
        }
Example #19
0
        public static StreamUrl GetStreamUrl(string sID, string sQuality)
        {
            string sRet = Get("tracks/" + sID + "/streamUrl", new Dictionary <string, string>()
            {
                { "soundQuality", sQuality }
            }, 3);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }

            StreamUrl aRet = JsonHelper.ConverStringToObject <StreamUrl>(sRet);

            aRet.FileSize = DownloadFileHepler.GetFileLength(aRet.Url);
            return(aRet);
        }
Example #20
0
        public static Video GetVideo(string sID, out string Errmsg)
        {
            string sRet = Get("videos/" + sID, out Errmsg);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }

            Video aRet = JsonHelper.ConverStringToObject <Video>(sRet);

            //get cover
            aRet.CoverUrl  = "https://resources.tidal.com/images/" + aRet.ImageID.Replace('-', '/') + "/1280x1280.jpg";
            aRet.CoverData = (byte[])HttpHelper.GetOrPost(aRet.CoverUrl, out Errmsg, IsRetByte: true, Timeout: 5000);

            //aRet.CoverUrl = "http://images.tidalhifi.com/im/im?w=1280&h=1280&uuid=" + sID + "&rows=2&cols=3&noph";
            //aRet.CoverData = (byte[])HttpHelper.GetOrPost(aRet.CoverUrl, out Errmsg, IsRetByte: true, Timeout: 5000);
            return(aRet);
        }
Example #21
0
        public static Playlist GetPlaylist(string sID, out string Errmsg)
        {
            string sRet = Get("playlists/" + sID, out Errmsg);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }
            Playlist aRet = JsonHelper.ConverStringToObject <Playlist>(sRet);

            //get itemlist
            ObservableCollection <Track> Tracks;
            ObservableCollection <Video> Videos;

            Errmsg      = GetPlaylistItems(sID, aRet.NumberOfTracks + aRet.NumberOfVideos, out Tracks, out Videos);
            aRet.Tracks = Tracks;
            aRet.Videos = Videos;

            return(aRet);
        }
Example #22
0
        public static bool CreatV2rayConfig(Server oObject, Settings bBase)
        {
            V2rayConfig config = JsonHelper.ConverStringToObject <V2rayConfig>(SystemHelper.GetEmbedText("Votrix.Protocol.V2rayTemplate.json"));

            config.SetLog((eLogLevel)bBase.Loglevel, bBase.SaveLog);
            config.SetApi("api", "StatsService");
            config.SetPolicy(true, true);
            //DNS
            //config.SetDns(params string[] sServices);
            //路由设置
            //config.SetRoutingDomainStrategy(eDomainStrategy eObj);
            //config.AddRoutingRulesItem(string sType, string sPort, string[] sinboundTag, string sOutboundTag, string[] sIP, string[] sDomain);

            ////传入连接配置
            //string[] sSniffingDestOverride = {"http","tls" };
            //Inbounds inItem1 = config.CreatInbound("proxy", int.Parse(bBase.PortSocks5), "socks", bBase.ShareAreaNetwork, bBase.OpenSniffing, sSniffingDestOverride, "noauth", bBase.SupportUDP);
            //Inbounds inItem2 = config.CreatInbound("api", 53543, "dokodemo-door", false, false, null, null, false, null, "127.0.0.1");
            ////config.AddInboundSettingsClient();
            ////config.SetStreamSettingsBase();
            //config.inbounds.Add(inItem1);
            //config.inbounds.Add(inItem2);

            ////传出连接配置
            //Outbounds outItem1 = config.CreatOutbounds("proxy", "vmess", bBase.OpenMux, 8, sSettingsResponseType: null);
            //config.AddOutboundsVnextItem(ref outItem1, oObject.Address, int.Parse(oObject.Port), new List<UsersItem>() { new UsersItem() {
            //    id = oObject.UUID,
            //    alterId = int.Parse(oObject.AlterID),
            //    email = "*****@*****.**",
            //    security = AIGS.Common.Convert.ConverEnumToString(oObject.SecurityVmess, typeof(eSecurityVmess), (int)(eSecurityVmess.auto)).Replace('_','-')
            //    } });
            //StreamSettings stream = outItem1.streamSettings;
            //config.SetStreamSettingsBase(ref stream, AIGS.Common.Convert.ConverEnumToString(oObject.Network, typeof(eNetwork), (int)(eNetwork.ws)).Replace('_', '-'),
            //    oObject.TLSEnable ? "tls" : "",
            //    oObject.TLSEnable ? oObject.AllowInsecure : false,
            //    oObject.TLSEnable ? oObject.Address : null);



            return(true);
        }
Example #23
0
        public static bool LogIn(string user, string password, out string errmsg)
        {
            string sRet = (string)HttpHelper.GetOrPost(URL + "login/username", out errmsg, new Dictionary <string, string>()
            {
                { "username", user },
                { "password", password },
                { "token", TOKEN },
                { "clientVersion", VERSION },
                { "clientUniqueKey", GetUID() }
            });

            if (!string.IsNullOrEmpty(errmsg))
            {
                return(false);
            }

            m_User      = JsonHelper.ConverStringToObject <Account>(sRet);
            m_User.User = user;
            m_User.Pwd  = password;
            m_isLogin   = true;
            return(true);
        }
Example #24
0
        private static string GetPlaylistItems(string sID, int iSum, out ObservableCollection <Track> Tracks, out ObservableCollection <Video> Videos)
        {
            int    iLimit  = 100;
            int    iOffset = 0;
            string Errmsg  = null;

            Tracks = new ObservableCollection <Track>();
            Videos = new ObservableCollection <Video>();

            while (iOffset < iSum)
            {
                string sRet = Get("playlists/" + sID + "/items", out Errmsg, new Dictionary <string, string>()
                {
                    { "offset", iOffset.ToString() }, { "limit", iLimit.ToString() }
                });
                if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
                {
                    return(Errmsg);
                }

                List <object> sItems = JsonHelper.ConverStringToObject <List <object> >(sRet, "items");
                foreach (object item in sItems)
                {
                    string sType = JsonHelper.GetValue(item.ToString(), "type");
                    if (sType.ToLower() == "video")
                    {
                        Videos.Add(JsonHelper.ConverStringToObject <Video>(item.ToString(), "item"));
                    }
                    else
                    {
                        Tracks.Add(JsonHelper.ConverStringToObject <Track>(item.ToString(), "item"));
                    }
                }
                iOffset += sItems.Count;
            }

            return(Errmsg);
        }
Example #25
0
        private static async Task <(string, string)> Request(LoginKey oKey, string sPath, Dictionary <string, string> oParas = null, int iRetry = 3)
        {
            string paras = $"?countryCode={oKey.CountryCode}";

            if (oParas != null)
            {
                foreach (var item in oParas)
                {
                    paras += $"&{item.Key}={item.Value}";
                }
            }

            string header = $"X-Tidal-SessionId:{oKey.SessionID}";

            if (oKey.AccessToken.IsNotBlank())
            {
                header = $"authorization:Bearer {oKey.AccessToken}";
            }

            Result result = await HttpHelper.GetOrPostAsync(BASE_URL + sPath + paras, Header : header, Retry : iRetry, Proxy : oKey.Proxy);

            if (result.Success == false)
            {
                TidalRespon respon = JsonHelper.ConverStringToObject <TidalRespon>(result.Errresponse);
                string      msg    = respon.UserMessage + "! ";
                if (respon.Status == "404" && respon.SubStatus == "2001")
                {
                    msg += "This might be region-locked.";
                }
                else if (respon.Status == "200")
                {
                    msg += "Get operation err.";
                }
                return(msg, null);
            }

            return(null, result.sData);
        }
Example #26
0
        public static Album GetAlbum(string sID, out string Errmsg, bool GetTracks = true)
        {
            string sRet = Get("albums/" + sID, out Errmsg);

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }
            Album aRet = JsonHelper.ConverStringToObject <Album>(sRet);

            //get cover
            aRet.CoverUrl  = "https://resources.tidal.com/images/" + aRet.Cover.Replace('-', '/') + "/1280x1280.jpg";
            aRet.CoverData = (byte[])HttpHelper.GetOrPost(aRet.CoverUrl, out Errmsg, IsRetByte: true, Timeout: 5000);

            //get tracklist
            if (GetTracks == false)
            {
                aRet.Tracks = new ObservableCollection <Track>();
                return(aRet);
            }

            string sRet2 = Get("albums/" + sID + "/tracks", out Errmsg);

            if (string.IsNullOrEmpty(sRet2) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }
            aRet.Tracks = JsonHelper.ConverStringToObject <ObservableCollection <Track> >(sRet2, "items");

            //change track title
            for (int i = 0; i < aRet.Tracks.Count; i++)
            {
                if (string.IsNullOrWhiteSpace(aRet.Tracks[i].Version))
                {
                    continue;
                }
                if (aRet.Tracks[i].Title.IndexOf(aRet.Tracks[i].Version) >= 0)
                {
                    continue;
                }
                aRet.Tracks[i].Title += '(' + aRet.Tracks[i].Version + ')';
            }

            //remove same title
            List <int> pSameIndex = new List <int>();

            for (int i = 0; i < aRet.Tracks.Count; i++)
            {
                pSameIndex.Clear();
                for (int j = 0; j < aRet.Tracks.Count; j++)
                {
                    if (aRet.Tracks[i].Title == aRet.Tracks[j].Title)
                    {
                        pSameIndex.Add(j);
                    }
                }

                if (pSameIndex.Count <= 1)
                {
                    continue;
                }

                for (int j = 0; j < pSameIndex.Count; j++)
                {
                    aRet.Tracks[pSameIndex[j]].Title += (j + 1).ToString();
                }
            }
            return(aRet);
        }
Example #27
0
        //导入链接
        public static Server LoadURLString(string sText)
        {
            if (sText.IsBlank())
            {
                return(null);
            }

            if (sText.StartsWith(VMESS_STRING_FLAG))
            {
                sText = sText.Substring(VMESS_STRING_FLAG.Length);
                sText = StringHelper.Base64Decode(sText);

                VmessUrl VmessUrl = JsonHelper.ConverStringToObject <VmessUrl>(sText);
                if (VmessUrl == null)
                {
                    return(null);
                }
                Server ret = new Server()
                {
                    PType     = eProtocolType.vmess,
                    Name      = VmessUrl.ps,
                    Address   = VmessUrl.add,
                    Port      = VmessUrl.port,
                    UUID      = VmessUrl.id,
                    AlterID   = VmessUrl.aid,
                    Host      = VmessUrl.host,
                    Path      = VmessUrl.path,
                    TLSEnable = VmessUrl.tls == "tls",
                    Network   = AIGS.Common.Convert.ConverStringToEnum(VmessUrl.net, typeof(eNetwork), (int)eNetwork.ws, true),
                    Type      = VmessUrl.type,
                };
                return(ret);
            }
            if (sText.StartsWith(SS_STRING_FLAG))
            {
                sText = sText.Substring(SS_STRING_FLAG.Length);
                string[] oTmp  = sText.Split("#");
                string   sName = oTmp.Length == 2 ? oTmp[1] : null;

                int index = oTmp[0].IndexOf("@");
                if (index > 0)
                {
                    sText = StringHelper.Base64Decode(oTmp[0].Substring(0, index)) + oTmp[0].Substring(index, oTmp[0].Length - index);
                }
                else
                {
                    sText = StringHelper.Base64Decode(oTmp[0]);
                }

                string[] oStrs = sText.Split('@');
                if (oStrs.Length != 2)
                {
                    return(null);
                }
                string[] oArr1 = oStrs[0].Split(':');
                string[] oArr2 = oStrs[1].Split(':');
                if (oArr1.Length != 2 || oArr2.Length != 2)
                {
                    return(null);
                }
                Server ret = new Server()
                {
                    PType      = eProtocolType.shadowsocks,
                    Name       = sName,
                    Address    = oArr2[0],
                    Port       = oArr2[1],
                    SecuritySS = AIGS.Common.Convert.ConverStringToEnum(oArr1[0].Replace('-', '_'), typeof(eSecuritySS), (int)eSecuritySS.aes_128_cfb, true),
                    Password   = oArr1[1],
                };
                return(ret);
            }
            if (sText.StartsWith(SOCKS_STRING_FLAG))
            {
                sText = sText.Substring(SOCKS_STRING_FLAG.Length);
                string[] oTmp  = sText.Split("#");
                string   sName = oTmp.Length == 2 ? oTmp[1] : null;

                int index = oTmp[0].IndexOf("@");
                if (index < 0)
                {
                    sText = StringHelper.Base64Decode(oTmp[0]);
                }
                //"name:[email protected]:10808"
                string[] oStrs = sText.Split('@');
                if (oStrs.Length != 2)
                {
                    return(null);
                }
                string[] oArr1 = oStrs[0].Split(':');
                string[] oArr2 = oStrs[1].Split(':');
                if (oArr1.Length != 2 || oArr2.Length != 2)
                {
                    return(null);
                }
                Server ret = new Server()
                {
                    PType    = eProtocolType.socks,
                    Name     = sName,
                    Address  = oArr2[0],
                    Port     = oArr2[1],
                    UserName = oArr1[0],
                    Password = oArr1[1],
                };
                return(ret);
            }
            return(null);
        }
Example #28
0
        /// <summary>
        /// 根据专辑和歌手获取匹配的网易云专辑
        /// </summary>
        /// <param name="sAlbumName">专辑名</param>
        /// <param name="sArtistName">歌手</param>
        /// <returns></returns>
        public static CloudMusicAlbum matchAlbum(string sAlbumName, string sArtistName)
        {
            //使用豆瓣接口搜索专辑,支持英文、中文、繁体搜索
            string serr;
            string stxt = (string)HttpHelper.GetOrPost("https://api.douban.com/v2/music/search?q=" + sAlbumName, out serr);
            List <DoubanMusicRecord> pDoubans = JsonHelper.ConverStringToObject <List <DoubanMusicRecord> >(stxt, "musics");

            //使用网易云接口搜索歌手
            string stxt2 = (string)HttpHelper.GetOrPost(string.Format("http://music.163.com/api/search/pc?s={0}&type=100&limit=10&offset=0", sArtistName), out serr);
            List <CloudMusicArtist> pClounds = JsonHelper.ConverStringToObject <List <CloudMusicArtist> >(stxt2, "result", "artists");

            //匹配
            int iIndex1 = -1;
            int iIndex2 = -1;

            for (int i = 0; pClounds != null && i < pClounds.Count && iIndex1 == -1; i++)
            {
                string skey = pClounds[i].name;
                for (int j = 0; pDoubans != null && j < pDoubans.Count && iIndex1 == -1; j++)
                {
                    for (int k = 0; pDoubans[j].author != null && k < pDoubans[j].author.Count; k++)
                    {
                        string stmp = converSimpleChinese(pDoubans[j].author[k].name);
                        if (skey == stmp || skey.Contains(stmp) || stmp.Contains(skey) || stmp == sArtistName)
                        {
                            iIndex1 = i;
                            iIndex2 = j;
                            break;
                        }
                    }
                }
            }

            if (iIndex1 < 0)
            {
                return(null);
            }

            string sname = converSimpleChinese(pDoubans[iIndex2].title);
            string stxt3 = (string)HttpHelper.GetOrPost(string.Format("http://music.163.com/api/search/pc?s={0}&type=10&limit=30&offset=0", sname), out serr);
            List <CloudMusicAlbum> pCloundAlbums = JsonHelper.ConverStringToObject <List <CloudMusicAlbum> >(stxt3, "result", "albums");

            //匹配
            int iIndex3 = -1;

            for (int i = 0; pCloundAlbums != null && i < pCloundAlbums.Count; i++)
            {
                if (pCloundAlbums[i].artist.name == pClounds[iIndex1].name &&
                    pCloundAlbums[i].name == sname)
                {
                    iIndex3 = i;
                    break;
                }
            }
            if (iIndex3 < 0)
            {
                return(null);
            }

            string          stxt4  = (string)HttpHelper.GetOrPost(string.Format("http://music.163.com/api/album/{0}?ext=true&id={1}&offset=0&total=true&limit=10", pCloundAlbums[iIndex3].id.ToString(), pCloundAlbums[0].id.ToString()), out serr);
            CloudMusicAlbum pAlbum = JsonHelper.ConverStringToObject <CloudMusicAlbum>(stxt4, "album");

            return(pAlbum);
        }
Example #29
0
        public static ArtistAlbumList GetArtistAlbumList(string sID, out string Errmsg, bool GetAlbums = true)
        {
            string sRet = Get("artists/" + sID + "/albums", out Errmsg, new Dictionary <string, string>()
            {
                { "offset", "0" },
                { "limit", "200" },// Get it all at once
            });

            if (string.IsNullOrEmpty(sRet) || !string.IsNullOrEmpty(Errmsg))
            {
                return(null);
            }
            ArtistAlbumList aRet = JsonHelper.ConverStringToObject <ArtistAlbumList>(sRet);

            if (aRet.TotalAlbums == 0)
            {
                return(null);
            }
            //get Ablums
            if (GetAlbums == false)
            {
                return(aRet);
            }

            // We already have a list of albums lets try to filter it so we don't get things we don't want!
            for (int i = 0; i < aRet.Albums.Count; ++i)
            {
                // Matching Titles
                var matching = aRet.Albums.Select(x => x).Where(album => album.Title.CompareTo(aRet.Albums[i].Title) == 0).ToList();
                // Check for dups and remove all matching
                if (matching.Count() > 1)
                {
                    foreach (var album in matching)
                    {
                        aRet.Albums.Remove(album);
                    }
                    // Move our index
                    i -= (matching.Count() - 1);
                    // Clamp
                    if (i < 0)
                    {
                        i = 0;
                    }
                }
                else
                {
                    // Skip anything we dont have duplicates for
                    continue;
                }
                // Find if we have one that has the master flag
                var masterMatching = matching.Select(album => album).Where(album => String.Compare(album.AudioQuality, "lossless", true) == 0).ToList();
                if (masterMatching.Count() > 0)
                {
                    // Has master flag lets check if there is also one with the explicit flag
                    var explicitMatching = masterMatching.Select(a => a).Where(album => album.ExplicitLyrics).ToList();
                    if (explicitMatching.Count() > 0)
                    {
                        aRet.Albums.Insert(i, explicitMatching.ElementAt(0));
                    }
                    else
                    {
                        // Nothing had the explicit flag set lets check the version for pa or ammended
                        explicitMatching = masterMatching.Select(a => a).Where(album => album.Version != null && (album.Version.ToLower().Contains("pa version") || album.Version.ToLower().Contains("amended version"))).ToList();
                        if (explicitMatching.Count > 0)
                        {
                            aRet.Albums.Insert(i, explicitMatching.ElementAt(0));
                        }
                        else
                        {
                            aRet.Albums.Insert(i, masterMatching.ElementAt(0));
                        }
                    }
                }
                else
                {
                    // No Master Check Explicit
                    var explicitMatching = matching.Select(a => a).Where(album => album.ExplicitLyrics).ToList();
                    if (explicitMatching.Count() > 0)
                    {
                        aRet.Albums.Insert(i, explicitMatching.ElementAt(0));
                    }
                    else
                    {
                        // Nothing had the explicit flag set lets check the version for pa or ammended
                        explicitMatching = matching.Select(a => a).Where(album => album.Version.ToLower().Contains("pa") || album.Version.ToLower().Contains("ammended")).ToList();
                        if (explicitMatching.Count > 0)
                        {
                            aRet.Albums.Insert(i, explicitMatching.ElementAt(0));
                        }
                        else
                        {
                            aRet.Albums.Insert(i, matching.ElementAt(0));
                        }
                    }
                }
            }


            // For each album get the track list
            for (int albumIndex = 0; albumIndex < aRet.Albums.Count; ++albumIndex)
            {
                string sRet2 = Get("albums/" + aRet.Albums[albumIndex].ID + "/tracks", out Errmsg);
                if (string.IsNullOrEmpty(sRet2) || !string.IsNullOrEmpty(Errmsg))
                {
                    return(null);
                }
                aRet.Albums[albumIndex].Tracks = JsonHelper.ConverStringToObject <ObservableCollection <Track> >(sRet2, "items");
                if (aRet.Artist == null)
                {
                    aRet.Artist = aRet.Albums[albumIndex].Artist;
                }
                //change track title
                for (int i = 0; i < aRet.Albums[albumIndex].Tracks.Count; i++)
                {
                    if (string.IsNullOrWhiteSpace(aRet.Albums[albumIndex].Tracks[i].Version))
                    {
                        continue;
                    }
                    if (aRet.Albums[albumIndex].Tracks[i].Title.IndexOf(aRet.Albums[albumIndex].Tracks[i].Version) >= 0)
                    {
                        continue;
                    }
                    aRet.Albums[albumIndex].Tracks[i].Title += '(' + aRet.Albums[albumIndex].Tracks[i].Version + ')';
                }

                //remove same title
                List <int> pSameIndex = new List <int>();
                for (int i = 0; i < aRet.Albums[albumIndex].Tracks.Count; i++)
                {
                    pSameIndex.Clear();
                    for (int j = 0; j < aRet.Albums[albumIndex].Tracks.Count; j++)
                    {
                        if (aRet.Albums[albumIndex].Tracks[i].Title == aRet.Albums[albumIndex].Tracks[j].Title)
                        {
                            pSameIndex.Add(j);
                        }
                    }

                    if (pSameIndex.Count <= 1)
                    {
                        continue;
                    }

                    for (int j = 0; j < pSameIndex.Count; j++)
                    {
                        aRet.Albums[albumIndex].Tracks[pSameIndex[j]].Title += (j + 1).ToString();
                    }
                }
            }
            return(aRet);
        }