Esempio n. 1
0
        private void txtCustomMovieFileNamingFormat_TextChanged(object sender, EventArgs e)
        {
            llCustomName.Text =
                CustomMovieName.NameFor(selectedShow, txtCustomMovieFileNamingFormat.Text);

            llFilenameDefaultFormat.Text = CustomMovieName.NameFor(selectedShow, TVSettings.Instance.MovieFilenameFormat);
        }
Esempio n. 2
0
        private void txtCustomMovieFileNamingFormat_TextChanged(object sender, EventArgs e)
        {
            llCustomName.Text =
                CustomMovieName.NameFor(selectedShow, txtCustomMovieFileNamingFormat.Text);

            llFilenameDefaultFormat.Text = selectedShow.ProposedFilename;
        }
        private void AddNewMovieToLibrary(PossibleNewMovie ai, bool isInLibraryFolderFileFinder, string?matchingRoot)
        {
            // need to add a new showitem
            MovieConfiguration found = new MovieConfiguration(ai);

            mDoc.FilmLibrary.Add(found);

            mDoc.Stats().AutoAddedMovies++;

            bool inDefaultPath = ai.Directory.Name.Equals(
                CustomMovieName.NameFor(found, TVSettings.Instance.MovieFolderFormat),
                StringComparison.CurrentCultureIgnoreCase);

            if (inDefaultPath && isInLibraryFolderFileFinder)
            {
                found.UseAutomaticFolders       = true;
                found.UseCustomFolderNameFormat = false;
                found.AutomaticFolderRoot       = matchingRoot !;
                found.UseManualLocations        = false;
                return;
            }

            if (isInLibraryFolderFileFinder)
            {
                found.AutomaticFolderRoot = matchingRoot !;
            }

            found.UseAutomaticFolders       = false;
            found.UseCustomFolderNameFormat = false;
            found.UseManualLocations        = true;
            found.ManualLocations.Add(ai.Directory.FullName);
        }
Esempio n. 4
0
 public MovieItemMissing([NotNull] MovieConfiguration movie, [NotNull] string whereItShouldBeFolder)
 {
     Episode      = null;
     Filename     = TVSettings.Instance.FilenameFriendly(CustomMovieName.NameFor(movie, TVSettings.Instance.MovieFilenameFormat));
     TheFileNoExt = whereItShouldBeFolder + System.IO.Path.DirectorySeparatorChar + Filename;
     Folder       = whereItShouldBeFolder;
     Movie        = movie;
 }
Esempio n. 5
0
        private void SetTagListText()
        {
            System.Text.StringBuilder tl = new System.Text.StringBuilder();

            foreach (string s in CustomMovieName.TAGS)
            {
                tl.AppendLine($"{s} - {CustomMovieName.NameFor(selectedShow, s)}");
            }

            txtTagList2.Text = tl.ToString();
        }
Esempio n. 6
0
        private static string TextJackettUrl(MovieConfiguration actionMovieConfig)
        {
            string       serverName = TVSettings.Instance.JackettServer;
            string       serverPort = TVSettings.Instance.JackettPort;
            string       allIndexer = TVSettings.Instance.JackettIndexer;
            string       apikey     = TVSettings.Instance.JackettAPIKey;
            const string FORMAT     = "{ShowName}";
            string?      text       = WebUtility.UrlEncode(CustomMovieName.NameFor(actionMovieConfig, FORMAT));

            return
                ($"http://{serverName}:{serverPort}{allIndexer}/api?t=movie&q={text}&apikey={apikey}");
        }
        private void AddToLibrary([NotNull] PossibleNewMovie ai)
        {
            if (ai.CodeUnknown)
            {
                return;
            }

            string?matchingRoot = TVSettings.Instance.MovieLibraryFolders.FirstOrDefault(s => ai.Directory.FullName.IsSubfolderOf(s));
            bool   isInLibraryFolderFileFinder = matchingRoot.HasValue();

            // see if there is a matching show item
            MovieConfiguration found = mDoc.FilmLibrary.GetMovie(ai);

            if (found is null)
            {
                AddNewMovieToLibrary(ai, isInLibraryFolderFileFinder, matchingRoot);
                return;
            }

            //We are updating an existing record

            string targetDirectoryName = CustomMovieName.NameFor(found, TVSettings.Instance.MovieFolderFormat);
            bool   inDefaultPath       = ai.Directory.Name.Equals(
                targetDirectoryName,
                StringComparison.CurrentCultureIgnoreCase);

            bool existingLocationIsDefaultToo = found.UseAutomaticFolders && found.AutomaticFolderRoot.In(TVSettings.Instance.MovieLibraryFolders.ToArray());

            if (inDefaultPath && isInLibraryFolderFileFinder && !existingLocationIsDefaultToo)
            {
                found.UseAutomaticFolders       = true;
                found.UseCustomFolderNameFormat = false;
                found.AutomaticFolderRoot       = matchingRoot !;
                //leave found.UseManualLocations alone to retain any existing manual locations
                return;
            }

            //we have an existing record that we need to add manual folders to

            if (isInLibraryFolderFileFinder && !found.AutomaticFolderRoot.HasValue())
            {
                //Probably in the library
                found.AutomaticFolderRoot = matchingRoot !;
            }

            found.UseManualLocations = true;
            if (!found.ManualLocations.Contains(ai.Directory.FullName))
            {
                found.ManualLocations.Add(ai.Directory.FullName);
            }
        }
