Exemple #1
0
        private void UpdateFileRating(PlexRatingsData currentFile)
        {
            uint?fileRating     = RatingsManager.FileRating(currentFile.file);
            int? plexFileRating = RatingsManager.PlexRatingFromFile(currentFile.file);
            int? plexDbRating   = (int?)currentFile.rating;

            uint?newRating = Convert.ToUInt32(RatingsManager.FileRatingFromPlexRating(plexDbRating));

            if (newRating == 0)
            {
                newRating = null;
            }

            string message = string.Format("Updating file rating for file \"{0}\", from {1} to {2}",
                                           currentFile.file,
                                           fileRating == null ? 0 : fileRating,
                                           newRating == null ? 0 : newRating);

            ShellFile so = ShellFile.FromFilePath(currentFile.file);

#if DEBUG
            Debug.Print(message);
#else
            so.Properties.System.Rating.Value = newRating;
#endif

            MessageManager.Instance.MessageWrite(this, MessageItem.MessageLevel.Information, message);
        }
Exemple #2
0
        private void SyncRating(PlexRatingsData currentFile)
        {
            try
            {
                if (currentFile != null && File.Exists(currentFile.file))
                {
                    try
                    {
                        int?plexFileRating = RatingsManager.PlexRatingFromFile(currentFile.file);
                        int?plexDbRating   = (int?)currentFile.rating;

                        if (plexFileRating != plexDbRating)
                        {
                            // NOTE: Plex wins if both the file and db have ratings that are different
                            if (plexDbRating != null)
                            {
                                UpdateFileRating(currentFile);
                            }
                            else
                            {
                                UpdatePlexDbRating(currentFile);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageManager.Instance.ExceptionWrite(this, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageManager.Instance.ExceptionWrite(this, ex);
            }
        }
Exemple #3
0
        private void UpdatePlexDbRating(PlexRatingsData currentFile)
        {
            int?plexFileRating = RatingsManager.PlexRatingFromFile(currentFile.file);
            int?plexDbRating   = (int?)currentFile.rating;

            string sql     = string.Empty;
            string message = string.Empty;

            // the rating(s) of a given file
            sql = string.Format(
                @"SELECT * FROM metadata_item_settings WHERE account_id = {0} AND guid = '{1}';",
                Settings.PlexAccountId, currentFile.guid);

            if (m_PlexDb.RecordsExists(sql))
            {
                message = string.Format("Updating Plex rating for file \"{0}\" from {1} to {2}",
                                        currentFile.file,
                                        plexDbRating == null ? 0 : plexDbRating,
                                        plexFileRating == null ? 0 : plexFileRating);

                MessageManager.Instance.MessageWrite(this, MessageItem.MessageLevel.Information,
                                                     message);

                bwProcess.ReportProgress(-2);

                // Update a rating entry
                sql = @"
UPDATE metadata_item_settings SET rating = {0} WHERE account_id = {1} AND guid = '{2}'";

                sql = string.Format(sql, plexFileRating, Settings.PlexAccountId, currentFile.guid);
            }
            else
            {
                message = string.Format("Creating Plex rating for file \"{0}\", rating {1}",
                                        currentFile.file,
                                        plexFileRating == null ? 0 : plexFileRating);

                MessageManager.Instance.MessageWrite(this, MessageItem.MessageLevel.Information,
                                                     message);

                bwProcess.ReportProgress(-3);

                // Create a rating entry
                sql = @"
INSERT INTO metadata_item_settings ([account_id], [guid], [rating], [view_offset], [view_count], [last_viewed_at], [created_at], [updated_at])
VALUES({0}, '{1}', {2}, NULL, 0, NULL, DATE('now'), DATE('now'));";

                sql = string.Format(sql, Settings.PlexAccountId, currentFile.guid, plexFileRating);
            }
#if DEBUG
            Debug.Print(message);
#else
            m_PlexDb.ExecutePlexSql(sql);
#endif
        }