Beispiel #1
0
        private byte[] GetImg(string url, out string imgRating, int rating = 7)
        {
            var text = "alt=\"Rating: (Explicit|Safe|Questionable).*?href=\"(.*?)\">";

            if ((rating & 1) != 1)
            {
                text = text.Replace("|Safe", string.Empty);
            }

            if ((rating & 2) != 2)
            {
                text = text.Replace("|Questionable", string.Empty);
            }

            if ((rating & 4) != 4)
            {
                text = text.Replace("Explicit|", string.Empty);
            }

            var regex           = new Regex(text);
            var @string         = Encoding.UTF8.GetString(HttpNet.Get(url, null, null, null, Timeout, Proxy));
            var matchCollection = regex.Matches(@string);

            if (matchCollection.Count <= 0)
            {
                throw new Exception("没有匹配到任何图片,请检查页数或网络设置");
            }
            var i = Random.Next(0, matchCollection.Count - 1);

            imgRating = matchCollection[i].Groups[1].Value;
            return(HttpNet.Get(matchCollection[i].Groups[2].Value, null, null, null, Timeout, Proxy));
        }
Beispiel #2
0
 public static string GetName(long uid)
 {
     try
     {
         return(JObject.Parse(Encoding.UTF8.GetString(
                                  HttpNet.Get("https://api.bilibili.com/x/web-interface/card?mid=" + uid.ToString())))["data"][
                    "card"]
                ["name"].ToString());
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
Beispiel #3
0
        public int GetTagsPage(string tag)
        {
            var html = Encoding.UTF8.GetString(HttpNet.Get("https://yande.re/post?tags=" + tag, null, null, null,
                                                           Timeout, Proxy));
            var regex = new Regex("(\\d+)</a> <a [^<>]+?>Next");

            if (regex.IsMatch(html))
            {
                return(int.Parse(regex.Match(html).Groups[1].Value));
            }

            var regex1 = new Regex("alt=\"Rating: (Explicit|Safe|Questionable).*?href=\"(.*?)\">");

            return(regex1.IsMatch(html) ? 1 : 0);
        }
Beispiel #4
0
        public static bool GetCosHot(out string[] urls)
        {
            urls = Array.Empty <string>();
            string @string = Encoding.UTF8.GetString(HttpNet.Get(
                                                         $"https://api.vc.bilibili.com/link_draw/v2/Photo/list?category=cos&type=hot&page_num={random.Next(0, 15)}&page_size=20"));

            if (string.IsNullOrWhiteSpace(@string))
            {
                return(false);
            }

            JObject jObject;

            try
            {
                jObject = JObject.Parse(@string);
            }
            catch (Exception)
            {
                return(false);
            }

            if (jObject["code"].ToObject <int>() == 0)
            {
                JToken jToken = jObject["data"]["items"];
                if (jToken.Count() == 0)
                {
                    return(false);
                }

                int           num     = random.Next(0, jToken.Count() - 1);
                JToken        jToken2 = jToken[num]["item"]["pictures"];
                List <string> str     = new List <string>();

                for (int i = 0; i < jToken2.Count(); i++)
                {
                    str.Add(jToken2[i]["img_src"].ToString());
                }

                urls = str.ToArray();
                return(true);
            }

            return(false);
        }
Beispiel #5
0
        private List <CQCode> GetTweetContent(Tweet tweet)
        {
            var temp = new List <CQCode> {
                CQCode.CQText(tweet.Content)
            };
            var img = new List <CQCode>();

            if (tweet.Media != null)
            {
                foreach (var item in tweet.Media)
                {
                    try
                    {
                        var data = HttpNet.Get(item["media_url_https"].ToString(), proxy: _config.Proxy);
                        img.Add(CQCode.CQImage("base64://" + Convert.ToBase64String(data), useCache: true));
                    }
                    catch (Exception e)
                    {
                        img.Add(CQCode.CQText($"Error: {e.Message}"));
                    }

                    switch (item["type"].ToString())
                    {
                    case "photo":
                    {
                        break;
                    }

                    case "video":
                    {
                        var mp4 = item["video_info"]["variants"]
                                  .FirstOrDefault(video => video["content_type"].ToString() == "video/mp4");

                        if (mp4 != null)
                        {
                            img.Add(CQCode.CQText(mp4["url"].ToString()));
                            var data     = HttpNet.Get(mp4["url"].ToString(), proxy: _config.Proxy);
                            var tempPath = AppDomain.CurrentDomain.BaseDirectory + "cache\\" + HashHelp.MD5Encrypt(data);
                            File.WriteAllBytes(tempPath, data);
                            img.Add(CQCode.CQVideo(tempPath, useCache: true));
                        }
                        else
                        {
                            img.Add(CQCode.CQText(item["video_info"]["variants"][0]["url"].ToString()));
                        }
                        break;
                    }

                    case "animated_gif":
                    {
                        var mp4 = item["video_info"]["variants"]
                                  .FirstOrDefault(video => video["content_type"].ToString() == "video/mp4");
                        if (mp4 != null)
                        {
                            img.Add(CQCode.CQText(mp4["url"].ToString()));
                            var data     = HttpNet.Get(mp4["url"].ToString(), proxy: _config.Proxy);
                            var tempPath = AppDomain.CurrentDomain.BaseDirectory + "cache\\" + HashHelp.MD5Encrypt(data);
                            File.WriteAllBytes(tempPath, data);
                            img.Add(CQCode.CQVideo(tempPath, useCache: true));
                        }
                        else
                        {
                            img.Add(CQCode.CQText(item["video_info"]["variants"][0]["url"].ToString()));
                        }
                        break;
                    }
                    }
                }
            }

            if (tweet.IsOnlyRetweet)
            {
                if (tweet.Retweet == null)
                {
                    return(new List <CQCode> {
                        CQCode.CQText("error")
                    });
                }
                else
                {
                    var a = new List <CQCode> {
                        CQCode.CQText(tweet.Retweet.UserName + ":\n")
                    };
                    a.AddRange(GetTweetContent(tweet.Retweet));
                    return(a);
                }
            }
            else
            {
                var time = CQCode.CQText("\n发送时间:" + tweet.CreatTime.ToString("yyyy-MM-dd HH:mm"));
                if (tweet.Retweet == null)
                {
                    temp.AddRange(img);
                    temp.Add(time);
                    return(temp);
                }
                else
                {
                    temp.AddRange(img);
                    temp.Add(time);
                    temp.Add(CQCode.CQText("\n" + tweet.Retweet.UserName + ":\n"));
                    temp.AddRange(GetTweetContent(tweet.Retweet));
                    return(temp);
                }
            }
        }