예제 #1
0
        public void CellMouseDoubleClick(object sender, EventArgs e)
        {
            DataGridView     d = sender as DataGridView;
            DataGridViewCell c = d.SelectedCells[0];

            if (c.ColumnIndex == 2 && c.Value != null)
            {
                string songPath = Utilities.SearchSongPath(d.Name, c.Value.ToString());
                if (songPath != string.Empty)
                {
                    axWindowsMediaPlayer2.URL = (songPath);
                    TagLib.File f = TagLib.File.Create(songPath, TagLib.ReadStyle.Average);
                    if (f.Tag.Pictures.Length == 0)
                    {
                        f.Dispose();
                        pictureBox7.Image = Properties.Resources.icons8_No_hay_entrada_Filled_50;
                        return;
                    }
                    MemoryStream         ms    = new MemoryStream(f.Tag.Pictures[0].Data.Data);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
                    pictureBox7.Image = image;
                    f.Dispose();
                }
            }
        }
예제 #2
0
        private void ChangeAndVerify(SafeUri uri, Action <TrackInfo> change, Action <TrackInfo> verify)
        {
            TagLib.File file  = StreamTagger.ProcessUri(uri);
            TrackInfo   track = new TrackInfo();

            StreamTagger.TrackInfoMerge(track, file);
            file.Dispose();

            // Make changes
            change(track);

            // Save changes
            bool saved = StreamTagger.SaveToFile(track, true, true, true);

            Assert.IsTrue(saved);

            // Read changes
            file  = StreamTagger.ProcessUri(uri);
            track = new TrackInfo();
            StreamTagger.TrackInfoMerge(track, file, false, true, true);
            file.Dispose();

            // Verify changes
            verify(track);
        }
예제 #3
0
        private string CreateFilePath(string trackPath)
        {
            TagLib.File track = TagLib.File.Create(trackPath);

            string extension = Path.GetExtension(trackPath);
            string invalid   = new string(Path.GetInvalidFileNameChars());

            if (track.Tag.Title == null)
            {
                throw new Exception(string.Format("This track contains no title information ({0})", trackPath));
            }

            string title  = track.Tag.Title;
            string number = track.Tag.Track.ToString("D2");

            track.Dispose();

            foreach (char c in invalid)
            {
                title = title.Replace(c.ToString(), "");
            }

            title = TextInfo.ToTitleCase(title.ToLower());

            StringBuilder builder = new StringBuilder();

            builder.AppendFormat(@"{2} - {0}{1}", title, extension, number);

            return(builder.ToString());
        }
예제 #4
0
파일: Tags.cs 프로젝트: MrTK-Dev/TAGEDITOR
        public static void SaveTags(SongFile songFile)
        {
            TagLib.File newFile = GetTagsFromFile(Caching.currentFile.fullPath);

            newFile.SetInterpret(songFile.Interpret);
            newFile.Tag.Title   = songFile.Title;
            newFile.Tag.Album   = songFile.Album;
            newFile.Tag.Comment = songFile.Comment;
            newFile.Tag.Track   = (uint)songFile.Track;
            newFile.Tag.Year    = (uint)songFile.Year;
            newFile.SetGenre(songFile.Genre);
            newFile.SetImage(Caching.currentFile.Cover.ConvertToPicture());

            newFile.Refresh(Caching.currentFile.fullPath);

            if (Caching.currentFile.Cover != null)
            {
                TagLib.File newFileTEMP = TagLib.File.Create(Caching.currentFile.fullPath);

                newFileTEMP.SetImage(Caching.currentFile.Cover.ConvertToPicture());

                newFileTEMP.Save();

                newFileTEMP.Dispose();
            }
        }
