Exemple #1
0
        public bool AddPost(BooruFile booruFile)
        {
            try
            {
                using (var connection = new SqliteConnection($"Data Source={dataSource}"))
                {
                    connection.Open();

                    var addPost = connection.CreateCommand();
                    addPost.CommandText =
                        "INSERT INTO posts values('" + (booruFile.md5 ?? Guid.NewGuid().ToString()) +
                        "', '" + (booruFile.site ?? "local") +
                        "', '" + (booruFile.ext ?? "") +
                        "', '" + (booruFile.artist ?? "anonymous") +
                        "', '" + (booruFile.rating ?? "unkown") +
                        "', " + (booruFile.score ?? (-1).ToString()) +
                        ", " + (booruFile.height ?? (-1).ToString()) +
                        ", " + (booruFile.width ?? (-1).ToString()) +
                        ", '" + (booruFile.date ?? DateTime.Now.ToString()) +
                        "', '" + (booruFile.source ?? "") +
                        "', '" + (booruFile.tags ?? "") +
                        "');";

                    //addPost.Parameters.AddWithValue("$md5", booruFile.md5 ?? Guid.NewGuid().ToString());
                    //addPost.Parameters.AddWithValue("$site", booruFile.site ?? "local");
                    //addPost.Parameters.AddWithValue("$ext", booruFile.ext ?? "");
                    //addPost.Parameters.AddWithValue("$artist", booruFile.artist ?? "anonymous");
                    //addPost.Parameters.AddWithValue("$rating", booruFile.rating ?? "unkown");
                    //addPost.Parameters.AddWithValue("$score", booruFile.score ?? (-1).ToString());
                    //addPost.Parameters.AddWithValue("$height", booruFile.height ?? (-1).ToString());
                    //addPost.Parameters.AddWithValue("$width", booruFile.width ?? (-1).ToString());
                    //addPost.Parameters.AddWithValue("$date", booruFile.date ?? DateTime.Now.ToString());
                    //addPost.Parameters.AddWithValue("$source", booruFile.source ?? "");
                    //addPost.Parameters.AddWithValue("$tags", booruFile.tags ?? "");

                    using (var reader = addPost.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var response = reader.GetString(0);

                            Console.WriteLine($"{response}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw ex;
            }

            return(true);
        }
Exemple #2
0
        public bool CreatePost(string fileName, BooruFile booruFile, bool cut = false)
        {
            try
            {
                if (File.Exists(fileName))
                {
                    var file = new FileInfo(fileName);
                    CreatePost(file, booruFile, cut);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            // -i="C:\\Files\\img.jpg"
            // -md5=612807eb63aedbf2488597aa3b59aa2c
            // -site=gelbooru
            // -ext=jpg
            // -artist=anonymous
            // -rating=questionable
            // -score=13
            // -width=100
            // -height=100
            // -date=12/12/12T12:00:00.0000Z
            // -source="http_pixiv.com..."
            // -tags="general:wet;general:bikini"
            // --cut

            try
            {
                var cut        = false;
                var fileOnly   = false;
                var parameters = new List <string>
                {
                    "i", "md5", "site", "ext", "artist", "rating", "score", "width", "height", "date", "source", "tags", "dir"
                };

                var argumentsDictionary = new Dictionary <string, string>();

                foreach (var arg in args)
                {
                    if (arg == "--cut")
                    {
                        cut = true;
                    }
                    else
                    {
                        foreach (var parameter in parameters)
                        {
                            var key = $"-{parameter}=";
                            if (arg.StartsWith(key))
                            {
                                argumentsDictionary[parameter] = arg.Substring(key.Length);
                            }
                        }
                    }
                }

                var  file = new FileInfo(args[0]);
                Post post = null;
                if (file.Extension == ".db")
                {
                    post = new Post(args[0], argumentsDictionary.ContainsKey("dir") ? argumentsDictionary["dir"] : "G:\\2.Anime\\1.Grabber\\");
                }
                else
                {
                    fileOnly = true;
                    post     = new Post("G:\\2.Anime\\1.Grabber\\grabber.db", "G:\\2.Anime\\1.Grabber\\");
                }

                if (post == null)
                {
                    return;
                }

                var booruFile = new BooruFile
                {
                    md5    = argumentsDictionary.ContainsKey("md5") ? argumentsDictionary["md5"] : Guid.NewGuid().ToString(),
                    site   = argumentsDictionary.ContainsKey("site") ? argumentsDictionary["site"] : "local",
                    ext    = argumentsDictionary.ContainsKey("ext") ? argumentsDictionary["ext"] : "",
                    artist = argumentsDictionary.ContainsKey("artist") ? argumentsDictionary["artist"] : "anonymous",
                    rating = argumentsDictionary.ContainsKey("rating") ? argumentsDictionary["rating"] : "unkown",
                    score  = argumentsDictionary.ContainsKey("score") ? argumentsDictionary["score"] : "-1",
                    width  = argumentsDictionary.ContainsKey("width") ? argumentsDictionary["width"] : "-1",
                    height = argumentsDictionary.ContainsKey("height") ? argumentsDictionary["height"] : "-1",
                    date   = argumentsDictionary.ContainsKey("date") ? argumentsDictionary["date"] : DateTime.Now.ToString(),
                    source = argumentsDictionary.ContainsKey("source") ? argumentsDictionary["source"] : "",
                    tags   = argumentsDictionary.ContainsKey("tags") ? argumentsDictionary["tags"] : ""
                };

                Console.WriteLine(booruFile.md5);

                if (argumentsDictionary.ContainsKey("i"))
                {
                    post.CreatePost(argumentsDictionary["i"], booruFile, cut);
                }
                else if (fileOnly)
                {
                    post.CreatePost(file, booruFile, true);
                }
                else
                {
                    post.AddPost(booruFile);
                }

                Console.WriteLine("End");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemple #4
0
        public bool CreatePost(FileInfo file, BooruFile booruFile, bool cut = false)
        {
            try
            {
                if (!file.Exists)
                {
                    return(false);
                }

                booruFile.site = booruFile.site ?? "local";
                booruFile.ext  = file.Extension;
                using (var image = Image.FromFile(file.FullName))
                {
                    booruFile.width  = image.Width.ToString();
                    booruFile.height = image.Height.ToString();
                }
                var directory = $"{workingDirectory}{(workingDirectory.EndsWith('\\') ? "" : "\\")}images\\{booruFile.site}\\";
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                var newFileName = $"{directory}{booruFile.md5}{booruFile.ext}";

                if (!File.Exists(newFileName))
                {
                    if (cut)
                    {
                        File.Move(file.FullName, newFileName);
                    }
                    else
                    {
                        File.Copy(file.FullName, newFileName);
                    }

                    try
                    {
                        return(AddPost(booruFile));
                    }
                    catch (Exception ex)
                    {
                        if (cut)
                        {
                            File.Move(newFileName, file.FullName);
                        }
                        else
                        {
                            File.Delete(newFileName);
                        }

                        throw ex;
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }
        }