Пример #1
0
 private DateTime DetermineDate( FileInfo fi, string type, string ext )
 {
     var theDate = DateTime.Now;
     var key = InferKey( fi, type, ext );
     if (Master.HaveMedia( key ))
     {
         var mi = new MediaItem {Filename = key};
         mi = Master.GetMedia( mi );
         theDate = mi.LibraryDate;
     }
     return theDate;
 }
Пример #2
0
 private void LogIt( MediaItem mi )
 {
     Logger.Info( string.Format( "  Adding {0,-60} - format:{1,-6}, type:{3,-6}, title:{2,-30}, dated:{4}",
                                 mi.Filename, mi.Format, mi.Title, mi.Type, mi.LibraryDate.ToShortDateString() ) );
 }
Пример #3
0
        private void AddMedia( MediaItem mi, bool latest )
        {
            if (latest)
            {
                var xmlItem = Master.GetMedia( mi ); //  filename is the key
                //  compare dates
                var libDate = xmlItem.LibraryDate;
                if (libDate < CutoffDate)
                {
            #if DEBUG
               Logger.Info( string.Format( "    {0} is old (library date {1})", mi.Filename, libDate.ToShortDateString() ) );
            #endif
               return;
                }
            #if DEBUG
            Logger.Info( string.Format( "    {0} is new - included in the latest", mi.Filename ) );
            #endif
             }

            if (ReportType.Equals( "TV Show Report" ))
            {
                if (!ListHasTitle( mi.Title ))
                {
                    LogIt( mi );
                    MediaList.Add( mi );
                }
            }
            else
            {
                if (!ListHas( mi.Filename ))
                {
                    LogIt( mi );
                    MediaList.Add( mi );
                }
            }
        }
Пример #4
0
 private void AddToLibrary( MediaItem mi )
 {
     Master.PutMedia( mi );
 }
Пример #5
0
        public void ProcessFile( string path, string parentDirectory, string extension, bool latest )
        {
            var fi = new FileInfo( path );

            if (!fi.Extension.Equals( "." + extension )) return;

            var action = "";
            var mi = new MediaItem {Filename = fi.Name};

            if (!IsValid( fi, extension )) return;

            var addIt = true;
            if (fi.Directory != null) mi.Type = InferType( fi.Directory.FullName );
            mi.LibraryDate = DetermineDate( fi, mi.Type, extension );
            mi.Format = extension;

            if (mi.Type.Equals( "Movie" ))
            {
                mi.Episode = "movie";
                //  for VOBs title is parents parent directory
                if (extension.Equals( "VOB" ))
                {
                    if (fi.Directory != null)
                    {
                        var dir = new FileInfo( fi.Directory.FullName );
                        if (dir.Directory != null) mi.Title = dir.Directory.Name;
                    }
                }
                else
                    //  avi or MKV
                    if (fi.Directory != null) mi.Title = fi.Directory.Name;
            }
            if (mi.Type.Equals( "TV" ))
            {
                //  set title from parent directory
                if (fi.Directory != null)
                {
                    var parent = new FileInfo( fi.Directory.FullName );
                    if (parent.Directory != null) mi.Title = parent.Directory.Name;
                }
                if (mi.Title.Equals( "TV" ))
                    Logger.Error( "No season directory for " + fi.Name );
                else
                {
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension( fi.Name );
                    if (fileNameWithoutExtension != null)
                        mi.Episode = fileNameWithoutExtension.Replace( '.', ' ' );
                    AddMedia( mi, latest );
                    AddToLibrary( mi );
                }
                addIt = false;
                action = "added";
            }

            if (addIt)
            {
                action = "added";
                AddMedia( mi, latest );
                if (!latest) AddToLibrary( mi ); //  xml

                Utility.Announce( string.Format( "Adding {0} from {1}", fi.Name, fi.DirectoryName ) );
            }
            action += " as " + mi.Title;
            #if DEBUG
             if ( latest )
                Logger.Info( string.Format( "File->{0,-50} - {1}", fi.FullName, action ) );
             //else
             //   action = "invalid";
            #endif
        }
Пример #6
0
 public void AddMediaItem( MediaItem m )
 {
     TheHT.Add( m.Filename, m );
 }
Пример #7
0
 private static void WriteMediaNode( XmlTextWriter writer, MediaItem m )
 {
     writer.WriteStartElement( "media-item" );
     WriteElement( writer, "filename", m.Filename );
     WriteElement( writer, "type", m.Type );
     WriteElement( writer, "title", m.Title );
     WriteElement( writer, "episode", m.Episode );
     WriteElement( writer, "libdate", m.LibraryDate.ToShortDateString() );
     writer.WriteEndElement();
 }
Пример #8
0
        public void PutMedia( MediaItem m )
        {
            if ( m.Filename.Equals( "VTS_01_0.VOB" ) )
            m.Filename = m.Title;

             if ( !TheHT.ContainsKey( m.Filename ) )
             {
            TheHT.Add( m.Filename, m );
            IsDirty = true;
             }
             else
             {
            Logger.Info( string.Format( "    {0} already in XML", m.Filename ) );
             }
        }
Пример #9
0
 public MediaItem GetMedia( MediaItem mi )
 {
     MediaItem m;
     if ( TheHT.ContainsKey( mi.Filename ) )
     {
     m = (MediaItem)TheHT[mi.Filename];
         CacheHits++;
     }
     else
     {
         //  new it up
         m = new MediaItem();
     m.Filename = mi.Filename;
     m.Title = mi.Title;
         m.LibraryDate = mi.LibraryDate;
         m.Episode = mi.Episode;
     m.Type = mi.Type;
     m.Format = mi.Format;
         PutMedia( m );
         CacheMisses++;
     }
     return m;
 }