예제 #5
0
        // GET /api/music
        public IEnumerable <Models.MusicModel> Get()
        {
            Cache cache = HttpContext.Current.Cache;

            List <Models.MusicModel> list = (List <Models.MusicModel>)cache["songlist"];

            if (list == null)
            {
                list = new List <Models.MusicModel>();
                foreach (string filepath in System.IO.Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Content/Music")))
                {
                    TagLib.File       file = TagLib.File.Create(filepath);
                    Models.MusicModel song = new Models.MusicModel();
                    var s = file.Tag.AlbumArtists.ToList();
                    s.AddRange(file.Tag.Performers.ToList());
                    song.Artist = string.Join(", ", s.ToArray());
                    //song.Artist = string.Join(", ", file.Tag.Performers, file.Tag.AlbumArtists);
                    song.MusicId = Guid.Parse(file.Name.Split('\\').Last().Replace(".mp3", ""));
                    song.Length  = file.Length;
                    song.Track   = file.Tag.Track;
                    song.Title   = file.Tag.Title;
                    song.Genres  = string.Join(", ", file.Tag.Genres);
                    song.Album   = file.Tag.Album;
                    song.Url     = "/api/music/" + file.Name.Split('\\').Last().Replace(".mp3", "");

                    list.Add(song);
                    file.Dispose();
                }

                cache.Insert("songlist", list, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(30));
            }

            return(list);
        }
        public async Task Convert4OneDrive(string outputPath)
        {
            string newPath     = Path.Combine(Path.GetDirectoryName(_inputFile), _album);
            string newFileName = newPath + ".zip";

            //rename
            File.Move(_inputFile, newFileName);
            //extract
            ZipFile.ExtractToDirectory(newFileName, Path.Combine(Path.GetDirectoryName(_inputFile), _album));

            foreach (string mp3 in Directory.EnumerateFiles(newPath, "*.mp3"))
            {
                TagLib.File file = TagLib.File.Create(mp3);
                file.Tag.Genres = new string[] { _genre };
                file.Save();
                file.Dispose();
            }

            foreach (string mp3 in Directory.EnumerateFiles(newPath, "*.mp3"))
            {
                string newMp3Name = Path.GetFileName(mp3).Split('-')[2].TrimStart();
                File.Move(mp3, Path.Combine(Path.GetDirectoryName(mp3), newMp3Name));
            }

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            Directory.Move(newPath, outputPath);
        }
예제 #7
0
        private async Task CreateDatabase()
        {
            var List = LoadFiles(Locations[0]);

            foreach (var file in List)
            {
                TagLib.File tFile = null;
                try
                {
                    tFile = TagLib.File.Create(file);
                    if (!string.IsNullOrEmpty(tFile.Tag.Album))
                    {
                        var list = await DatabaseHelper.QueryAlbums(tFile.Tag.Album);

                        if (list.Count == 0)
                        {
                            DatabaseHelper.AddAlbum(new Album()
                            {
                                Name = tFile.Tag.Album
                            });
                        }
                    }
                }
                catch (TagLib.UnsupportedFormatException)
                {
                    Debug.WriteLine($"UnsupportedFormatException thrown with file: {file}");
                }
                finally
                {
                    tFile?.Dispose();
                }
            }
        }
예제 #8
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new TagEditor();

            using (TagLib.File FD = TagLib.File.Create(selectedPath))
            {
                using (Context db = new Context())
                {
                    dialog.Id = SelectAudio();
                    var a = db.Audios.Where(c => c.id == selectedAudioId).ToList <Audio>().FirstOrDefault();
                    dialog.TrackTitle   = a.Title;
                    dialog.Author       = a.Singer;
                    dialog.Album        = a.Album;
                    dialog.Genre        = FD.Tag.FirstGenre;
                    dialog.Year         = FD.Tag.Year.ToString();
                    dialog.counter.Text = a.countPlay.ToString();
                    try
                    {
                        dialog.Image = PlaylistNameDialog.LoadImage(FD.Tag.Pictures[0].Data.Data);
                    }
                    catch
                    {
                        dialog.Image = currentImage;
                    }
                    dialog.Path = selectedPath;
                    FD.Dispose();
                }
            }

            dialog.Show();
            dialog.Closed += Dialog_Closed;
        }
