Esempio n. 1
0
        public frmManualFetch(MovieEntry entry, MetadataAccessor accessor)
        {
            InitializeComponent();

            m_entry = entry;
            m_accessor = accessor;
        }
Esempio n. 2
0
        /// <summary>
        /// Saves a new watching session and creates a new movie if necessary
        /// </summary>
        /// <param name="movieEntry">A movie entry</param>
        /// <returns>A JSON representation of a timeline entry</returns>
        public JsonResult QuickSave(MovieEntry movieEntry)
        {
            // Used to emulate a failure
            if (movieEntry.Director == "FAIL") {
                throw new Exception("Une erreur");
            }

            WatchingSession watchingSession;
            using (var uow = new UnitOfWork(true)) {
                var movie = uow.Movies.FindByTitle(movieEntry.Title) ??
                            new Movie() { Title = movieEntry.Title, Director = movieEntry.Director };

                watchingSession = new WatchingSession() { Date = DateTime.ParseExact(movieEntry.EntryDate, "dd/MM/yyyy", null) };
                movie.AddWatchingSession(watchingSession);

                uow.Movies.SaveOrUpdate(movie);
                uow.Commit();
            }

            var timelineEntry = new TimelineEntry(watchingSession, this);
            return Json(timelineEntry);
        }
Esempio n. 3
0
        /// <summary>
        /// Load list of movies and metadata from library.
        /// </summary>
        public void LoadLibraryMovies(string libraryPath)
        {
            // Ensure this library was not already added.
            if (m_libraryPaths.Contains(libraryPath))
                return;

            // Add library directory to the list of libraries.
            m_libraryPaths.Add(libraryPath);

            // Get library subdirectories.
            AppLog.Instance.Log(AppLog.Severity.Debug, "Looking into library directory '" + libraryPath + "' for movies.");

            string[] movieDirs;
            try
            {
               movieDirs = Directory.GetDirectories(libraryPath);
            }
            catch (IOException exc)
            {
                AppLog.Instance.Log(AppLog.Severity.Error, "Couldn't access library directory '" + libraryPath + "': " + exc.Message);

                // Re-throw exception to caller.
                throw exc;
            }

            // Load movies from library path.
            foreach (string movieDir in movieDirs)
            {
                MovieEntry entry = new MovieEntry();
                entry.movieTag = movieDir.Substring(movieDir.LastIndexOf('\\') + 1);
                entry.moviePath = movieDir;
                entry.libraryPath = libraryPath;
                entry.movie = null;

                // Make sure there is no duplicate entry in the list.
                if (m_movies.Contains(entry.moviePath))
                    continue;

                Exception loadException = null;
                try
                {
                    // Load the movie metadata (if any).
                    entry.movie = LoadMovieMetadata(movieDir);

                    if (entry.movie == null)
                        AppLog.Instance.Log(AppLog.Severity.Debug, "\tNo metadata found for movie '" + entry.movieTag + "'.");
                    else
                        AppLog.Instance.Log(AppLog.Severity.Debug, "\tLoaded metadata for movie '" + entry.movieTag + "'.");
                }
                catch (Exception exc)
                {
                    AppLog.Instance.Log(AppLog.Severity.Error, "\tFailed to load metadata for movie '" + entry.movieTag + "'. Reason: " + exc.Message);
                    loadException = exc;
                }

                // Add the movie to the list.
                m_movies.Add(entry);

                // Notify event subscribers.
                MovieLoaded(entry, loadException);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Deletes all metadata associated with a movie.
        /// </summary>
        /// <param name="entry">Movie to delete metadata.</param>
        public void FlushMovieMetadata(MovieEntry entry)
        {
            AppLog.Instance.Log(AppLog.Severity.Debug, "Flushing metadata for movie '" + entry.moviePath + "'.");
            string metadataPath = entry.moviePath + "\\" + Constants.METADATA_PATH;
            string metadataFile = metadataPath + "\\" + Constants.METADATA_FILE;

            Exception deleteException = null;
            try
            {
                // Tell data managers to clear metadata.
                foreach (DataManager manager in m_dataManagers)
                    manager.Clear(entry);

                if (Directory.Exists(metadataPath))
                {
                    if (File.Exists(metadataFile))
                        File.Delete(metadataFile);

                    // Delete associated images.
                    if (entry.movie != null)
                    {
                        foreach (MovieImage mi in entry.movie.Images)
                        {
                            if (File.Exists(mi.path))
                                File.Delete(mi.path);
                        }
                    }

                    // Try to delete directory.
                    Directory.Delete(metadataPath);
                }

            }
            catch (Exception exc)
            {
                deleteException = exc;
            }

            // Clear movie metadata.
            entry.movie = null;

            // Re-throw delete exception if one occurred.
            if (deleteException != null)
                throw deleteException;
        }
Esempio n. 5
0
        /// <summary>
        /// Fetches metadata for a given movie. This method is
        /// thread-safe. Throws an exception on failure.
        /// </summary>
        /// <param name="entry">Entry to fetch.</param>
        public void FetchMovieMetadata(MovieEntry entry)
        {
            if (!m_movies.Contains(entry))
                throw new Exception("Movie entry does not exist in library.");

            // Clear previous metadata if it exists.
            FlushMovieMetadata(entry);

            AppLog.Instance.Log(AppLog.Severity.Debug, "Fetching metadata for '" + entry.moviePath + "'.");

            // Create metadata directory for movie if it doesn't exist.
            CreateMetadataDir(entry.moviePath);

            // If the ID was not provided, search for movie and pick first result.
            string movieID;
            if (!string.IsNullOrEmpty(entry.manualID))
            {
                movieID = entry.manualID;
            }
            else
            {
                IEnumerable<MovieSearchResult> results = m_accessor.SearchMovies(entry.movieTag, null);
                if (results.Count() < 1)
                    throw new NoResultsFoundException("No results found for specified movie.");

                MovieSearchResult result = results.First();
                movieID = result.ID;
            }

            // Fetch the movie.
            Movie movie = m_accessor.FetchMovie(movieID, entry.moviePath + "\\" + Constants.METADATA_PATH);

            lock (entry)
            {
                entry.movie = movie;

                // Write the metadata to disk.
                WriteMovieMetadata(entry.moviePath, entry.movie);

                // Notify data managers of the change.
                foreach (DataManager manager in m_dataManagers)
                    manager.Add(entry);
            }
        }
Esempio n. 6
0
        private static string[] GetID(MovieEntry entry)
        {
            // Concatenate the header and first 8 characters of
            // the MD5 of the full path to the movie to construct the id.
            MD5 hasher = MD5.Create();
            byte[] hashData = hasher.ComputeHash(Encoding.Default.GetBytes(entry.moviePath));

            StringBuilder hash = new StringBuilder();
            for (int i = 0; i < 4; i++)
                hash.Append(hashData[i].ToString("X2"));

            string[] idparts = new string[2];
            idparts[0] = DVDID_HEADER;
            idparts[1] = hash.ToString();

            return idparts;
        }
Esempio n. 7
0
        public void Clear(MovieEntry entry)
        {
            string[] idparts = GetID(entry);

            string dvdidFile = entry.moviePath + "\\" + entry.movieTag + ".dvdid.xml";
            if (File.Exists(dvdidFile))
                File.Delete(dvdidFile);

            string dvdinfofile = m_infoCachePath + "\\" + idparts[0] + "-" + idparts[1] + ".xml";
            if (File.Exists(dvdinfofile))
                File.Delete(dvdinfofile);

            string dvdimagefile = m_imageCachePath + "\\" + idparts[0] + "-" + idparts[1] + ".jpg";
            if (File.Exists(dvdimagefile))
                File.Delete(dvdimagefile);
        }
Esempio n. 8
0
        public void Add(MovieEntry entry)
        {
            if (entry.movie == null)
                return;

            string[] idparts = GetID(entry);
            string dvdidFile = entry.moviePath + "\\" + entry.movieTag + ".dvdid.xml";
            if (!File.Exists(dvdidFile))
            {
                // Create dvdid file.
                XDocument idDoc = GenerateIDXML(entry.movie, idparts);
                idDoc.Save(dvdidFile);
            }

            string dvdinfofile = m_infoCachePath + "\\" + idparts[0] + "-" + idparts[1] + ".xml";
            if (!File.Exists(dvdinfofile))
            {
                // Create dvdinfo file.
                XDocument infoDoc = GenerateInfoXml(entry.movie, idparts);
                infoDoc.Save(dvdinfofile);
            }

            string dvdimagefile = m_imageCachePath + "\\" + idparts[0] + "-" + idparts[1] + ".jpg";
            if (!File.Exists(dvdimagefile))
            {
                // Resize and save image to image cache as JPEG.
                if (entry.movie.Images.Count > 0)
                {
                    string sourceImage = entry.movie.Images.First().path;

                    using (Bitmap originalImage = new Bitmap(sourceImage))
                    {
                        using (Bitmap resizedImage = new Bitmap(COVER_RESIZE_WIDTH, COVER_RESIZE_HEIGHT))
                        {
                            using (Graphics surface = Graphics.FromImage(resizedImage))
                            {
                                surface.SmoothingMode = SmoothingMode.AntiAlias;
                                surface.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                surface.PixelOffsetMode = PixelOffsetMode.HighQuality;
                                surface.DrawImage(originalImage, 0, 0, resizedImage.Width, resizedImage.Height);
                            }

                            resizedImage.Save(dvdimagefile, ImageFormat.Jpeg);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
            public void FetchAsync(MovieEntry entry)
            {
                m_doneEvent.Reset();

                Thread workerThread = new Thread(new ParameterizedThreadStart(DoFetch));
                workerThread.Start(entry);
            }
Esempio n. 10
0
        private void FetchMetadataManual(MovieEntry entry)
        {
            // Show the manual metadata fetch form.
            frmManualFetch dialog = new frmManualFetch(entry, m_library.GetMetadataAccessor());
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                // Fetch the selected item by ID. Use the same fetching
                // infrastructure as with the automated fetch.
                List<MovieEntry> entries = new List<MovieEntry>();

                entry.manualID = dialog.SelectedID;
                entries.Add(entry);

                FetchMetadata(entries);
            }
        }
Esempio n. 11
0
        private void AddMetadataWithout(MovieEntry entry, string errorMessage = null)
        {
            // Add item to 'without' list.
            ListViewItem item = new ListViewItem();
            item.Tag = entry;
            item.Text = "";

            if (errorMessage != null)
            {
                item.ImageIndex = 0;
                item.ToolTipText = errorMessage;
            }

            item.SubItems.Add(entry.movieTag);
            item.SubItems.Add(entry.moviePath);
            lvMetadataWithout.Items.Add(item);
        }
Esempio n. 12
0
 private void AddMetadataWith(MovieEntry entry)
 {
     // Add item to 'with' list.
     ListViewItem item = new ListViewItem();
     item.Tag = entry;
     item.Text = "";
     item.SubItems.Add(entry.movie.Name);
     item.SubItems.Add((entry.movie.Released != null) ? entry.movie.Released.Value.Year.ToString() : "");
     lvMetadataWith.Items.Add(item);
 }
Esempio n. 13
0
 public void MovieLoadEventHandler(MovieEntry entry, Exception loadException)
 {
     // Add the item to the correct list (depending on whether or
     // not it already has metadata available).
     if (entry.movie != null)
     {
         AddMetadataWith(entry);
     }
     else
     {
         if (loadException != null)
             AddMetadataWithout(entry, "Error loading metadata for movie from file.");
         else
             AddMetadataWithout(entry);
     }
 }