Example #1
0
        // Method used by OnCreated / OncHanged to add / update the song structure
        private static void AddUpdateSong(string strFileName)
        {
            if (musicDB.SongExists(strFileName))
            {
                musicDB.UpdateSong(strFileName);
                return;
            }
            // For some reason the Create is fired already by windows while the file is still copied.
            // This happens especially on large songs copied via WLAN.
            // The result is that MP Readtag is throwing an IO Exception.
            // I'm trying to open the file here and in case of an exception i'll put it on a thread to be
            // processed 5 seconds later again.
            try
            {
                FileInfo file = new FileInfo(strFileName);
                Stream   s    = null;
                s = file.OpenRead();
                s.Close();
            }
            catch (IOException)
            {
                // The file is not closed yet. Ignore the event, it will be processed by the Change event
                return;
            }

            musicDB.AddSong(strFileName);
            // Check for Various Artists
            //musicDB.CheckVariousArtists(song.Album);
        }
Example #2
0
        private static void ThreadEncodeTrack()
        {
            m_Ripping = true;

            try
            {
                CreateTempFolder();
                if (mp3Background)
                {
                    GUIWaitCursor.Show();
                }
                else if (dlgProgress != null)
                {
                    dlgProgress.Reset();
                    dlgProgress.SetPercentage(0);
                    dlgProgress.StartModal(GetID);
                    dlgProgress.Progress();
                    dlgProgress.ShowProgressBar(true);
                }

                while (importQueue.Count > 0)
                {
                    TrackInfo trackInfo = (TrackInfo)importQueue.Dequeue();
                    if ((dlgProgress != null) && !mp3Background)
                    {
                        if (importQueue.Count > 0)
                        {
                            dlgProgress.SetHeading(
                                string.Format(GUILocalizeStrings.Get(1105) + " ({0} " + GUILocalizeStrings.Get(1104) + ")",
                                              importQueue.Count + 1));
                        }
                        else
                        {
                            dlgProgress.SetHeading(GUILocalizeStrings.Get(1103));
                        }

                        dlgProgress.SetLine(2,
                                            string.Format("{0:00}. {1} - {2}", trackInfo.MusicTag.Track, trackInfo.MusicTag.Artist,
                                                          trackInfo.MusicTag.Title));
                        //dlgProgress.SetLine(2, trackInfo.TempFileName);
                        if (dlgProgress.IsCanceled)
                        {
                            m_CancelRipping = true;
                        }
                    }

                    if (!m_CancelRipping)
                    {
                        m_Drive = new CDDrive();
                        SaveTrack(trackInfo);
                        if (File.Exists(trackInfo.TempFileName) && !m_CancelRipping)
                        {
                            #region Tagging

                            try
                            {
                                Tags tags = Tags.FromFile(trackInfo.TempFileName);
                                tags["TRCK"] = trackInfo.MusicTag.Track.ToString() + "/" + trackInfo.TrackCount.ToString();
                                tags["TALB"] = trackInfo.MusicTag.Album;
                                tags["TPE1"] = trackInfo.MusicTag.Artist;
                                tags["TIT2"] = trackInfo.MusicTag.Title;
                                tags["TCON"] = trackInfo.MusicTag.Genre;
                                if (trackInfo.MusicTag.Year > 0)
                                {
                                    tags["TYER"] = trackInfo.MusicTag.Year.ToString();
                                }
                                tags["TENC"] = "MediaPortal / Lame";
                                tags.Save(trackInfo.TempFileName);
                            }
                            catch
                            {
                            }

                            #endregion

                            #region Database

                            try
                            {
                                if (!Directory.Exists(trackInfo.TargetDir))
                                {
                                    Directory.CreateDirectory(trackInfo.TargetDir);
                                }

                                if (File.Exists(trackInfo.TargetFileName))
                                {
                                    if (mp3ReplaceExisting)
                                    {
                                        File.Delete(trackInfo.TargetFileName);
                                    }
                                }

                                if (!File.Exists(trackInfo.TargetFileName))
                                {
                                    File.Move(trackInfo.TempFileName, trackInfo.TargetFileName);
                                }

                                if (File.Exists(trackInfo.TargetFileName) && mp3Database)
                                {
                                    if (importUnknown || (trackInfo.MusicTag.Artist != "Unknown Artist") ||
                                        (trackInfo.MusicTag.Album != "Unknown Album"))
                                    {
                                        MusicDatabase dbs = MusicDatabase.Instance;
                                        dbs.AddSong(trackInfo.TargetFileName);
                                    }
                                }
                            }
                            catch
                            {
                                Log.Info("CDIMP: Error moving encoded file {0} to new location {1}", trackInfo.TempFileName,
                                         trackInfo.TargetFileName);
                            }

                            #endregion
                        }
                    }
                }
                if (mp3Background)
                {
                    GUIWaitCursor.Hide();
                }
                else
                {
                    dlgProgress.Close();
                }
            }
            finally
            {
                CleanupTempFolder();
            }
            m_CancelRipping = false;
            m_Ripping       = false;
        }