예제 #9
0
        public static bool SaveToFile(TrackInfo track, bool write_metadata, bool write_rating, bool write_play_count)
        {
            // Note: this should be kept in sync with the metadata read in StreamTagger.cs
            TagLib.File file = ProcessUri(track.Uri);
            if (file == null)
            {
                return(false);
            }

            if (write_metadata)
            {
                file.Tag.Performers           = new string [] { track.ArtistName };
                file.Tag.PerformersSort       = new string [] { track.ArtistNameSort };
                file.Tag.Album                = track.AlbumTitle;
                file.Tag.AlbumSort            = track.AlbumTitleSort;
                file.Tag.MusicBrainzReleaseId = track.AlbumMusicBrainzId;
                file.Tag.AlbumArtists         = track.AlbumArtist == null ? new string [0] : new string [] { track.AlbumArtist };
                file.Tag.AlbumArtistsSort     = (track.AlbumArtistSort == null ? new string [0] : new string [] { track.AlbumArtistSort });
                file.Tag.MusicBrainzArtistId  = track.ArtistMusicBrainzId;
                // Bug in taglib-sharp-2.0.3.0: Crash if you send it a genre of "{ null }"
                // on a song with both ID3v1 and ID3v2 metadata. It's happy with "{}", though.
                // (see http://forum.taglib-sharp.com/viewtopic.php?f=5&t=239 )
                file.Tag.Genres             = (track.Genre == null) ? new string[] {} : new string [] { track.Genre };
                file.Tag.Title              = track.TrackTitle;
                file.Tag.TitleSort          = track.TrackTitleSort;
                file.Tag.MusicBrainzTrackId = track.MusicBrainzId;
                file.Tag.Track              = (uint)track.TrackNumber;
                file.Tag.TrackCount         = (uint)track.TrackCount;
                file.Tag.Composers          = new string [] { track.Composer };
                file.Tag.Conductor          = track.Conductor;
                file.Tag.Grouping           = track.Grouping;
                file.Tag.Copyright          = track.Copyright;
                file.Tag.Comment            = track.Comment;
                file.Tag.Disc           = (uint)track.DiscNumber;
                file.Tag.DiscCount      = (uint)track.DiscCount;
                file.Tag.Year           = (uint)track.Year;
                file.Tag.BeatsPerMinute = (uint)track.Bpm;

                SaveIsCompilation(file, track.IsCompilation);
            }

            if (write_rating)
            {
                // FIXME move StreamRatingTagger to taglib#
                StreamRatingTagger.StoreRating(track.Rating, file);
            }
            if (write_play_count)
            {
                StreamRatingTagger.StorePlayCount(track.PlayCount, file);
            }

            file.Save();
            file.Dispose();

            track.FileSize          = Banshee.IO.File.GetSize(track.Uri);
            track.FileModifiedStamp = Banshee.IO.File.GetModifiedTime(track.Uri);
            track.LastSyncedStamp   = DateTime.Now;
            return(true);
        }
예제 #10
0
 public void GetTags()
 {
     if (Program.mainWindow == null)
     {
         return;
     }
     try
     {
         if (Program.mainWindow.supportedModuleTypes.Contains(Path.GetExtension(filename).ToLower()))
         {
             Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
             int track = Bass.BASS_MusicLoad(filename, 0, 0, BASSFlag.BASS_MUSIC_NOSAMPLE | BASSFlag.BASS_MUSIC_PRESCAN, 0);
             title  = Bass.BASS_ChannelGetMusicName(track);
             artist = Bass.BASS_ChannelGetMusicMessage(track);
             length = (int)Bass.BASS_ChannelBytes2Seconds(track, (int)Bass.BASS_ChannelGetLength(track));
             Bass.BASS_Free();
         }
         else if (Program.mainWindow.supportedMidiTypes.Contains(Path.GetExtension(filename).ToLower()))
         {
             Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
             int track = BassMidi.BASS_MIDI_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_DEFAULT, 0);
             title  = Path.GetFileName(filename);
             length = (int)Bass.BASS_ChannelBytes2Seconds(track, (int)Bass.BASS_ChannelGetLength(track));
             Bass.BASS_Free();
         }
         else
         {
             TagLib.File tagFile = TagLib.File.Create(filename);
             title = tagFile.Tag.Title;
             if (tagFile.Tag.Performers.Length > 0)
             {
                 artist = tagFile.Tag.Performers[0];
             }
             album = tagFile.Tag.Album;
             //year = tagFile.Tag.Year+"";
             //comment = tagFile.Tag.Comment;
             length  = (int)tagFile.Properties.Duration.TotalSeconds;
             bitrate = tagFile.Properties.AudioBitrate;
             tagFile.Dispose();
         }
     }
     catch (Exception)
     {
         title  = filename;
         length = 0;
     }
     if (String.IsNullOrWhiteSpace(title))
     {
         title = Path.GetFileName(filename);
     }
     try
     {
         listened = Int32.Parse(Program.mainWindow.xmlCacher.GetListened(filename));
     }
     catch (Exception)
     {
         listened = 0;
     }
 }
