private static FileInfoBase OrganisedLibraryTVShowFile(IFileSystem fileSystem, ITVShow tvShow) { // Initalise empty name. var path = ""; // Make clean extension. var extension = tvShow.File.Extension.Replace(".", ""); if (tvShow.SeasonNumber.HasValue && !string.IsNullOrEmpty (tvShow.Name)) { // If has SeasonNumber and has EpisodeName. path = string.Format ("{0}/Season {1}/{0} - S{1:D2}E{2:D2} - {3}.{4}", tvShow.TVShowName, tvShow.SeasonNumber, tvShow.EpisodeNumber, tvShow.Name, extension); } else if (tvShow.SeasonNumber.HasValue && string.IsNullOrEmpty (tvShow.Name)) { // If has SeasonNumber and has NO EpisodeName. path = string.Format ("{0}/Season {1}/{0} - S{1:D2}E{2:D2}.{3}", tvShow.TVShowName, tvShow.SeasonNumber, tvShow.EpisodeNumber, extension); } else if (!tvShow.SeasonNumber.HasValue && !string.IsNullOrEmpty (tvShow.Name)) { // If has NO SeasonNumber and has EpisodeName. path = string.Format ("{0}/{0} - E{1:D2} - {2}.{3}", tvShow.TVShowName, tvShow.EpisodeNumber, tvShow.Name, extension); } else if (!tvShow.SeasonNumber.HasValue && string.IsNullOrEmpty (tvShow.Name)) { // If has NO SeasonNumber and has NO EpisodeName. path = string.Format ("{0}/{0} - E{1:D2}.{2}", tvShow.TVShowName, tvShow.EpisodeNumber, extension); } // Get full file path and return FileInfo. var fullPath = fileSystem.Path.Combine (ResourceManager.TVShowLibrary.RootDirectory.FullName, path); return fileSystem.FileInfo.FromFileName (fullPath); }
public AddToLibrary(IFileSystem fileSystem, ITVShow tvShow, TextWriter stdOut=null, TextWriter stdErr=null) : base("AddToLibrary" + idCounter++, stdOut, stdErr) { _action = () => { // Create new tvShow file. var newFile = OrganisedLibraryTVShowFile (fileSystem, tvShow); LogOutput("Library path {0}", newFile.FullName); // Check not moving to itself. if (tvShow.File.FullName == newFile.FullName) { LogOutput("Can not move to self."); return; } // Create directory if it does not exist. if (!newFile.Directory.Exists) { LogOutput("Creating directory {0}", newFile.Directory.FullName); newFile.Directory.Create(); } // Copy. LogOutput("Copying {0} to {1}", tvShow.File.FullName, newFile.Directory.FullName); tvShow.File.CopyTo(newFile.FullName, true); }; }
public RemuxEncodeMetadataAndAddToLibrary(IFileSystem fileSystem, ITVShow tvShow, bool deleteOriginal, TextWriter stdOut=null, TextWriter stdErr=null) : base("RemuxEncodeMetadataAndAddToLibrary" + idCounter++, stdOut, stdErr) { _action = () => { // Create and set working area. var workingArea = fileSystem.DirectoryInfo.FromDirectoryName (fileSystem.Path.Combine (fileSystem.Path.Combine (fileSystem.Path.GetTempPath (), Assembly.GetExecutingAssembly().GetName().Name), this.GetType().Name)); if (!workingArea.Exists) { LogOutput("Creating working area at {0}.", workingArea.FullName); workingArea.Create(); } // Make working area file. var name = tvShow.File.Name.Replace(tvShow.File.Extension, "") + ".m4v"; var workingAreaFile = fileSystem.FileInfo.FromFileName(fileSystem.Path.Combine(workingArea.FullName, name)); // Make working area tvShow. var workingAreaTVShow = new WorkingTVShow(tvShow, workingAreaFile); // Remux. var remuxTask = new Remux(fileSystem, tvShow.File, workingAreaFile, StdOut, StdErr); LogOutput("Starting remux sub-task {0}.", remuxTask.Id); remuxTask.StdOut = StdOut; remuxTask.StdErr = StdErr; remuxTask.Invoke(); // Encode. var encodeTask = new EncodeMetadata(fileSystem, workingAreaTVShow, StdOut, StdErr); LogOutput("Starting encoding sub-task {0}.", encodeTask.Id); encodeTask.StdOut = StdOut; encodeTask.StdErr = StdErr; encodeTask.Invoke(); // Add to library. var addToLibrary = new AddToLibrary(fileSystem, workingAreaTVShow, StdOut, StdErr); LogOutput("Starting add to library sub-task {0}.", addToLibrary.Id); addToLibrary.StdOut = StdOut; addToLibrary.StdErr = StdErr; addToLibrary.Invoke(); // Delete working area tvShow file. LogOutput("Deleting working area file {0}.", workingAreaTVShow.File.Name); workingAreaTVShow.File.Delete(); // If delete original. if(deleteOriginal) { LogOutput("Deleting original file {0}.", tvShow.File.Name); tvShow.File.Delete(); } }; }
public async Task <ITVShow> GetTvShowDetailsAsync(string id, string language) { ITVShow details = _nfoFactory.CreateTVShow(); string url = $"http://my.scraper.url/search?id={id}&language={language}"; string content = await GetPageContent(url); // TODO : parse your content to create to fill the details return(details); }
public WorkingTVShow(ITVShow tvShow, FileInfoBase file) { File = file; Definition = tvShow.Definition; TVShowName = tvShow.TVShowName; SeasonNumber = tvShow.SeasonNumber; EpisodeNumber = tvShow.EpisodeNumber; Name = tvShow.Name; Description = tvShow.Description; Genres = tvShow.Genres; Cast = tvShow.Cast; Directors = tvShow.Directors; Screenwriters = tvShow.Screenwriters; ReleaseDate = tvShow.ReleaseDate; Network = tvShow.Network; Artwork = tvShow.Artwork; }
public async Task <SearchResultEntity[]> SearchByIdAsync(string id, string language, bool getPicture) { List <SearchResultEntity> result = new List <SearchResultEntity>(); ITVShow detail = await GetTvShowDetailsAsync(id, language); if (detail != null) { result.Add(new SearchResultEntity { Id = detail.Id, ItemType = ItemType.TVShow, Title = detail.Title, Year = detail.Premiered, }); } return(result.ToArray()); }
public TVShowController(IConfiguration config, ITVShow tvShow) { _config = config; _tvSHow = tvShow; }
public EncodeMetadata(IFileSystem fileSystem, ITVShow tvShow, TextWriter stdOut=null, TextWriter stdErr=null) : base("EncodeMetadata" + idCounter++, stdOut, stdErr) { _action = () => { // Create and set working area. var workingArea = fileSystem.DirectoryInfo.FromDirectoryName (fileSystem.Path.Combine (fileSystem.Path.Combine (fileSystem.Path.GetTempPath (), Assembly.GetExecutingAssembly().GetName().Name), this.GetType().Name)); if (!workingArea.Exists) { LogOutput("Creating working area at {0}.", workingArea.FullName); workingArea.Create(); } // Make temp encoding file and artwork file. var workingAreaEncodingFile = fileSystem.FileInfo.FromFileName(fileSystem.Path.Combine(workingArea.FullName, tvShow.File.Name)); var tempArtworkFile = tvShow.Artwork.ToFile(fileSystem); // Setup default arguments. var arguments = string.Format ("-source \"{0}\" -dest \"{1}\" ", tvShow.File.FullName, workingAreaEncodingFile.FullName); // Set metadata arguments. var metadataList = new Dictionary<string, string> (); metadataList ["Name"] = tvShow.Name; metadataList ["Artist"] = tvShow.TVShowName; metadataList ["Album"] = tvShow.TVShowName; metadataList ["Genre"] = string.Join (", ", tvShow.Genres); metadataList ["Release Date"] = tvShow.ReleaseDate.ToString ("yyyy-MM-dd"); metadataList ["Track #"] = string.Format ("{0}", tvShow.EpisodeNumber); metadataList ["TV Show"] = tvShow.TVShowName.ToString (); metadataList ["TV Episode #"] = tvShow.EpisodeNumber.ToString (); metadataList ["TV Network"] = tvShow.Network; metadataList ["TV Episode ID"] = string.Format("{0}{1:D2}", tvShow.SeasonNumber, tvShow.EpisodeNumber); metadataList ["TV Season"] = tvShow.SeasonNumber.ToString (); metadataList ["Description"] = tvShow.Description; metadataList ["Long Description"] = tvShow.Description; metadataList ["Cast"] = string.Join (", ", tvShow.Cast); metadataList ["Director"] = string.Join (", ", tvShow.Directors); metadataList ["Screenwriters"] = string.Join (", ", tvShow.Screenwriters); metadataList ["HD Video"] = ((int) tvShow.Definition).ToString(); metadataList ["Media Kind"] = "TV Show"; metadataList ["Artwork"] = tempArtworkFile.FullName; // Convert metadata arguments list to string. if (metadataList.Any ()) { arguments += " -metadata "; foreach (var metadata in metadataList) { arguments += string.Format ("\"{{{0}:{1}}}\"", metadata.Key, metadata.Value); } } // Encode. LogOutput("Encoding {0} to working area location {1}.", tvShow.File.FullName, workingAreaEncodingFile.FullName); if(External.Run(External.Application.SublerCLI, arguments, StdOut, StdErr).ExitCode!=0) { LogError("Encoding failed."); LogOutput("Deleting temp artwork file {0}.", tempArtworkFile.FullName); return; } // Delete temp artwork file. LogOutput("Deleting temp artwork file {0}.", tempArtworkFile.FullName); tempArtworkFile.Delete(); // Replace original file with newly created encoded file. LogOutput("Deleting original file {0}.", tvShow.File.FullName); tvShow.File.Delete(); LogOutput("Moving newly created encoded file {0} to orginal file location {1}.", workingAreaEncodingFile.FullName, tvShow.File.FullName); workingAreaEncodingFile.MoveTo(tvShow.File.FullName); }; }