Esempio n. 1
0
        private void selectFolderButton_Click(object sender, RoutedEventArgs e)
        {
            VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog();

            dialog.ShowDialog();
            if (!string.IsNullOrEmpty(dialog.SelectedPath))
            {
                List <string> foundFiles    = new List <string>();
                Regex         fileNameRegex = new Regex(@"(\d+)");
                string[]      files         = Directory.GetFiles(dialog.SelectedPath);
                foreach (string file in files)
                {
                    string fileName = System.IO.Path.GetFileNameWithoutExtension(file);
                    Match  match    = fileNameRegex.Match(fileName);
                    if (match.Success)
                    {
                        int numberCandidate = int.Parse(match.Groups[1].Value);
                        foreach (object item in this.episodeListDataGrid.Items)
                        {
                            FileMetaDataInfo infoItem = item as FileMetaDataInfo;
                            if (infoItem.Metadata.TrackNumber == numberCandidate)
                            {
                                infoItem.LocalFileName = file;
                                infoItem.UpdateFile    = true;
                            }
                        }
                    }
                }

                this.episodeListDataGrid.Items.Refresh();
            }
        }
Esempio n. 2
0
        private void goButton_Click(object sender, RoutedEventArgs e)
        {
            this.Cursor = Cursors.Wait;
            try
            {
                foreach (object item in this.episodeListDataGrid.Items)
                {
                    FileMetaDataInfo infoItem = item as FileMetaDataInfo;
                    if (!string.IsNullOrEmpty(infoItem.LocalFileName) && infoItem.UpdateFile)
                    {
                        MP4File currentFile = MP4File.Open(infoItem.LocalFileName);
                        currentFile.Tags.Album           = this.albumTextBox.Text;
                        currentFile.Tags.AlbumArtist     = this.showTextBox.Text;
                        currentFile.Tags.Artist          = this.showTextBox.Text;
                        currentFile.Tags.TVShow          = this.showTextBox.Text;
                        currentFile.Tags.SeasonNumber    = int.Parse(this.seasonNumberTextBox.Text);
                        currentFile.Tags.EpisodeNumber   = infoItem.Metadata.TrackNumber;
                        currentFile.Tags.Title           = infoItem.Metadata.TrackName;
                        currentFile.Tags.TrackNumber     = Convert.ToInt16(infoItem.Metadata.TrackNumber);
                        currentFile.Tags.TotalTracks     = Convert.ToInt16(infoItem.Metadata.TrackCount);
                        currentFile.Tags.DiscNumber      = Convert.ToInt16(infoItem.Metadata.DiscNumber);
                        currentFile.Tags.TotalDiscs      = Convert.ToInt16(infoItem.Metadata.DiscCount);
                        currentFile.Tags.Description     = infoItem.Metadata.ShortDescription;
                        currentFile.Tags.LongDescription = infoItem.Metadata.LongDescription;
                        currentFile.Tags.EpisodeId       = string.Format("S{0}E{1}", this.seasonNumberTextBox.Text, infoItem.Metadata.TrackNumber);

                        System.Drawing.Image artwork = System.Drawing.Image.FromFile(this.artworkFile);
                        currentFile.Tags.Artwork = artwork;

                        if (this.albumTextBox.Text.StartsWith("a ", StringComparison.InvariantCultureIgnoreCase) ||
                            this.albumTextBox.Text.StartsWith("an ", StringComparison.InvariantCultureIgnoreCase) ||
                            this.albumTextBox.Text.StartsWith("the ", StringComparison.InvariantCultureIgnoreCase))
                        {
                            string sortAlbumValue = this.albumTextBox.Text.Substring(this.albumTextBox.Text.IndexOf(' ') + 1);
                            currentFile.Tags.SortAlbum = sortAlbumValue;
                        }

                        if (this.showTextBox.Text.StartsWith("a ", StringComparison.InvariantCultureIgnoreCase) ||
                            this.showTextBox.Text.StartsWith("an ", StringComparison.InvariantCultureIgnoreCase) ||
                            this.showTextBox.Text.StartsWith("the ", StringComparison.InvariantCultureIgnoreCase))
                        {
                            string sortShowValue = this.showTextBox.Text.Substring(this.showTextBox.Text.IndexOf(' ') + 1);
                            currentFile.Tags.SortTVShow      = sortShowValue;
                            currentFile.Tags.SortArtist      = sortShowValue;
                            currentFile.Tags.SortAlbumArtist = sortShowValue;
                        }


                        if (infoItem.Metadata.TrackName.StartsWith("a ", StringComparison.InvariantCultureIgnoreCase) ||
                            infoItem.Metadata.TrackName.StartsWith("an ", StringComparison.InvariantCultureIgnoreCase) ||
                            infoItem.Metadata.TrackName.StartsWith("the ", StringComparison.InvariantCultureIgnoreCase))
                        {
                            string sortNameValue = infoItem.Metadata.TrackName.Substring(infoItem.Metadata.TrackName.IndexOf(' ') + 1);
                            currentFile.Tags.SortName = sortNameValue;
                        }

                        currentFile.Tags.ContentId   = infoItem.Metadata.TrackId;
                        currentFile.Tags.ReleaseDate = infoItem.Metadata.ReleaseDate.ToString("yyyy-MM-dd");
                        currentFile.Tags.MediaType   = MediaKind.TVShow;

                        currentFile.Save();

                        infoItem.UpdateFile = false;
                    }
                }

                this.episodeListDataGrid.Items.Refresh();
            }
            finally
            {
                this.Cursor = null;
            }
        }