예제 #11
0
        public static void Play(string path)
        {
            EngineBASS.Path = path;
            EngineBASS.Play();

            tagFile?.Dispose();
            tagFile = TagLib.File.Create(EngineBASS.Path);
        }
예제 #12
0
 public void Write()
 {
     if (_mp3file != null)
     {
         _mp3file.Save();
         _mp3file.Dispose();
     }
 }
        private Task <List <AudioArtist> > GetFromLibrary()
        {
            return(Task.Run(async() =>
            {
                var musicFiles = FilesHelper.GetMusicFiles();

                double totalCount = musicFiles.Count;

                var artists = new Dictionary <string, AudioArtist>();

                foreach (var filePath in musicFiles)
                {
                    TagLib.File audioFile = null;

                    try
                    {
                        audioFile = TagLib.File.Create(filePath);
                    }
                    catch (Exception ex)
                    {
                        LoggingService.Log(ex);
                        continue;
                    }

                    var track = new LocalAudio();
                    string artist = string.Empty;
                    if (!string.IsNullOrWhiteSpace(audioFile.Tag.FirstPerformer))
                    {
                        artist = audioFile.Tag.FirstPerformer;
                    }
                    else if (!string.IsNullOrWhiteSpace(audioFile.Tag.FirstAlbumArtist))
                    {
                        artist = audioFile.Tag.FirstAlbumArtist;
                    }

                    if (!string.IsNullOrWhiteSpace(artist))
                    {
                        track.ArtistId = Md5Helper.Md5(StringHelper.ToUtf8(artist).Trim().ToLower());
                        track.Artist = StringHelper.ToUtf8(artist).Trim();
                        if (!artists.ContainsKey(track.ArtistId))
                        {
                            artists.Add(track.ArtistId, new AudioArtist()
                            {
                                Id = track.ArtistId, Title = track.Artist
                            });
                        }
                    }

                    audioFile.Dispose();

                    await Task.Delay(50);
                }

                LoggingService.Log("Music scan finished. Found " + artists.Count + " artists");

                return artists.Values.ToList();
            }));
        }
예제 #14
0
        private void playSong()
        {
            while (!isStopped)
            {
                isMusicEnd = false;
                TagLib.File songFile = TagLib.File.Create(SongFiles[CurrentSong]);
                currentSongFileDescriptor = songFile.Tag;
                if (currentSongFileDescriptor.Pictures.Length > 0)
                {
                    foreach (var pic in currentSongFileDescriptor.Pictures)
                    {
                        OnSongPicLoaded?.Invoke(pic.Data.Data);
                        break;
                    }
                }
                else
                {
                    OnSongPicLoaded?.Invoke(null);
                }
                songFile.Dispose();



                // 这个bug是当前第一优先级
                try
                {
                    audioFile = new AudioFileReader(SongFiles[CurrentSong]);
                }
                catch (Exception ex)
                {
                    CurrentSong = (CurrentSong + 1) % SongFiles.Count;
                    continue;
                }
                SampleAggregator aggregator = new SampleAggregator(audioFile)
                {
                    NotificationCount = audioFile.WaveFormat.SampleRate / 1024,
                    PerformFFT        = true,
                };
                aggregator.FFTCalculated     += Aggregator_FFTCalculated;
                aggregator.MaximumCalculated += Aggregator_MaximumCalculated;
                playAction?.Invoke();
                outputDevice.Stop();
                outputDevice.Init(aggregator);
                outputDevice.Play();
                while (!Main.gameMenu && !isMusicEnd && (outputDevice.PlaybackState == PlaybackState.Playing ||
                                                         outputDevice.PlaybackState == PlaybackState.Paused))
                {
                    Thread.Sleep(16);
                    OnProgressUpdate(audioFile.CurrentTime, audioFile.TotalTime);
                }
                if (Main.gameMenu || isStopped)
                {
                    break;
                }
                CurrentSong = (CurrentSong + 1) % SongFiles.Count;
                playAction  = null;
            }
        }
예제 #15
0
 private void ClearMetadata()
 {
     TagLib.File file = GetTagLibFile();
     file.Tag.Clear();
     file.RemoveTags(file.TagTypes & ~file.TagTypesOnDisk);
     file.RemoveTags(TagLib.TagTypes.AllTags);
     file.Save();
     file.Dispose();
 }
        public TaglibWrapper(string path)
        {
            TagLib.File f        = TagLib.File.Create(path, TagLib.ReadStyle.Average);
            var         duration = (int)f.Properties.Duration.TotalSeconds;

            this.time  = TimeSpan.FromSeconds(duration);
            this.album = f.Tag.Album;
            f.Dispose();
        }
