示例#1
0
        public List <string> getPlaylistsItems(string playlistId)
        {
            string        query    = "https://api.spotify.com/v1/playlists/" + playlistId + "/tracks";
            Task <string> task     = Task.Run(async() => await GetStringAsync(query));
            dynamic       response = JsonConvert.DeserializeObject(task.Result);

            Newtonsoft.Json.Linq.JArray items = response["items"];
            return(items.Select(i => i["track"].Value <string>("uri")).ToList());
        }
 public override void OnDidChangeConfiguration(DidChangeConfigurationParams parameters)
 {
     if (parameters.settings is Newtonsoft.Json.Linq.JArray)
     {
         Newtonsoft.Json.Linq.JArray array     = parameters.settings as Newtonsoft.Json.Linq.JArray;
         IEnumerable <string>        arguments = array.Select(t => t.ToString());
         typeCobolWorkspace.DidChangeConfigurationParams(arguments);
     }
     else
     {
         typeCobolWorkspace.DidChangeConfigurationParams(parameters.settings.ToString());
     }
 }
示例#3
0
        private void GetSupportedExtensions()
        {
            string URL     = Wiki + "/api.php?action=query&meta=siteinfo&siprop=fileextensions&format=json";
            var    request = HttpWebRequest.CreateHttp(URL);

            request.Method    = "POST";
            request.UserAgent = "MultiUploader 0.1";
            try
            {
                var     responseStream = request.GetResponse().GetResponseStream();
                var     json           = new StreamReader(responseStream, Encoding.UTF8).ReadToEnd();
                dynamic responseObj    = JsonConvert.DeserializeObject(json);
                Newtonsoft.Json.Linq.JArray extensions = responseObj["query"]["fileextensions"];
                SupportedExtensions = string.Join(";", extensions.Select(x => $"*.{x["ext"].ToString()}").ToArray());
            }
            catch
            {
                SupportedExtensions = "*.png;*.gif;*.jpg;*.jpeg;*.ico;*.pdf;*.svg;*.odt;*.ods;*.odp;*.odg;*.odc;*.odf;*.odi;*.odm;*.ogg;*.ogv;*.oga";
            }
        }
示例#4
0
        public void GetLotList(uint shardID, Action <uint[]> callback)
        {
            var client  = Client();
            var request = new RestRequest("userapi/city/" + shardID + "/city.json");

            client.ExecuteAsync(request, (resp, h) =>
            {
                GameThread.NextUpdate(x =>
                {
                    if (resp.StatusCode != System.Net.HttpStatusCode.OK)
                    {
                        callback(null);
                    }
                    else
                    {
                        dynamic obj = JsonConvert.DeserializeObject(resp.Content);
                        Newtonsoft.Json.Linq.JArray data = obj.reservedLots;
                        uint[] result = data.Select(y => Convert.ToUInt32(y)).ToArray();
                        callback(result);
                    }
                });
            });
        }
