Ejemplo n.º 1
0
        private void buttonResultsEdit_Click(object sender, EventArgs e)
        {
            MovieTag tag = (MovieTag)listViewResults.SelectedItems[0].Tag;

            Add form = new Add(true, tag.Search, tag.Results);

            form.ShowDialog();

            if (form.SelectedMovie != null)
            {
                tag.Search  = form.SelectedMovie.Name;
                tag.Results = form.SearchResults;
                listViewResults.SelectedItems[0].Tag = tag;

                listViewResults.SelectedItems[0].SubItems[1].Text = form.SelectedMovie.Name;

                if (form.SelectedMovie.Released != null)
                {
                    listViewResults.SelectedItems[0].SubItems[2].Text = form.SelectedMovie.Released.Value.Year.ToString();
                }
                else
                {
                    listViewResults.SelectedItems[0].SubItems[2].Text = "";
                }

                listViewResults.SelectedItems[0].SubItems[3].Text = "Movie manually selected";
                listViewResults.SelectedItems[0].ForeColor        = Color.Purple;
            }
        }
Ejemplo n.º 2
0
        private void buttonResultsAdd_Click(object sender, EventArgs e)
        {
            foreach (Movie movie in addMovies)
            {
                string folder = Program.Settings.MovieDirectory + @"\" + Program.Settings.MovieDirectoryStructure;
                folder = folder.Replace("<title>", movie.Title.Replace(':', '-'));
                folder = folder.Replace("<year>", movie.Released.Value.Year.ToString());

                // Create folder
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }

                // Move file
                foreach (string filename in movie.Filenames)
                {
                    if (!File.Exists(folder + @"\" + Path.GetFileName(filename)))
                    {
                        FileInfo file = new FileInfo(filename);
                        if (Program.Settings.MovieCopy)
                        {
                            file.CopyTo(folder + @"\" + Path.GetFileName(filename));
                        }
                        else
                        {
                            file.MoveTo(folder + @"\" + Path.GetFileName(filename));
                        }
                    }
                }

                for (int i = 0; i < movie.Filenames.Count; i++)
                {
                    movie.Filenames[i] = folder + @"\" + Path.GetFileName(movie.Filenames[i]);
                }

                // Download cover
                if (!File.Exists(folder + @"\folder.jpg"))
                {
                    webclient.DownloadFile(movie.Cover.Url, folder + @"\folder.jpg");
                }

                // Add to database
                if (Program.Database.Movies.ContainsKey(movie.Id))
                {
                    Program.Database.Remove(movie.Id);
                }
                Program.Database.Add(movie.Id, movie);
            }

            foreach (ListViewItem lvi in listViewResults.Items)
            {
                MovieTag filetag = (MovieTag)lvi.Tag;
                if (Program.Database.Movies.ContainsKey(filetag.MovieInfo.Id))
                {
                    lvi.Remove();
                }
            }
        }
Ejemplo n.º 3
0
        private void listViewResults_MouseUp(object sender, MouseEventArgs e)
        {
            ListViewItem lvi = listViewResults.GetItemAt(e.X, e.Y);

            if ((e.X > listViewResults.Columns[0].Width) && (e.X < listViewResults.Columns[0].Width + listViewResults.Columns[1].Width))
            {
                if (lvi != null)
                {
                    if (lvi.SubItems[1].Text != "")
                    {
                        Rectangle ClickedItem = lvi.Bounds;

                        if ((ClickedItem.Left + listViewResults.Columns[1].Width) < 0)
                        {
                            return;
                        }

                        else if (ClickedItem.Left < 0)
                        {
                            if ((ClickedItem.Left + listViewResults.Columns[1].Width) > listViewResults.Width)
                            {
                                ClickedItem.Width = listViewResults.Width;
                                ClickedItem.X     = listViewResults.Columns[0].Width;
                            }
                            else
                            {
                                ClickedItem.Width = listViewResults.Columns[1].Width + ClickedItem.Left;
                                ClickedItem.X     = listViewResults.Columns[0].Width + 2;
                            }
                        }
                        else if (listViewResults.Columns[1].Width > listViewResults.Width)
                        {
                            ClickedItem.Width = listViewResults.Width;
                        }
                        else
                        {
                            ClickedItem.Width = listViewResults.Columns[1].Width;
                            ClickedItem.X     = listViewResults.Columns[0].Width + 2;
                        }

                        ClickedItem.Y += listViewResults.Top;
                        ClickedItem.X += listViewResults.Left;

                        comboBoxMovie.Bounds = ClickedItem;

                        comboBoxMovie.Items.Clear();

                        MovieTag tag = (MovieTag)lvi.Tag;
                        foreach (TMDB.Movie movie in tag.Results)
                        {
                            if (movie.Released != null)
                            {
                                comboBoxMovie.Items.Add(movie.Name + " (" + movie.Released.Value.Year.ToString() + ")");
                            }
                            else
                            {
                                comboBoxMovie.Items.Add(movie.Name);
                            }
                        }
                        comboBoxMovie.SelectedIndex = 0;

                        comboBoxMovie.Visible = true;
                        comboBoxMovie.BringToFront();
                        comboBoxMovie.Focus();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        //---------------------------------------------------------------

        void tmdb_MovieSearchCompleted(object sender, TMDB.MovieSearchCompletedEventArgs e)
        {
            threadCount -= 1;

            if (e.Error == null)
            {
                if (e.Movies.Length > 0)
                {
                    MovieTag movietag = (MovieTag)listViewResults.Items[(int)e.UserState].Tag;

                    movietag.Results = e.Movies;
                    listViewResults.Items[(int)e.UserState].Tag = movietag;

                    listViewResults.Items[(int)e.UserState].ForeColor        = Color.Blue;
                    listViewResults.Items[(int)e.UserState].SubItems[3].Text = "Match found, downloading info...";
                    listViewResults.Items[(int)e.UserState].SubItems[1].Text = e.Movies[0].Name;

                    if (e.Movies[0].Released.HasValue)
                    {
                        listViewResults.Items[(int)e.UserState].SubItems[2].Text = e.Movies[0].Released.Value.Year.ToString();
                    }

                    threadCount += 1;

                    EnsureVisibleScroll((int)e.UserState);

                    Program.Tmdb.GetMovieInfoAsync(e.Movies[0].Id, (int)e.UserState);
                }
                else
                {
                    listViewResults.Items[(int)e.UserState].ForeColor        = Color.Red;
                    listViewResults.Items[(int)e.UserState].SubItems[3].Text = "Unable to find match";
                    progressBarResults.Value += 1;

                    if (searchPos < listViewResults.Items.Count)
                    {
                        MovieTag movietag = (MovieTag)listViewResults.Items[searchPos].Tag;
                        threadCount += 1;
                        EnsureVisibleScroll(searchPos);
                        Program.Tmdb.MovieSearchAsync(movietag.Search, searchPos);
                        searchPos += 1;
                    }
                }
            }
            else
            {
                listViewResults.Items[(int)e.UserState].ForeColor        = Color.Red;
                listViewResults.Items[(int)e.UserState].SubItems[3].Text = "Remote server error";
                progressBarResults.Value += 1;
            }

            progressBarResults.Value += 1;
            int    current = progressBarResults.Value;
            int    max     = progressBarResults.Maximum;
            double percent = ((double)current / (double)max) * 100;

            if (progressBarResults.Value == progressBarResults.Maximum)
            {
                scanning = false;

                percent     = 100;
                threadCount = 0;
            }

            labelProgress.Text = percent.ToString("0.0") + "% (" + completedMatches + " / " + listViewResults.Items.Count + ")";

            if (!scanning && threadCount == 0 && percent != 100)
            {
                labelProgress.Text = "Aborted (" + completedMatches + " / " + listViewResults.Items.Count + ")";
                Program.Tmdb.MovieSearchCompleted -= new TMDB.Api.MovieSearchAsyncCompletedEventHandler(tmdb_MovieSearchCompleted);
            }
            else if ((scanning && threadCount == 0) || percent == 100)
            {
                buttonResultsAbort.Enabled         = true;
                Program.Tmdb.MovieSearchCompleted -= new TMDB.Api.MovieSearchAsyncCompletedEventHandler(tmdb_MovieSearchCompleted);
            }

            if (threadCount == 0)
            {
                buttonResultsBack.Enabled   = true;
                buttonResultsAutoId.Enabled = true;
                buttonResultsAbort.Text     = "Close";

                foreach (ListViewItem lvi in listViewResults.Items)
                {
                    if (lvi.ForeColor == Color.Green)
                    {
                        buttonResultsAdd.Enabled = true;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void buttonResultsOpen_Click(object sender, EventArgs e)
        {
            MovieTag tag = (MovieTag)listViewResults.SelectedItems[0].Tag;

            Process.Start(tag.MovieInfo.Filenames[0]);
        }
Ejemplo n.º 6
0
        void Tmdb_GetMovieInfoCompleted(object sender, TMDB.MovieInfoCompletedEventArgs e)
        {
            threadCount -= 1;
            MovieTag tag;

            if (scanning)
            {
                if (searchPos < listViewResults.Items.Count)
                {
                    while (listViewResults.Items[searchPos].ForeColor == Color.Purple || (listViewResults.Items[searchPos].ForeColor == Color.Red && listViewResults.Items[searchPos].SubItems[3].Text == "Unable to find match"))
                    {
                        searchPos += 1;
                        progressBarResults.Value += 1;
                        completedMatches         += 1;
                    }

                    listViewResults.Items[searchPos].SubItems[3].Text = "Scanning...";
                    tag = (MovieTag)listViewResults.Items[searchPos].Tag;

                    threadCount += 1;

                    EnsureVisibleScroll(searchPos);

                    Program.Tmdb.MovieSearchAsync(tag.Search, searchPos);
                    searchPos += 1;
                }
            }

            if (e.Error == null)
            {
                if (e.Movie != null)
                {
                    completedMatches += 1;

                    MovieTag filetag = (MovieTag)listViewResults.Items[(int)e.UserState].Tag;

                    Movie add = new Movie();
                    add                  = filetag.MovieInfo;
                    add.Id               = e.Movie.Id;
                    add.Title            = e.Movie.Name;
                    add.AlternativeTitle = e.Movie.AlternativeName;
                    add.ImdbId           = e.Movie.ImdbId;
                    add.Language         = e.Movie.Language;
                    add.Overview         = e.Movie.Overview;
                    add.Released         = e.Movie.Released;
                    add.Trailer          = e.Movie.Trailer;
                    add.Votes            = e.Movie.Votes;
                    add.Rating           = e.Movie.Rating;
                    add.Budget           = e.Movie.Budget;
                    add.Certification    = e.Movie.Certification;
                    add.Homepage         = e.Movie.Homepage;
                    add.Revenue          = e.Movie.Revenue;

                    foreach (TMDB.Image img in e.Movie.Images)
                    {
                        if (img.Size == TMDB.ImageSize.original)
                        {
                            add.Cover = img;
                            break;
                        }
                    }

                    addMovies.Add(add);

                    listViewResults.Items[(int)e.UserState].ForeColor        = Color.Green;
                    listViewResults.Items[(int)e.UserState].SubItems[3].Text = "Complete";
                }
                else
                {
                    listViewResults.Items[(int)e.UserState].ForeColor        = Color.Red;
                    listViewResults.Items[(int)e.UserState].SubItems[3].Text = "Unable to find match";
                }
            }
            else
            {
                listViewResults.Items[(int)e.UserState].ForeColor        = Color.Red;
                listViewResults.Items[(int)e.UserState].SubItems[3].Text = "Remote server error";
            }

            progressBarResults.Value += 1;
            int    current = progressBarResults.Value;
            int    max     = progressBarResults.Maximum;
            double percent = ((double)current / (double)max) * 100;

            if (progressBarResults.Value == progressBarResults.Maximum)
            {
                scanning = false;

                percent     = 100;
                threadCount = 0;
            }

            labelProgress.Text = percent.ToString("0.0") + "% (" + completedMatches + " / " + listViewResults.Items.Count + ")";

            if (!scanning && threadCount == 0 && percent != 100)
            {
                labelProgress.Text = "Aborted (" + completedMatches + " / " + listViewResults.Items.Count + ")";
                Program.Tmdb.GetMovieInfoCompleted -= new TMDB.Api.MovieInfoAsyncCompletedEventHandler(Tmdb_GetMovieInfoCompleted);
            }
            else if ((scanning && threadCount == 0) || percent == 100)
            {
                buttonResultsAbort.Enabled          = true;
                Program.Tmdb.GetMovieInfoCompleted -= new TMDB.Api.MovieInfoAsyncCompletedEventHandler(Tmdb_GetMovieInfoCompleted);
            }

            if (threadCount == 0)
            {
                buttonResultsBack.Enabled   = true;
                buttonResultsAutoId.Enabled = true;
                buttonResultsAbort.Text     = "Close";

                foreach (ListViewItem lvi in listViewResults.Items)
                {
                    if (lvi.ForeColor == Color.Green)
                    {
                        buttonResultsAdd.Enabled = true;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void buttonFoldersScan_Click(object sender, EventArgs e)
        {
            listViewResults.Items.Clear();
            buttonResultsRemove.Enabled = false;
            buttonResultsOpen.Enabled   = false;
            buttonResultsEdit.Enabled   = false;

            List <Movie> movies = new List <Movie>();

            foreach (ListViewItem lvi in listViewFolders.Items)
            {
                if (Directory.Exists(lvi.Text))
                {
                    string[] files = ListFiles(lvi.Text, checkBoxFoldersSubdirectories.Checked);
                    foreach (string file in files)
                    {
                        Movie movie = Format.GetFileInfo(Path.GetFileNameWithoutExtension(file));

                        foreach (Movie added in movies)
                        {
                            if (added.FileTitle == movie.FileTitle && added.FileYear == movie.FileYear)
                            {
                                added.FileDiscs += 1;
                                movie.FileDiscs += 1;
                                added.Filenames.Add(file);
                            }
                        }

                        if (movie.FileDiscs == 1)
                        {
                            movie.Filenames = new List <string>();
                            movie.Filenames.Add(file);
                            movies.Add(movie);
                        }
                    }
                }
            }

            foreach (Movie movie in movies)
            {
                if (movie.FileTitle != null)
                {
                    ListViewItem lvi      = new ListViewItem(new string[] { Path.GetFileName(movie.Filenames[0]), "", "", "Ready", "" });
                    MovieTag     movieTag = new MovieTag();
                    movieTag.Search    = movie.FileTitle;
                    movieTag.MovieInfo = movie;
                    lvi.Tag            = movieTag;
                    listViewResults.Items.Add(lvi);
                }
            }

            progressBarResults.Maximum = listViewResults.Items.Count * 2;
            progressBarResults.Value   = 0;
            labelProgress.Text         = "0% (0 / " + listViewResults.Items.Count + ")";

            listviewColumnSorter.Sorting = SortOrder.Ascending;
            listviewColumnSorter.Column  = 0;
            listViewResults.Sorting      = SortOrder.Ascending;
            ListViewColumnSortArrows.SetSortIcons(listViewResults, ref sortedColumn, 0);
            listViewResults.Sort();

            panelFolders.Visible = false;
            panelResults.Visible = true;

            buttonResultsAutoId.Enabled = (listViewResults.Items.Count > 0); //TODO: Only if red
        }