예제 #17
0
        public void Load(string filepath)
        {
            Filepath = filepath;
            TagLib.File f = TagLib.File.Create(filepath, TagLib.ReadStyle.Average);
            Tag        = f.Tag;
            Properties = f.Properties;

            SaveThumb();
            f.Dispose();
        }
 private void ChangeAuthorForSelectedSongs()
 {
     foreach (Song item in musicListView.SelectedItems)
     {
         TagLib.File musicFileTags = TagLib.File.Create(GetFileWithPath(item.FileName));
         musicFileTags.Tag.AlbumArtists = new string[] { AuthorTextBox.Text };
         musicFileTags.Save();
         musicFileTags.Dispose();
     }
     InformationTextBox.Text = MusicManagement.Resources.Resources.AuthorUpdated;
 }
 private void ChangeAlbumForAllSongs()
 {
     foreach (Song item in musicListView.Items)
     {
         TagLib.File musicFileTags = TagLib.File.Create(GetFileWithPath(item.FileName));
         musicFileTags.Tag.Album = AlbumTextBox.Text;
         musicFileTags.Save();
         musicFileTags.Dispose();
     }
     InformationTextBox.Text = MusicManagement.Resources.Resources.AllSongsAlbumUpdated;
 }
 private void ChangeTitleForSelectedSongs()
 {
     foreach (Song item in musicListView.SelectedItems)
     {
         TagLib.File musicFileTags = TagLib.File.Create(GetFileWithPath(item.FileName));
         musicFileTags.Tag.Title = TitleTextBox.Text;
         musicFileTags.Save();
         musicFileTags.Dispose();
     }
     InformationTextBox.Text = MusicManagement.Resources.Resources.TitleUpdated;
 }