示例#5
0
        /// <summary>
        /// 영화 API 스캔
        /// </summary>
        private void movie()
        {
            History      history      = new History(kobisInfo.RootDir);
            UrlGenerator urlGenerator = new UrlGenerator();

            string kobiskey  = kobisInfo.Key;
            string tmdbkey   = tmdbInfo.Key;
            string pageindex = kobisInfo.Params[Constant.ParamList.PARAM_KOBIS_PAGEINDEX];
            string viewcount = kobisInfo.Params[Constant.ParamList.PARAM_KOBIS_VIEWCOUNT];
            string startdt   = kobisInfo.Params[Constant.ParamList.PARAM_KOBIS_STARTDT];
            string enddt     = kobisInfo.Params[Constant.ParamList.PARAM_KOBIS_ENDDT];

            List <string> crawledData = history.getCrawledDataList();

            history.backupFile();
            history.createFile();

            Console.Write("[info] kobis api reading...");
            XDocument xDoc = XDocument.Load(
                urlGenerator.movieListAPI(
                    kobisInfo.Services[Constant.ApiList.MOVIE_LIST],
                    kobiskey, pageindex, viewcount, startdt, enddt
                    )
                );

            Console.WriteLine("[OK][{0}]", DateTime.Now.ToString("yyyymmddhhmmss"));

            var root      = xDoc.Descendants("movieListResult");
            var movieList = root.Descendants("movieList").Descendants("movie").Select(m => m);

            XElement movieXml = new XElement("root");

            List <string> kobisList = new List <string>();

            foreach (var movie in movieList)
            {
                string movieCd = movie.Element("movieCd").Value;
                kobisList.Add(movieCd);
            }

            Console.Write("[info] filtering exist data...");
            List <string> newItem = kobisList.AsParallel()
                                    .Where(code => !crawledData.Contains(code))
                                    .ToList();

            Console.WriteLine("[OK][{0}]", DateTime.Now.ToString("yyyymmddhhmmss"));

            Console.Write("[info] target data [{0}] counts", newItem.Count);
            foreach (var item in newItem)
            {
                history.writeInFile(item);

                #region MOVIE_DETAIL
                xDoc = XDocument.Load(
                    urlGenerator.movieInfoAPI(
                        kobisInfo.Services[Constant.ApiList.MOVIE_DETAIL],
                        kobiskey, item
                        )
                    );

                var movieInfo = xDoc.Descendants("movieInfoResult").Descendants("movieInfo").Select(info => info).First();

                string movieCd   = Utils.XmlUtil.getElementValue(movieInfo.Element("movieCd"), "");
                string movieNm   = Utils.XmlUtil.getElementValue(movieInfo.Element("movieNm"), "");
                string movieNmEn = Utils.XmlUtil.getElementValue(movieInfo.Element("movieNmEn"), "");
                string movieNmOg = Utils.XmlUtil.getElementValue(movieInfo.Element("movieNmOg"), "");
                string showTm    = Utils.XmlUtil.getElementValue(movieInfo.Element("showTm"), "0");
                string openDt    = Utils.XmlUtil.getElementValue(movieInfo.Element("openDt"), "미개봉");
                string genres    = string.Join(",", movieInfo.Element("genres")
                                               .Elements("genre")
                                               .Select(genre =>
                                                       Utils.XmlUtil.getElementValue(genre.Element("genreNm"), "")
                                                       )
                                               );
                string audits = Utils.StringUtil.replaceNullOrEmpty(
                    movieInfo.Element("audits")
                    .Elements("audit")
                    .Select(audit =>
                            Utils.XmlUtil.getElementValue(audit.Element("watchGradeNm"), "")
                            ).FirstOrDefault()
                    , "");
                string isAdult = (audits == "" || audits != "청소년관람불가") ? "N" : "Y";
                string nations = Utils.StringUtil.replaceNullOrEmpty(
                    movieInfo.Element("nations")
                    .Elements("nation")
                    .Select(nation =>
                            Utils.XmlUtil.getElementValue(nation.Element("nationNm"), "")
                            ).FirstOrDefault()
                    , "");
                nations = (openDt != "미개봉") ? "한국" : nations;
                var directors = movieInfo.Element("directors")
                                .Elements("director")
                                .Select(director =>
                                        Utils.XmlUtil.getElementValue(director.Element("peopleNm"), "")
                                        );
                var actors = movieInfo.Element("actors")
                             .Elements("actor")
                             .Select(actor =>
                                     Utils.XmlUtil.getElementValue(actor.Element("peopleNm"), "")
                                     );
                #endregion

                #region PEOPLE_DETAIL
                xDoc = XDocument.Load(
                    urlGenerator.peopleInfoAPI(
                        kobisInfo.Services[Constant.ApiList.PEOPLE_LIST],
                        kobiskey,
                        movieNm
                        )
                    );

                var peopleList = xDoc.Descendants("peopleListResult").Descendants("peopleList").Descendants("people").Select(info => info);

                string directorsCd = string.Join(",", peopleList.Where(p =>
                                                                       p.Element("repRoleNm").Value == "감독" &&
                                                                       directors.Contains(p.Element("peopleNm").Value)
                                                                       )
                                                 .Select(p =>
                                                         Utils.XmlUtil.getElementValue(p.Element("peopleCd"), "")
                                                         )
                                                 );
                string actorsCd = string.Join(",", peopleList.Where(p =>
                                                                    p.Element("repRoleNm").Value == "배우" &&
                                                                    actors.Contains(p.Element("peopleNm").Value)
                                                                    )
                                              .Select(p =>
                                                      Utils.XmlUtil.getElementValue(p.Element("peopleCd"), "")
                                                      )
                                              );
                #endregion

                #region TMDB_SEARCH
                System.Net.WebClient client = new System.Net.WebClient();
                client.Encoding = System.Text.Encoding.UTF8;

                var json = client.DownloadString(
                    urlGenerator.tmdbInfoAPI(
                        tmdbInfo.Services[Constant.ApiList.MOVIE_LIST],
                        tmdbkey, movieNm, movieNmEn, openDt
                        )
                    );

                Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(json);

                int    tmdbKey   = 0;
                string overview  = string.Empty;
                string poster    = string.Empty;
                string thumbnail = string.Empty;

                int findCount = Convert.ToInt32(jObject["total_results"]);
                Newtonsoft.Json.Linq.JArray jResult = ((Newtonsoft.Json.Linq.JArray)jObject["results"]);

                dynamic results;
                if (findCount > 1)
                {
                    results = jResult.Where(result =>
                                            result["release_date"].ToString().Replace("-", "") == openDt.Replace("미개봉", "")
                                            )
                              .Select(result => result
                                      ).FirstOrDefault();
                }
                else if (findCount == 1)
                {
                    results = jResult.Select(result => result).FirstOrDefault();
                }
                else
                {
                    results = null;
                }

                if (results != null)
                {
                    tmdbKey   = (results["id"] != null) ? Convert.ToInt32(results["id"].ToString()) : 0;
                    overview  = (results["overview"] != null) ? results["overview"].ToString() : "";
                    poster    = (results["poster_path"] != null) ? results["poster_path"].ToString() : "";
                    thumbnail = (results["backdrop_path"] != null) ? results["backdrop_path"].ToString() : "";

                    poster    = (poster != "") ? tmdbInfo.PosterRootUrl + poster : "";
                    thumbnail = (thumbnail != "") ? tmdbInfo.ThumbnailRootUrl + thumbnail : "";

                    string path = string.Format("{0}\\{1}\\", tmdbInfo.DownloadPath, movieCd);

                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }

                    using (System.Net.WebClient wc = new System.Net.WebClient())
                    {
                        if (poster.Trim() != "")
                        {
                            try
                            {
                                string filenm = poster.Substring(poster.LastIndexOf("/") + 1);
                                client.DownloadFile(new Uri(poster), path + filenm);
                                poster = poster.Replace(tmdbInfo.PosterRootUrl, string.Format("{0}/{1}", tmdbInfo.DownloadUrl, movieCd));
                            }
                            catch (System.Net.WebException)
                            {
                            }
                        }

                        if (thumbnail.Trim() != "")
                        {
                            try
                            {
                                string filenm = thumbnail.Substring(thumbnail.LastIndexOf("/"));
                                client.DownloadFile(new Uri(thumbnail), path + filenm);
                                thumbnail = thumbnail.Replace(tmdbInfo.ThumbnailRootUrl, string.Format("{0}/{1}", tmdbInfo.DownloadUrl, movieCd));
                            }
                            catch (System.Net.WebException)
                            {
                            }
                        }
                    }
                }
                #endregion

                movieXml.Add(
                    new XElement("movieList",
                                 new XElement("movieCd", movieCd),
                                 new XElement("movieNm", movieNm),
                                 new XElement("movieNmEn", movieNmEn),
                                 new XElement("movieNmOg", movieNmOg),
                                 new XElement("showTm", showTm),
                                 new XElement("openDt", openDt),
                                 new XElement("genres", genres),
                                 new XElement("audits", audits),
                                 new XElement("isAdult", isAdult),
                                 new XElement("nations", nations),
                                 new XElement("directors", directorsCd),
                                 new XElement("actors", actorsCd),
                                 new XElement("tmdbKey", tmdbKey),
                                 new XElement("overview", overview),
                                 new XElement("poster", poster),
                                 new XElement("thumbnail", thumbnail)
                                 )
                    );
                _scanCount++;
                printRealtimeCrawlCount();
            }
            history.closeFile();

            System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(string.Format("{0}\\crawled\\", kobisInfo.RootDir));

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            using (System.IO.StreamWriter record = new System.IO.StreamWriter(string.Format("{0}\\crawled\\{1}.xml", kobisInfo.RootDir, System.DateTime.Now.ToString("yyyyMMddhhmmss"))))
            {
                record.WriteLine(movieXml.ToString());
                record.Flush();
            }

            Console.WriteLine();
            Console.WriteLine("CRAWL COUNT : {0}", _scanCount);
        }
