public static int GetMediaCount(MediaType mediaType, RatingCategory ratingCategory, float[] minMax, double ratio) {
     using (Entities context = new Entities()) {
         if (ratingCategory.Name != "Intensity")
             return GetMediaQuery(context, mediaType, ratingCategory, minMax[0], minMax[1], ratio).Count();
         else
             return GetIntensityQuery(context, mediaType, ratingCategory, minMax[0], minMax[1], ratio).Count();
     }
 }
        /// <summary>
        /// Returns the default file name for specified video.
        /// </summary>
        /// <param name="artist">The video's artist.</param>
        /// <param name="title">The video's title.</param>
        /// <param name="folder">The folder where to place the file.</param>
        /// <param name="mediaType">The type of media.</param>
        /// <returns>A relative path and file excluding the extension.</returns>
        public string GetDefaultFileName(string artist, string title, Guid? category, MediaType mediaType) {
            bool ArtistHasFolder = false;
            string Folder = null;

            if (customFolder == null) {
                // Artist has its own folder if there are at least 5 videos in the database for that artist
                if (artist.Length > 0)
                    ArtistHasFolder = artistCount.Where(a => a.MediaType == mediaType && string.Equals(a.Artist, artist, StringComparison.OrdinalIgnoreCase) && a.Count >= 5).Any();

                // Folder is Category unless artist has 6 videos. If no category is specified, folder is Other.
                if (ArtistHasFolder)
                    Folder = artist;
                else if (category != null)
                    Folder = categories.FirstOrDefault(c => c.MediaCategoryId == category).Folder;
            } else {
                // A custom folder was requested, such as Downloads
                Folder = customFolder;
            }

            // Generate default path and file name.
            // string FolderName = Folder.Length > 0 ? folder : (artist.Length > 0 ? artist : "Other");
            string FileName;
            if (!ArtistHasFolder && artist.Length > 0)
                FileName = string.Format("{0} - {1}", artist, title);
            else
                FileName = title;

            if (customFolder == null) {
                if (mediaType == MediaType.Video) {
                    if (Folder == null)
                        Folder = "Others";
                } if (mediaType == MediaType.Audio) {
                    if (Folder != null)
                        Folder = "Audios\\" + Folder;
                    else
                        Folder = "Audios";
                } else if (mediaType == MediaType.Image) {
                    if (Folder != null)
                        Folder = "Images\\" + Folder;
                    else
                        Folder = "Images";
                }
            }

            // Remove illegal characters.
            foreach (char c in Path.GetInvalidPathChars()) {
                Folder = Folder.Replace(c.ToString(), "");
            }
            foreach (char c in Path.GetInvalidFileNameChars()) {
                FileName = FileName.Replace(c.ToString(), "");
            }
            // Avoid a duplicate '.' before the extension
            FileName = FileName.TrimEnd('.');
            // Avoid a '.' at the end of a folder name.
            Folder = Folder.TrimEnd('.');

            return String.Format("{0}\\{1}", Folder, FileName);
        }
        // public static readonly string AviSynthPluginsPath64 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Encoder_x64\");

        public static string[] GetMediaTypeExtensions(MediaType mediaType) {
            if (mediaType == MediaType.Video)
                return VideoExtensions;
            else if (mediaType == MediaType.Audio)
                return AudioExtensions;
            else if (mediaType == MediaType.Image)
                return ImageExtensions;
            else
                return null;
        }
 public static IQueryable<Media> GetMediaQuery(Entities context, MediaType mediaType, RatingCategory ratingCategory, double min, double max, double ratio) {
     var Query = (from m in context.Media
                  let val = (from r in m.MediaRatings
                             where r.RatingCategory.Name == ratingCategory.Name
                             select r.DbGetValue(r.Height, r.Depth, ratio)).FirstOrDefault()
                  where (mediaType == MediaType.None || m.MediaTypeId == (int)mediaType) &&
                     val != null && val > min && val <= max
                  orderby m.Artist, m.Title
                  select m);
     return Query;
 }
 public static IQueryable<Media> GetIntensityQuery(Entities context, MediaType mediaType, RatingCategory ratingCategory, double min, double max, double ratio) {
     var Query = (from m in context.Media
                      let val = (from r in m.MediaRatings
                                 let val = r.DbGetValue(r.Height, r.Depth, ratio)
                                 orderby val descending
                                 select val).Take(5).Average()
                  where (mediaType == MediaType.None || m.MediaTypeId == (int)mediaType) &&
                     val > min && val <= max
                  orderby m.Artist, m.Title
                  select m);
     return Query;
 }
 /// <summary>
 /// Returns a list of video count for each graph bar.
 /// </summary>
 /// <param name="mediaType">The type of media to return.</param>
 /// <param name="graphType">The rating type to generate the graph for.</param>
 /// <param name="ratio">The ratio to use when multiplying Height and Depth.</param>
 /// <returns>A list of 14 integers.</returns>
 public List<int> LoadGraph(MediaType mediaType, RatingCategory graphType, double ratio) {
     List<int> Result = new List<int>();
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[0], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[1], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[2], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[3], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[4], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[5], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[6], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[7], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[8], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[9], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[10], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[11], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[12], ratio));
     Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[13], ratio));
     return Result;
 }
 public Media GetVideoByTitle(MediaType mediaType, string artist, string title) {
     Media Result = (from v in context.Media
                     where v.MediaTypeId == (int)mediaType && v.Artist == artist && v.Title == title
                     select v).Include(v => v.MediaRatings.Select(r => r.RatingCategory)).FirstOrDefault();
     return Result;
 }
 /// <summary>
 /// Returns a list of video count for each graph bar.
 /// </summary>
 /// <param name="mediaType">The type of media to return.</param>
 /// <param name="graphType">The rating type to generate the graph for.</param>
 /// <param name="ratio">The ratio to use when multiplying Height and Depth.</param>
 /// <returns>A list of 14 integers.</returns>
 public async Task<List<int>> LoadGraphAsync(MediaType mediaType, RatingCategory graphType, double ratio) {
     return await Task.Run(() => LoadGraph(mediaType, graphType, ratio));
 }
 private bool OrphanMatchesConditions(MediaType mediaType, string fileName, SearchSettings settings) {
     bool Result = true;
     Result = (settings.MediaType == MediaType.None || mediaType == settings.MediaType) &&
                 (string.IsNullOrEmpty(settings.Search) || (fileName != null && fileName.IndexOf(settings.Search, StringComparison.OrdinalIgnoreCase) != -1)) &&
                 (string.IsNullOrEmpty(settings.RatingCategory) || !settings.RatingValue.HasValue) &&
                 (settings.HasRating == HasRatingEnum.All || settings.HasRating == HasRatingEnum.Without);
     foreach (SearchConditionSetting item in settings.ConditionFilters) {
         if (!(item.Field == FieldConditionEnum.None || item.Value == BoolConditionEnum.None ||
             (item.Field == FieldConditionEnum.IsInDatabase && item.Value == BoolConditionEnum.No) ||
             (item.Field == FieldConditionEnum.FileExists && item.Value == BoolConditionEnum.Yes) ||
             (item.Field == FieldConditionEnum.HasDownloadUrl && item.Value == BoolConditionEnum.No)))
             Result = false;
     }
     return Result;
 }
 /// <summary>
 /// Initializes a new instance of the SearchSettings class.
 /// </summary>
 /// <param name="mediaType">The type of media to return.</param>
 /// <param name="excludeVideos">A list of videos to exclude from the search.</param>
 /// <param name="allowDownloading">False to allow downloading from the Internet, True to search only local files.</param>
 /// <param name="ratingRatio">A number between -1 and 1 representing the rating Heigth/Depth priority ratio.</param>
 public SearchSettings(MediaType mediaType, List<Guid> excludeVideos, bool allowDownloading, double ratingRatio):this() {
     this.MediaType = mediaType;
     this.ExcludeVideos = excludeVideos;
     this.AllowDownloading = allowDownloading;
     this.RatingRatio = ratingRatio;
 }