예제 #21
0
        public void LoadMusic(string dir)
        {
            dataGridView1.Rows.Clear();
            TagLib.File    f2 = null;
            FileInfo       f  = null;
            FileSystemInfo f1 = null;
            bool           path_B;
            string         path;

            String[] s1 = Directory.GetFiles(dir, "*.mp3", SearchOption.AllDirectories);
            int      j  = 0;

            for (i = 0; i < s1.Length; i++)
            {
                f      = new FileInfo(s1[i]);
                f1     = new FileInfo(s1[i]);
                path_B = f1.Exists;
                if (path_B && f.Length != 0)
                {
                    try
                    {
                        path = f1.FullName;
                        f2   = TagLib.File.Create(path);
                        if (!f2.PossiblyCorrupt)
                        {
                            dataGridView1.Rows.Add();
                            dataGridView1.Rows[j].Cells[0].Value = path;
                            dataGridView1.Rows[j].Cells[1].Value = f1.Name;
                            dataGridView1.Rows[j].Cells[2].Value = f2.Tag.Title;
                            dataGridView1.Rows[j].Cells[3].Value = f2.Tag.FirstPerformer;
                            dataGridView1.Rows[j].Cells[4].Value = f2.Tag.Album;
                            dataGridView1.Rows[j].Cells[5].Value = f2.Tag.JoinedGenres;
                            dataGridView1.Rows[j].Cells[6].Value = f2.Tag.Track.ToString();
                            j++;
                        }
                    }
                    catch (TagLib.CorruptFileException ex)
                    {
                        MessageBox.Show((f1.FullName + " " + ex.Message), "Hey!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            f2.Dispose();
            if (j == 1)
            {
                lblSongsFound.Text = "You have found " + j.ToString() + " file.";
            }
            else
            {
                lblSongsFound.Text = "You have found " + j.ToString() + " files.";
            }
        }
예제 #22
0
        public static Track ParseFromFile(string path)
        {
            if (!File.Exists(path))
            {
                throw new System.IO.FileLoadException("Die Datei ist nicht vorhanden");
            }
            Track tag = new Track();

            if (System.IO.Path.GetExtension(path) != ".m3u")
            {
                tag.Path = path;

                TagLib.File tagfile = TagLib.File.Create(path);
                TagLib.Tag  t       = tagfile.Tag;
                tagfile.Dispose();
                if (string.IsNullOrEmpty(t.Title))
                {
                    tag.Title = System.IO.Path.GetFileNameWithoutExtension(path);
                }
                else
                {
                    tag.Title = t.Title;
                }
                tag.Performer = t.FirstPerformer;
                tag.Album     = t.Album;
                if (t.Year > 0)
                {
                    tag.Year = new DateTime(Convert.ToInt32(t.Year), 1, 1);
                }
                if (t.Pictures.Count() > 0)
                {
                    MemoryStream ms    = new MemoryStream(t.Pictures[0].Data.Data);
                    BitmapImage  Cover = new BitmapImage();
                    Cover.BeginInit();
                    Cover.StreamSource = ms;
                    Cover.EndInit();
                    tag.AlbumArt = Cover;
                }
                if (tag.AlbumArt != null)
                {
                    tag.AlbumArt.Freeze();
                }
                tag._hastags = true;
            }
            else
            {
                tag.Path  = path;
                tag.Title = System.IO.Path.GetFileNameWithoutExtension(path);
                tag.Album = System.IO.Path.GetDirectoryName(path);
            }
            return(tag);
        }
예제 #23
0
 private void SafeClose()
 {
     try
     {
         f.Dispose();
     }
     catch { }
     try
     {
         fs.Dispose();
     }
     catch { }
 }
예제 #24
0
        private string CreateDirectoryPath(string trackPath)
        {
            TagLib.File track = TagLib.File.Create(trackPath);

            if (track.Tag == null)
            {
                throw new Exception(string.Format("This track seems to be invalid and can't be read ({0})", trackPath));
            }

            if (track.Tag.Performers == null)
            {
                throw new Exception(string.Format("This track contains no artist information ({0})", trackPath));
            }

            if (track.Tag.Album == null)
            {
                throw new Exception(string.Format("This track contains no album information ({0})", trackPath));
            }

            string invalid = new string(Path.GetInvalidPathChars());
            string performer;

            if (track.Tag.Performers.Length > 1)
            {
                performer = string.Join("", track.Tag.Performers);
            }
            else
            {
                performer = track.Tag.Performers[0];
            }

            string album = track.Tag.Album;

            track.Dispose();

            foreach (char c in invalid)
            {
                performer = performer.Replace(c.ToString(), "");
                album     = album.Replace(c.ToString(), "");
            }

            //performer = TextInfo.ToTitleCase(performer.ToLower());
            album = TextInfo.ToTitleCase(album.ToLower()).Replace("/", "-").Replace("?", "").Replace(":", "");

            StringBuilder builder = new StringBuilder();

            builder.AppendFormat(@"\{0}\{1}\", performer, album);

            return(builder.ToString());
        }
예제 #25
0
        public static void CheckFileTags(string fileName)
        {
            //TagLib.File wav = TagLib.File.Create(savePathWav+fileName+".wav");
            //wav.Dispose();

            //tag mp3 file
            TagLib.File mp3     = TagLib.File.Create(savePathMP3 + fileName + ".mp3");
            string[]    artists = new string[] { "artist 1", "artist 2", "artist 3", "artist 4" };
            mp3.Tag.AlbumArtists = artists;
            string[] performers = new string[] { "Jim Reeves", "Patsy Cline", "\"Boxcar\" Willie" };
            mp3.Tag.Performers = performers;
            mp3.Save();
            mp3.Dispose();
        }
예제 #26
0
        private void WriteMetadata()
        {
            ClearMetadata();
            WriteAlbumCover();

            TagLib.File file = GetTagLibFile();
            file.Tag.Title      = Title;
            file.Tag.Performers = Artists.Split(',');
            file.Tag.Album      = Album;
            file.Tag.Track      = (uint)Convert.ToInt32(TrackNumber);
            file.Tag.Year       = (uint)Convert.ToInt32(Year);
            file.Save();
            file.Dispose();
        }
예제 #27
0
        private void SdkOnDownloadCompleted(object sender, SdkEventArgs e)
        {
            if (e.Error == null)
            {
                if (this.isLaunch)
                {
                    var fileName = Path.GetFileName(this.downloadFileName);
                    var filePath = this.GetFilePath(fileName);

                    this.LaunchFile(filePath);
                    this.isLaunch = false;
                }
            }
            else
            {
                this.ProcessError(e.Error);
            }

            fs.Close();

            TagLib.File f = TagLib.File.Create(downloadFileName);
            currentSongName = f.Tag.FirstPerformer + " - " + f.Tag.Title;

            Dispatcher.BeginInvoke((Action)(() =>
            {
                foreach (int i in new List <int>()
                {
                    0, 1, 2
                })
                {
                    if (txtSongList[i] != currentSongName)
                    {
                        this.buttons[i].Content = txtSongList[i];
                    }
                    else
                    {
                        this.buttons[i].Content = txtSongList[3];
                    }
                }

                this.buttons[3].Content = currentSongName;
                this.buttons[3].Tag = "1";
                mp.Open(new Uri(this.downloadFileName, UriKind.RelativeOrAbsolute));
                mp.Play();
            }));

            txtSongList.Remove(currentSongName);
            f.Dispose();
        }
예제 #28
0
        /// <summary>
        ///     Creates an instance of <see cref="Soulseek.File"/> from the given path.
        /// </summary>
        /// <param name="filename">The fully qualified path to the file.</param>
        /// <param name="maskedFilename">The masked filename.</param>
        /// <returns>The created instance.</returns>
        public File Create(string filename, string maskedFilename)
        {
            var code      = 1;
            var size      = new FileInfo(filename).Length;
            var extension = Path.GetExtension(filename).TrimStart('.').ToLowerInvariant();
            List <FileAttribute> attributeList = default;

            if (SupportedExtensions.Contains(extension))
            {
                attributeList = new List <FileAttribute>();
                TagLib.File file = default;

                try
                {
                    file = TagLib.File.Create(filename, TagLib.ReadStyle.Average | TagLib.ReadStyle.PictureLazy);

                    // try to mimick the behavior of existing clients by providing attributes selectively and in a specific order,
                    // depending on whether files use a lossless or lossy codec. lossless files should have BitsPerSample, while lossy
                    // will not. this may not be the best way to determine this.
                    bool isLossless = file.Properties.BitsPerSample > 0;

                    if (!isLossless)
                    {
                        // per Nicotine+ docs, Soulseek NS, Nicotine+, Museek+, SoulSeeX all send bit rate, length, then VBR
                        attributeList.Add(new FileAttribute(FileAttributeType.BitRate, file.Properties.AudioBitrate));
                        attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds));
                        attributeList.Add(new FileAttribute(FileAttributeType.VariableBitRate, IsVBR(file) ? 1 : 0));
                    }
                    else
                    {
                        // SoulseekQt 2015-6-12 and later provides the length, sample rate and bit depth for lossless files
                        // bitrate can be deduced from this information
                        attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds));
                        attributeList.Add(new FileAttribute(FileAttributeType.SampleRate, file.Properties.AudioSampleRate));
                        attributeList.Add(new FileAttribute(FileAttributeType.BitDepth, file.Properties.BitsPerSample));
                    }
                }
                catch (Exception ex)
                {
                    Log.Debug("Failed to read metadata from file '{Filename}'; the file is an unsupported format or may be corrupt ({ExceptionType})", filename, ex.GetType().Name);
                }
                finally
                {
                    file?.Dispose();
                }
            }

            return(new File(code, maskedFilename, size, extension, attributeList));
        }
예제 #29
0
 private void SetTagsFromFile(string filePath)
 {
     try
     {
         TagLib.File file_tags = TagLib.File.Create(filePath);
         Author = Filter.CleanStringForSearch(file_tags.Tag.FirstPerformer);
         Title  = Filter.CleanStringForSearch(file_tags.Tag.Title);
         file_tags.Dispose();
     }
     catch
     {
         Author = null;
         Title  = null;
     }
 }
 private void ChangeNumberForSelectedSongs()
 {
     try
     {
         var         selectedSong  = (Song)musicListView.SelectedItem;
         TagLib.File musicFileTags = TagLib.File.Create(GetFileWithPath(selectedSong.FileName));
         musicFileTags.Tag.Track = Convert.ToUInt32(NumberTextBox.Text);
         musicFileTags.Save();
         musicFileTags.Dispose();
         InformationTextBox.Text = MusicManagement.Resources.Resources.NumberChanged;
     }
     catch (Exception exc)
     {
         InformationTextBox.Text = exc.Message;
     }
 }