Example #1
0
        /// <summary>
        /// Loads the pixbuf animation for image, tries loading from file directly, falls back
        /// on vidthumbs path.
        /// </summary>
        /// <returns>The pixbuf animation for image.</returns>
        /// <param name="path">Path.</param>
        /// <param name="md5">Md5.</param>
        public static Gdk.PixbufAnimation LoadPixbufAnimationForImage(string path, string md5)
        {
            Gdk.PixbufAnimation animation = null;

            var configVidthumbsPath = BooruApp.BooruApplication.Database.Config.GetString("vidthumbs.path");

            if (!string.IsNullOrEmpty(configVidthumbsPath))
            {
                animation = animation ?? PixbufLoader.LoadPixbufAnimationFromImageFile(configVidthumbsPath + "/" + md5 + ".jpg");
                animation = animation ?? PixbufLoader.LoadPixbufAnimationFromImageFile(configVidthumbsPath + "/" + md5 + ".png");
            }

            var configVidthumbsPath2 = BooruApp.BooruApplication.Database.Config.GetString("vidthumbs.path2");

            if (!string.IsNullOrEmpty(configVidthumbsPath2))
            {
                animation = animation ?? PixbufLoader.LoadPixbufAnimationFromImageFile(configVidthumbsPath2 + "/" + md5 + ".jpg");
                animation = animation ?? PixbufLoader.LoadPixbufAnimationFromImageFile(configVidthumbsPath2 + "/" + md5 + ".png");
            }

            animation = animation ?? PixbufLoader.LoadPixbufAnimationFromImageFile(path);
            animation = animation ?? new Gdk.PixbufAnimation(null, Resources.ID_PIXBUFS_NOPREVIEW);

            return(animation);
        }
Example #2
0
        private Gdk.PixbufAnimation LoadAnimation()
        {
            if (this.cachedAnimation != null)
            {
                return(this.cachedAnimation);
            }

            return(PixbufLoader.LoadPixbufAnimationForImage(this.Details));
        }
Example #3
0
 public static Gdk.PixbufAnimation LoadPixbufAnimationForImage(ImageDetails data)
 {
     return(PixbufLoader.LoadPixbufAnimationForImage(data.Path, data.MD5));
 }
Example #4
0
        public void ImportEntry(ImageEntry entry)
        {
            entry.Status = "Getting File Type";
            CallUpdate(entry);

            bool           callBooru = false;
            BooruImageType fileType  = BooruImageTypeHelper.IdentifyType(entry.path, out callBooru);

            switch (fileType)
            {
            case BooruImageType.Unknown:
                BooruApp.BooruApplication.Log.Log(BooruLog.Category.Files, BooruLog.Severity.Warning, "Unsupported file type: " + entry.path);
                entry.Status = "Unsupported file type";
                CallUpdate(entry);
                return;

            case BooruImageType.Image:
                entry.IsImage = true;
                entry.IsAnim  = false;
                break;

            case BooruImageType.Animation:
                entry.IsImage = true;
                entry.IsAnim  = true;
                break;

            case BooruImageType.Video:
                entry.IsImage = false;
                entry.IsAnim  = true;
                break;
            }

            entry.Status = "Getting MD5";
            CallUpdate(entry);
            entry.MD5 = GetEntryMD5(entry);

            List <string> tags;
            bool          tagMeExpired = false;
            ImageDetails  details      = BooruApp.BooruApplication.Database.GetImageDetails(entry.MD5);

            if (details != null)
            {
                tags = BooruApp.BooruApplication.Database.GetImageTags(entry.MD5);
                tags.Sort();
                entry.TagString = string.Join(" ", tags);

                var    timeSinceUpdate = DateTime.Now.Subtract(details.Updated);
                double daysSinceUpdate = timeSinceUpdate.TotalDays;
                entry.LastUpdated = ReadableTimeSpan(details.Updated);
                // has image a tagme tag and last update was some time ago, ask servers again
                if (tags.Contains("tagme") && daysSinceUpdate > 30)
                {
                    tagMeExpired = true;
                }
            }
            else
            {
                entry.LastUpdated = "never";
                tags = new List <string>();
            }
            entry.Tags = tags;
            CallUpdate(entry);

            bool askedServer = false;

            entry.Status = "Asking plugins...";
            CallUpdate(entry);

            if (BooruApp.BooruApplication.PluginLoader.TagFinderPlugins.FindTagsForFile(entry.path, entry.MD5, tagMeExpired, tags))
            {
                askedServer = true;
            }
            CallUpdate(entry);

            if (details == null)
            {
                var tmpPixBuf = PixbufLoader.LoadPixbufAnimationForImage(entry.path, entry.MD5);
                if (tmpPixBuf != null)
                {
                    BooruApp.BooruApplication.Database.SetImageSize(entry.MD5, new Point2D(tmpPixBuf.Width, tmpPixBuf.Height));
                    tmpPixBuf.Dispose();
                }
            }

            entry.TagString = string.Join(" ", entry.Tags);

            if (askedServer || details == null || details.Updated.Ticks == 0)
            {
                entry.Status = (details == null)?"Adding to DB":"Updating";
                CallUpdate(entry);
                if (details == null || askedServer)
                {
                    int tries = 1;
                    while (!BooruApp.BooruApplication.Database.AddImageIfNew(entry.path, entry.MD5, entry.TagString, fileType))
                    {
                        BooruApp.BooruApplication.Log.Log(BooruLog.Category.Files, BooruLog.Severity.Error, "Database error: " + entry.path);
                        entry.Status = string.Format("DB Error. Retrying... {0}", tries);
                        CallUpdate(entry);
                        tries++;
                        Thread.Sleep(1000);
                    }
                }
                Queries.Images.UpdateUpdated.Execute(entry.MD5);
                entry.Status = (details == null)?"Added":"Updated";
                CallUpdate(entry);
            }
            else
            {
                entry.Status = "No change";
                CallUpdate(entry);
            }
        }