Beispiel #1
0
        private void clean_series_season_files( IDirectoryItem directory )
        {
            foreach ( var subdirectory in directory.Items.OfType< IDirectoryItem >() )
            {
                string seasonNum;

                try
                {
                    seasonNum = subdirectory.FullName?.Length < 8 ? "99" : subdirectory.FullName?.Substring( 7 ).Trim();
                }
                catch ( Exception ex )
                {
                    Factory.Instance.LogLines.Enqueue( ex.Message );
                    Factory.Instance.LogLines.Enqueue( ex.StackTrace );
                    Factory.Instance.ItemProvider.BadNameFiles.Enqueue( new BadNameUpdate {Directory = subdirectory, File = null, SuggestName = ""} );
                    seasonNum = "99";
                }

                foreach ( var file in subdirectory.Items.OfType< IFileItem >() )
                {
                    if ( String.Compare( file.FullName, "Thumbs.db", StringComparison.Ordinal ) == 0 )
                    {
                        Factory.Instance.ItemProvider.DirectoryDeletions.Enqueue( new DeletionUpdate {Directory = subdirectory, File = file} );
                        continue;
                    }

                    var test1 = @"^" + Regex.Escape( directory.FullName ) + @"\s+-\s+(" + seasonNum + @")x[0-9]{2}";
                    var test2 = @"^" + Regex.Escape( directory.FullName ) + @"\s+-\s+(" + seasonNum + @")xSpecial\s+[0-9]+";

                    if ( Regex.IsMatch( file.FullName, test1, RegexOptions.IgnoreCase ) || Regex.IsMatch( file.FullName, test2, RegexOptions.IgnoreCase ) )
                    {
                        this.clean_series_season_files_check_episode_name( directory, subdirectory, file );
                        this.clean_series_season_file_check_extra( directory, subdirectory, file );
                        continue;
                    }
                    if ( Regex.IsMatch( file.FullName, @"^" + Regex.Escape( directory.FullName ) + @"\.? - (\[(.*?)\]).*?(\[(.*)\])", RegexOptions.IgnoreCase ) )
                    {
                        continue;
                    }

                    if ( Regex.IsMatch( file.FullName, @"^" + Regex.Escape( directory.FullName ) + @".*" ) == false )
                    {
                        Factory.Instance.ItemProvider.BadNameFiles.Enqueue( new BadNameUpdate {Directory = directory, File = file, SuggestName = ""} );
                    }
                    else if ( Regex.IsMatch( file.FullName, @".*?(" + seasonNum + @")x([0-9]{2}|(" + seasonNum + @")xSpecial\s+?[0-9]+)" ) == false )
                    {
                        const string stest1 = @".*?([0-9]+)x([0-9]{2})";
                        const string stest2 = @"([0-9]+)xSpecial\s+?([0-9]+)";

                        var match1 = Regex.Match( file.FullName, stest1 );
                        var match2 = Regex.Match( file.FullName, stest2 );

                        if ( !match1.Success && !match2.Success )
                        {
                            Factory.Instance.ItemProvider.BadNameFiles.Enqueue( new BadNameUpdate {Directory = directory, File = file, SuggestName = ""} );
                            continue;
                        }

                        var seasonint = match1.Success ? match1.Groups[ 1 ].Value : match2.Groups[ 1 ].Value;

                        var newdirectory = directory.Path + "\\Season " + seasonint;
                        var newfilelocation = directory.Path + "\\Season " + seasonint + "\\" + file.FullName;

                        Factory.Instance.ItemProvider.BadLocationFiles.Enqueue( new BadLocationUpdate {Directory = subdirectory, File = file, NewPath = newfilelocation} );

                        if ( Directory.Exists( newdirectory ) )
                        {
                            continue;
                        }

                        var missingdirectory = new DirectoryItem {Parent = directory, FullName = "Season " + seasonint, Path = newdirectory};
                        var di = new DirectoryInsert {Directory = directory, SubDirectory = missingdirectory, Seasonnum = int.Parse( seasonint )};
                        Factory.Instance.ItemProvider.NewDirectoryUpdates.Enqueue( di );
                    }
                }

                this.clean_series_season_files_find_missing( directory, subdirectory );
                this.clean_series_season_duplicates( directory );
            }
        }
Beispiel #2
0
        private void clean_series_top_level_directories( IDirectoryItem directory )
        {
            if ( directory?.Items == null )
            {
                return;
            }

            foreach ( var inode in directory.Items.OfType< IDirectoryItem >() )
            {
                if ( Regex.IsMatch( inode.FullName, @"^Season ([0-9]+)" ) )
                {
                    continue;
                }

                Factory.Instance.LogLines.Enqueue( @"Dirty directory name : " + inode.Path );
                Factory.Instance.ItemProvider.BadNameFiles.Enqueue( new BadNameUpdate {Directory = inode, File = null, SuggestName = ""} );
            }

            if ( Factory.Instance.Tvdb == null )
            {
                return;
            }

            foreach ( var series in Factory.Instance.Tvdb.get_series() )
            {
                if ( String.Compare( directory.FullName, series.get_name(), StringComparison.Ordinal ) != 0 )
                {
                    continue;
                }

                foreach ( var season in series.get_seasons() )
                {
                    var check = @"Season " + season.get_season_num();

                    if ( Factory.Instance.ItemProvider.contains_child( directory, check ) )
                    {
                        continue;
                    }

                    var missingseason = new DirectoryItem {FullName = check, Path = directory.Path + "\\" + check, Missing = true, Parent = directory};

                    foreach ( var episode in season.get_episodes() )
                    {
                        var epnum = season.get_season_num() + "x" + string.Format( "{0:00}", episode.get_episode_num() );
                        var fileitem = new FileItem {FullName = directory.FullName + " - " + epnum + " - " + episode.get_episode_name(), Missing = true, Parent = missingseason, Path = directory.Path + "\\" + check + "\\" + directory.FullName + " - " + epnum + " - " + episode.get_episode_name()};
                        missingseason.Items.Add( fileitem );

                        var torrent = this.clean_series_season_files_find_torrent( series.ImdbId, episode.get_episode_num(), season.get_season_num() );

                        if ( torrent.Epname != null && String.CompareOrdinal( torrent.Epname, "" ) != 0 )
                        {
                            fileitem.Torrent = true;
                            fileitem.TorrentLink = torrent.Magnetlink;
                        }
                    }

                    var di = new DirectoryInsert {Directory = directory, SubDirectory = missingseason, Seasonnum = season.get_season_num()};
                    Factory.Instance.ItemProvider.NewDirectoryUpdates.Enqueue( di );
                }

                break;
            }
        }