Esempio n. 8
0
        private string AutoFolderNameForMovie()
        {
            if (string.IsNullOrEmpty(AutomaticFolderRoot))
            {
                return(string.Empty);
            }

            if (UseCustomNamingFormat)
            {
                return(AutomaticFolderRoot.EnsureEndsWithSeparator() + CustomMovieName.NameFor(this, CustomNamingFormat));
            }

            return(AutomaticFolderRoot.EnsureEndsWithSeparator() + CustomMovieName.NameFor(this, TVSettings.Instance.MovieFolderFormat));
        }
Esempio n. 9
0
        public CustomNameTagsFloatingWindow(MovieConfiguration?movie)
        {
            InitializeComponent();

            foreach (string s in CustomMovieName.TAGS)
            {
                string txt = s;
                if (movie != null)
                {
                    txt += " - " + CustomMovieName.NameFor(movie, s);
                }

                label1.Text += txt + "\r\n";
            }
        }
Esempio n. 10
0
        public AddEditMovie([NotNull] MovieConfiguration si, TVDoc doc)
        {
            selectedShow  = si;
            mDoc          = doc;
            addingNewShow = si.TvdbCode == -1;
            InitializeComponent();

            SetupDropDowns(si);

            lblSeasonWordPreview.Text = TVSettings.Instance.MovieFolderFormat + "-(" +
                                        CustomMovieName.NameFor(si,
                                                                TVSettings.Instance.MovieFolderFormat) + ")";

            lblSeasonWordPreview.ForeColor = Color.DarkGray;

            codeFinderForm =
                new CombinedCodeFinder(si.TmdbCode != -1 ? si.TmdbCode.ToString() : "", MediaConfiguration.MediaType.movie, si.Provider)
            {
                Dock = DockStyle.Fill
            };

            codeFinderForm.SelectionChanged += MTCCF_SelectionChanged;

            pnlCF.SuspendLayout();
            pnlCF.Controls.Add(codeFinderForm);
            pnlCF.ResumeLayout();

            cntfw = null;
            chkCustomShowName.Checked = si.UseCustomShowName;
            if (chkCustomShowName.Checked)
            {
                txtCustomShowName.Text = si.CustomShowName;
            }

            chkCustomRegion.Checked = selectedShow.UseCustomRegion;
            cbRegion.Text           = selectedShow.CustomRegionCode;

            UpdateCustomShowNameEnabled();

            SetupLanguages(si);

            cbDoRenaming.Checked     = si.DoRename;
            cbDoMissingCheck.Checked = si.DoMissingCheck;

            SetProvider(si);
            chkManualFolders.Checked = selectedShow.UseManualLocations;
            chkAutoFolders.Checked   = selectedShow.UseAutomaticFolders;
            PopulateRootDirectories(selectedShow.AutomaticFolderRoot);
            txtFolderNameFormat.Text            = selectedShow.CustomFolderNameFormat;
            txtCustomMovieFileNamingFormat.Text = selectedShow.CustomNamingFormat;
            cbUseCustomNamingFormat.Checked     = selectedShow.UseCustomNamingFormat;

            ActiveControl = codeFinderForm; // set initial focus to the code entry/show finder control

            foreach (string folder in selectedShow.ManualLocations)
            {
                lvManualFolders.Items.Add(folder);
            }

            PopulateAliasses();
            SetTagListText();
            EnableDisableCustomNaming();
            UpdateIgnore();
            SetMovieFolderType(si);
        }