示例#6
0
        public JObject Process(string method, JArray _params)
        {
            JObject json = new JObject();

            switch (method)
            {
            case "unlock":
                //if (wallet == null) return "wallet is null.";
                if (ExtensionSettings.Default.WalletConfig.Path.Trim().Length < 1)
                {
                    throw new RpcException(-500, "Wallet file is exists.");
                }

                if (_params.Count < 2)
                {
                    throw new RpcException(-501, "parameter is error.");
                }
                string password = _params[0].AsString();
                int    duration = (int)_params[1].AsNumber();

                if (Unlocking)
                {
                    throw new RpcException(-502, "wallet is unlocking....");
                }

                Unlocking = true;
                try
                {
                    if (wallet == null)
                    {
                        wallet = OpenWallet(ExtensionSettings.Default.WalletConfig.Indexer, ExtensionSettings.Default.WalletConfig.Path, password);
                        walletTimeLock.SetDuration(wallet == null ? 0 : duration);
                        return($"success");
                    }
                    else
                    {
                        bool ok = walletTimeLock.UnLock(wallet, password, duration);
                        return(ok ? "success" : "failure");
                    }
                }
                finally
                {
                    Unlocking = false;
                }

            case "getutxos":
            {
                if (wallet == null || walletTimeLock.IsLocked())
                {
                    throw new RpcException(-400, "Access denied");
                }
                else
                {
                    //address,assetid
                    UInt160            scriptHash = _params[0].AsString().ToScriptHash();
                    IEnumerable <Coin> coins      = wallet.FindUnspentCoins();
                    UInt256            assetId;
                    if (_params.Count >= 2)
                    {
                        switch (_params[1].AsString())
                        {
                        case "bhp":
                            assetId = Blockchain.GoverningToken.Hash;
                            break;

                        case "gas":
                            assetId = Blockchain.UtilityToken.Hash;
                            break;

                        default:
                            assetId = UInt256.Parse(_params[1].AsString());
                            break;
                        }
                    }
                    else
                    {
                        assetId = Blockchain.GoverningToken.Hash;
                    }
                    coins = coins.Where(p => p.Output.AssetId.Equals(assetId) && p.Output.ScriptHash.Equals(scriptHash));

                    //json["utxos"] = new JObject();
                    Coin[] coins_array = coins.ToArray();
                    //const int MAX_SHOW = 100;

                    json["utxos"] = new JArray(coins_array.Select(p =>
                        {
                            return(p.Reference.ToJson());
                        }));

                    return(json);
                }
            }

            case "verifytx":
            {
                Transaction tx  = Transaction.DeserializeFrom(_params[0].AsString().HexToBytes());
                string      res = VerifyTransaction.Verify(Blockchain.Singleton.GetSnapshot(), new List <Transaction> {
                        tx
                    }, tx);

                json["result"] = res;
                if ("success".Equals(res))
                {
                    json["tx"] = tx.ToJson();
                }
                return(json);
            }

            case "claimgas":
            {
                if (wallet == null || walletTimeLock.IsLocked())
                {
                    throw new RpcException(-400, "Access denied");
                }
                else
                {
                    RpcCoins           coins = new RpcCoins(wallet, system);
                    ClaimTransaction[] txs   = coins.ClaimAll();
                    if (txs == null)
                    {
                        json["txs"] = new JArray();
                    }
                    else
                    {
                        json["txs"] = new JArray(txs.Select(p =>
                            {
                                return(p.ToJson());
                            }));
                    }
                    return(json);
                }
            }

            case "showgas":
            {
                if (wallet == null || walletTimeLock.IsLocked())
                {
                    throw new RpcException(-400, "Access denied");
                }
                else
                {
                    RpcCoins coins = new RpcCoins(wallet, system);
                    json["unavailable"] = coins.UnavailableBonus().ToString();
                    json["available"]   = coins.AvailableBonus().ToString();
                    return(json);
                }
            }

            case "getutxoofaddress":
            {
                string from    = _params[0].AsString();
                string jsonRes = RequestRpc("getUtxo", $"address={from}");

                Newtonsoft.Json.Linq.JArray jsons = (Newtonsoft.Json.Linq.JArray)JsonConvert.DeserializeObject(jsonRes);
                json["utxo"] = new JArray(jsons.Select(p =>
                    {
                        JObject peerJson        = new JObject();
                        peerJson["txid"]        = p["txid"].ToString();
                        peerJson["n"]           = (int)p["n"];
                        peerJson["value"]       = (double)p["value"];
                        peerJson["address"]     = p["address"].ToString();
                        peerJson["blockHeight"] = (int)p["blockHeight"];
                        return(peerJson);
                    }));
                return(json);
            }

            case "gettransaction":
            {
                string from     = _params[0].AsString();
                string position = _params[1].AsString() != "" ? _params[1].AsString() :"1";
                string offset   = _params[2].AsString() != "" ? _params[2].AsString() : "20";
                string jsonRes  = RequestRpc("findTxVout", $"address={from}&position={position}&offset={offset}");

                Newtonsoft.Json.Linq.JArray jsons = Newtonsoft.Json.Linq.JArray.Parse(jsonRes);

                json["transaction"] = new JArray(jsons.Select(p =>
                    {
                        JObject peerJson                 = new JObject();
                        peerJson["blockHeight"]          = p["blockHeight"].ToString();
                        peerJson["txid"]                 = p["txid"].ToString();
                        peerJson["type"]                 = p["type"].ToString();
                        Newtonsoft.Json.Linq.JToken[] jt = p["inAddress"].ToArray();
                        JArray j_inaddress               = new JArray();
                        foreach (Newtonsoft.Json.Linq.JToken i in jt)
                        {
                            string s = i.ToString();
                            j_inaddress.Add(s);
                        }
                        peerJson["inputaddress"]  = j_inaddress;
                        peerJson["asset"]         = p["asset"].ToString();
                        peerJson["n"]             = (int)p["n"];
                        peerJson["value"]         = (double)p["value"];
                        peerJson["outputaddress"] = p["address"].ToString();
                        peerJson["time"]          = p["time"].ToString();
                        peerJson["utctime"]       = (int)p["utcTime"];
                        peerJson["confirmations"] = p["confirmations"].ToString();
                        return(peerJson);
                    }));
                return(json);
            }

            case "get_tx_list":
            {
                string from     = _params[0].AsString();
                string position = _params[1].AsString() != "" ? _params[1].AsString() : "1";
                string offset   = _params[2].AsString() != "" ? _params[2].AsString() : "20";
                string jsonRes  = RequestRpc("findTxAddressRecord", $"address={from}&position={position}&offset={offset}");
                Newtonsoft.Json.Linq.JObject jsons = Newtonsoft.Json.Linq.JObject.Parse(jsonRes);
                json["transaction"] = new JArray(jsons["txAddressRecord"].Select(p =>
                    {
                        JObject peerJson                  = new JObject();
                        peerJson["txid"]                  = p["txid"].ToString();
                        peerJson["blockHeight"]           = p["blockHeight"].ToString();
                        peerJson["time"]                  = p["time"].ToString();
                        peerJson["type"]                  = p["type"].ToString();
                        Newtonsoft.Json.Linq.JToken [] jt = p["inAddressList"].ToArray();
                        JArray j_inaddress                = new JArray();
                        foreach (Newtonsoft.Json.Linq.JToken i in jt)
                        {
                            string s = i.ToString();
                            j_inaddress.Add(s);
                        }
                        peerJson["inputaddress"]  = j_inaddress;
                        peerJson["outputaddress"] = new JArray(p["outAddressList"].OrderBy(g => g["n"]).Select(k =>
                        {
                            JObject a    = new JObject();
                            a["n"]       = k["n"].ToString();
                            a["asset"]   = k["asset"].ToString();
                            a["value"]   = (double)k["value"];
                            a["address"] = k["outAddress"].ToString();
                            a["svalue"]  = k["svalue"].ToString();
                            return(a);
                        }));
                        return(peerJson);
                    }));
                return(json);
            }

            default:
                throw new RpcException(-32601, "Method not found");
            }
        }