public async Task <IActionResult> TvShows(string order = null) { var model = new TvShowViewModel { Order = order, files = analysisService.FindVideo(ShowSearchLocation) }; model.files = readService.ExtractMetaInfoFromMediaTitle(model.files).SuccessFiles; if (string.IsNullOrEmpty(order)) { model.files = model.files.Where(x => x.MediaInformation.IsMovie == false && x.MediaInformation.IsPersonal == false).OrderBy(x => x.MediaInformation.Name).ToList(); List <string> searchedFiles = new List <string>(); foreach (var f in model.files) { var matchName = searchedFiles.FirstOrDefault(x => x.Equals(f.MediaInformation.Name)); if (string.IsNullOrEmpty(matchName)) { searchedFiles.Add(f.MediaInformation.Name); var cacheResult = await tvdbService.GetFileCachedInfo(f); if (cacheResult != null) { f.FileImageUrl = cacheResult.SiteRelativeImageUrl; } else { f.FileImageUrl = DefaultImaageUrl; } } else { f.FileImageUrl = model.files.FirstOrDefault(x => x.MediaInformation.Name.Equals(f.MediaInformation.Name)).FileImageUrl; } } } else if (order.Equals("CreatedDesc", StringComparison.OrdinalIgnoreCase)) { model.files = model.files .Where(x => x.MediaInformation.IsMovie == false && x.MediaInformation.IsPersonal == false) .OrderByDescending(x => x.FileInfo.CreationTime).ToList(); } return(View(model)); }
public void OrganiseCopyMediaFiles(string input) { var videos = FindVideo(input); videos = readService.ExtractMetaInfoFromMediaTitle(videos).SuccessFiles; videos = programInterfaceService.UserManualFixFiles(videos); var movies = videos.Where(x => x.MediaInformation.IsMovie == true).ToList(); videos.RemoveAll(x => x.MediaInformation.IsMovie == true); var personal = videos.Where(x => x.MediaInformation.IsPersonal == true).ToList(); videos.RemoveAll(x => x.MediaInformation.IsPersonal == true); List <SeriesFileStructureModel> seriesFileStructures = new List <SeriesFileStructureModel>(); List <FileInformationModel> unknownFiles = new List <FileInformationModel>(); foreach (var video in videos) { if (seriesFileStructures.Count > 0) { try { if (!seriesFileStructures.Any(x => x.SeriesName.Equals(video.MediaInformation.Name))) { SeriesFileStructureModel seriesFileStructure = new SeriesFileStructureModel(); seriesFileStructure.Seasons = new List <string>(); seriesFileStructure.Seasons.Add(video.MediaInformation.Season); seriesFileStructure.SeriesName = video.MediaInformation.Name; seriesFileStructures.Add(seriesFileStructure); } else { if (!seriesFileStructures.Where(x => x.SeriesName.Equals(video.MediaInformation.Name)).Any(x => x.Seasons.Any(o => o.Equals(video.MediaInformation.Season)))) { int index = seriesFileStructures.FindIndex(x => x.SeriesName.Equals(video.MediaInformation.Name)); seriesFileStructures[index].Seasons.Add(video.MediaInformation.Season); } } } catch (Exception) { unknownFiles.Add(video); } } else { SeriesFileStructureModel seriesFileStructure = new SeriesFileStructureModel(); seriesFileStructure.Seasons = new List <string>(); seriesFileStructure.Seasons.Add(video.MediaInformation.Season); seriesFileStructure.SeriesName = video.MediaInformation.Name; seriesFileStructures.Add(seriesFileStructure); } } if (unknownFiles.Count > 0) { Console.WriteLine("Found {0} unknown files", unknownFiles.Count); Console.WriteLine("Writing unkown files to disk..."); var writeSuccess = writeService.WriteFilenamesToFile(unknownFiles); if (writeSuccess) { Console.WriteLine("Write Successful"); } else { Console.WriteLine("Write Failed"); } } var allVideos = new List <FileInformationModel>(); allVideos.AddRange(videos); allVideos.AddRange(movies); allVideos.AddRange(personal); Console.WriteLine("Found {0} movies", movies.Count()); foreach (var item in movies) { Console.WriteLine("{0} ({1})", item.MediaInformation.Name, item.MediaInformation.Year); } Console.WriteLine("Found {0} personal files", personal.Count()); foreach (var series in seriesFileStructures) { Console.WriteLine("{0}. {1} Seasons", series.SeriesName, series.Seasons.Count); } Console.WriteLine("Would you like to copy these series/movies?"); var uInput = Console.ReadLine(); if (uInput.Contains('y') || uInput.Contains('Y')) { writeService.CopyMediaFiles(seriesFileStructures, allVideos.Where(x => !string.IsNullOrEmpty(x.MediaInformation.Name)).ToList()); } Console.WriteLine("Could not read {0} files", unknownFiles.Count); Console.ReadLine(); }