Esempio n. 11
0
        private void CheckMovieFolder(MovieConfiguration si, DirFilesCache dfc, TVDoc.ScanSettings settings, string folder)
        {
            if (settings.Token.IsCancellationRequested)
            {
                return;
            }

            FileInfo[] files = dfc.GetFiles(folder);

            bool renCheck = TVSettings.Instance.RenameCheck && si.DoRename && Directory.Exists(folder); // renaming check needs the folder to exist

            bool missCheck = TVSettings.Instance.MissingCheck && si.DoMissingCheck;

            if (!renCheck && !missCheck)
            {
                return;
            }

            FileInfo[] movieFiles = files.Where(f => f.IsMovieFile()).ToArray();

            if (movieFiles.Length == 0)
            {
                FileIsMissing(si, folder, missCheck);
                return;
            }

            if (settings.Token.IsCancellationRequested)
            {
                return;
            }

            List <string> bases   = movieFiles.Select(GetBase).Distinct().ToList();
            string        newBase = TVSettings.Instance.FilenameFriendly(CustomMovieName.NameFor(si, TVSettings.Instance.MovieFilenameFormat));

            if (bases.Count == 1 && bases[0].Equals(newBase))
            {
                //All Seems OK

                //This is the code that will iterate over the DownloadIdentifiers and ask each to ensure that
                //it has all the required files for that show
                Doc.TheActionList.Add(downloadIdentifiers.ProcessMovie(si, movieFiles.First(m => m.Name.StartsWith(newBase, StringComparison.Ordinal))));

                return;
            }

            if (renCheck && bases.Count == 1 && !bases[0].Equals(newBase, StringComparison.CurrentCultureIgnoreCase))
            {
                foreach (FileInfo fi in files)
                {
                    if (settings.Token.IsCancellationRequested)
                    {
                        return;
                    }
                    string baseString = bases[0];

                    if (fi.Name.StartsWith(baseString, StringComparison.CurrentCultureIgnoreCase))
                    {
                        string   newName = fi.Name.Replace(baseString, newBase);
                        FileInfo newFile = FileHelper.FileInFolder(folder, newName); // rename updates the filename

                        if (newFile.IsMovieFile())
                        {
                            //This is the code that will iterate over the DownloadIdentifiers and ask each to ensure that
                            //it has all the required files for that show
                            Doc.TheActionList.Add(downloadIdentifiers.ProcessMovie(si, newFile));
                        }

                        if (newFile.FullName != fi.FullName)
                        {
                            //Check that the file does not already exist
                            //if (FileHelper.FileExistsCaseSensitive(newFile.FullName))
                            if (FileHelper.FileExistsCaseSensitive(files, newFile))
                            {
                                LOGGER.Warn(
                                    $"Identified that {fi.FullName} should be renamed to {newName}, but it already exists.");
                            }
                            else
                            {
                                LOGGER.Info($"Identified that {fi.FullName} should be renamed to {newName}.");
                                Doc.TheActionList.Add(new ActionCopyMoveRename(ActionCopyMoveRename.Op.rename, fi,
                                                                               newFile, si, false, null, Doc));

                                //The following section informs the DownloadIdentifers that we already plan to
                                //copy a file in the appropriate place and they do not need to worry about downloading
                                //one for that purpose
                                downloadIdentifiers.NotifyComplete(newFile);
                            }
                        }
                        else
                        {
                            if (fi.IsMovieFile())
                            {
                                //File is correct name
                                LOGGER.Debug($"Identified that {fi.FullName} is in the right place. Marking it as 'seen'.");
                                //Record this movie as seen

                                TVSettings.Instance.PreviouslySeenMovies.EnsureAdded(si);
                                if (TVSettings.Instance.IgnorePreviouslySeenMovies)
                                {
                                    Doc.SetDirty();
                                }
                            }
                        }
                    }
                } // foreach file in folder
            }
            else
            {
                if (movieFiles.First().IsMovieFile())
                {
                    //File is correct name
                    LOGGER.Debug($"Identified that {movieFiles.First().FullName} is in the right place. Marking it as 'seen'.");
                    //Record this movie as seen

                    TVSettings.Instance.PreviouslySeenMovies.EnsureAdded(si);
                    if (TVSettings.Instance.IgnorePreviouslySeenMovies)
                    {
                        Doc.SetDirty();
                    }
                }
            }
        }
Esempio n. 12
0
        public static void SearchForMovie(MovieConfiguration mov)
        {
            string       serverName = TVSettings.Instance.JackettServer;
            string       serverPort = TVSettings.Instance.JackettPort;
            const string FORMAT     = "{ShowName} ({Year})";

            string url = $"http://{serverName}:{serverPort}/UI/Dashboard#search={WebUtility.UrlEncode(CustomMovieName.NameFor(mov, FORMAT))}&tracker=&category=";

            Helpers.OpenUrl(url);
        }
Esempio n. 13
0
        protected override void FixInternal()
        {
            List <string> currentLocations = Movie.AutomaticLocations().ToList();
            string        newLocation      = Movie.AutomaticFolderRoot.EnsureEndsWithSeparator() + CustomMovieName.NameFor(Movie, TVSettings.Instance.MovieFolderFormat);

            Movie.UseCustomFolderNameFormat = false;

            if (!currentLocations.Any())
            {
                return;
            }
            string message = $"Could not move files for {Movie.ShowName}. Would have liked to move files from [{currentLocations.ToCsv()}] to '{newLocation}'";

            if (currentLocations.Count > 1)
            {
                LOGGER.Warn($"{message}, but there are more than one source. ");
                return;
            }

            string currentLocation = currentLocations.Single();

            if (currentLocation == newLocation)
            {
                //Nothing to do
                return;
            }

            LOGGER.Info($"Moving files from '{currentLocations.Single()}' to '{newLocation}'");

            if (Directory.Exists(newLocation))
            {
                LOGGER.Warn($"{message}, but that directory already exists.");
                return;
            }

            try
            {
                Directory.Move(currentLocations.Single(), newLocation);
            }
            catch (UnauthorizedAccessException uae)
            {
                throw new FixCheckException(message + ": " + uae.Message);
            }
            catch (DirectoryNotFoundException)
            {
                //the source was not present anyway, so do nothing
            }
            catch (PathTooLongException ptle)
            {
                throw new FixCheckException(message + ": " + ptle.Message);
            }
        }