예제 #1
0
        /// <summary>
        /// 加载图片
        /// </summary>
        public void LoadImages()
        {
            images = new List <FileInfo>();

            var commonPicturesDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.CommonPictures));

            images.AddRange(commonPicturesDir.GetFiles("*.jpg", SearchOption.AllDirectories));
            images.AddRange(commonPicturesDir.GetFiles("*.png", SearchOption.AllDirectories));


            var myPicturesDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));

            images.AddRange(myPicturesDir.GetFiles("*.jpg", SearchOption.AllDirectories));
            images.AddRange(myPicturesDir.GetFiles("*.png", SearchOption.AllDirectories));

            myMusicDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic));
            myCoverDir = new DirectoryInfo(myMusicDir.FullName + @"\Covers\");
            if (!myCoverDir.Exists)
            {
                myCoverDir.Create();
            }
            myLyricDir = new DirectoryInfo(myMusicDir.FullName + @"\Lyrics\");
            if (!myLyricDir.Exists)
            {
                myLyricDir.Create();
            }
            FileInfo[] musics = myMusicDir.GetFiles("*.mp3");

            foreach (var music in musics)
            {
                string cover = myCoverDir + @"\" + System.IO.Path.GetFileNameWithoutExtension(music.FullName) + ".jpg";
                if (!File.Exists(cover))
                {
                    ID3Info info = new ID3Info(music.FullName, true);//从ID3V2信息中读取封面
                    info.Load();
                    if (info.ID3v2Info.HaveTag && info.ID3v2Info.AttachedPictureFrames.Items.Length > 0)
                    {
                        MemoryStream         ms  = info.ID3v2Info.AttachedPictureFrames.Items[0].Data;
                        System.Drawing.Image img = Bitmap.FromStream(ms);
                        img.Save(cover, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                    else
                    {
                        File.Copy(System.Environment.CurrentDirectory + @"\cover.jpg", cover, true);
                    }
                }
                images.Add(new FileInfo(cover));
            }

            images.Sort(new FileInfoComparer());
            foreach (FileInfo f in images)
            {
                flow.Add(Environment.MachineName, f.FullName);
            }
        }
예제 #2
0
        private void ExecCodeProj(string fileName)
        {
            ID3Info id3Info = new ID3Info(fileName, true);

            id3Info.Load();
            textBox1.Text = id3Info.ID3v2Info.GetTextFrame("TIT2") + ";" + id3Info.ID3v1Info.Title;

            id3Info.ID3v2Info.SetTextFrame("TIT2", id3Info.ID3v1Info.Title.Trim());
            id3Info.ID3v1Info.Title = id3Info.ID3v1Info.Title.Trim() + "";
            id3Info.Save();

            textBox2.Text = id3Info.ID3v2Info.GetTextFrame("TIT2") + ";" + id3Info.ID3v1Info.Title;
        }
예제 #3
0
        /// <summary>
        /// 打开图片展示或者音乐播放窗口
        /// </summary>
        private void OpenSubWindow()
        {
            string path = CheckIfMusicPath(currentIndex);

            if (path != "")
            {
                ID3Info id3Info = new ID3Info(path, true);
                id3Info.Load();
                BassEngine.Instance.OpenFile(path);
                musicWindow = new MusicWindow(images[currentIndex], id3Info);
                musicWindow.Show();
            }
            else
            {
                detialWindow = new DetialWindow(images[currentIndex]);
                detialWindow.Show();
            }
        }
예제 #4
0
        /// <summary>
        /// 下载红心歌曲
        /// </summary>
        public void Download()
        {
            if (Directory.Exists(Path) == false)//如果不存在就创建文件夹
            {
                Directory.CreateDirectory(Path);
            }
            client.NewList();
            client.SwitchChannel(Channel.RedHeart);
            int times = 0;
            int num   = 0;

            while (dic.Count <= Total)
            {
                foreach (Song song in client.Playlist)
                {
                    if (!dic.Keys.Contains(song.SongID))
                    {
                        dic.Add(song.SongID, song);
                        num++;
                        currentSong = song;
                        string fileName = Path + song.Title + ".mp3";
                        try
                        {
                            image = Image.FromStream(WebRequest.Create(song.PictureURL).GetResponse().GetResponseStream());
                        }
                        catch (Exception)
                        {
                            image = Properties.Resources.cover;
                        }
                        NewSong.Invoke(num, image, song.Title, song.Artist);
                        if (File.Exists(fileName))
                        {
                            Exist++;
                        }
                        else
                        {
                            if (Downfile(song.MediaURL, fileName))
                            {
                                Success++;
                                ID3Info info = new ID3Info(fileName, true);
                                info.Load();
                                info.ID3v2Info.SetMinorVersion(3);
                                AttachedPictureFrame pic = null;
                                try
                                {
                                    if (!string.IsNullOrEmpty(CoverPath))//保存封面
                                    {
                                        image.Save(CoverPath + song.Title + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                                    }

                                    ms = new System.IO.MemoryStream();
                                    image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                                    // 创建新封面
                                    pic = new AttachedPictureFrame(
                                        FrameFlags.Compression, "cover.jpg", TextEncodings.UTF_16, "",
                                        AttachedPictureFrame.PictureTypes.Cover_Front, ms);
                                    info.ID3v2Info.AttachedPictureFrames.Add(pic);
                                    // 添加新封面到MP3中
                                }
                                catch
                                {
                                }

                                if (!string.IsNullOrEmpty(lyricPath))//下载歌词
                                {
                                    downloadLrc.SaveLyric(song.Artist, song.Title, lyricPath + song.Title + ".lrc");
                                }

                                // 设置其它属性(ID3V1)
                                info.ID3v1Info.Title  = song.Title;
                                info.ID3v1Info.Artist = song.Artist;
                                info.ID3v1Info.Album  = song.AlbumTitle;

                                //jasine fixed 2015.9.23
                                info.ID3v1Info.Year = song.PublicationTime;
                                //info.ID3v1Info.Year = "";

                                info.ID3v1Info.Comment = "*****@*****.**"; //注释---------添加不上去
                                info.ID3v1Info.Genre   = 12;                     //类型代码Other:12 对应于ID3V2中自定义类型RedHeart

                                // 设置其它属性(ID3V2)
                                info.ID3v2Info.SetTextFrame("TIT2", song.Title);
                                info.ID3v2Info.SetTextFrame("TPE1", song.Artist);
                                info.ID3v2Info.SetTextFrame("TALB", song.AlbumTitle);

                                //jasine fixed 2015.9.23
                                info.ID3v2Info.SetTextFrame("TYER", song.PublicationTime);
                                //info.ID3v2Info.SetTextFrame("TYER", "");

                                //info.ID3v2Info.SetTextFrame("COMM", "*****@*****.**");//注释---------添加不上去
                                info.ID3v2Info.SetTextFrame("TCON", "RedHeart");//类型

                                //jasine fixed 2015.9.23
                                //info.ID3v2Info.SetTextFrame("TPUB", song.Publisher);//发布者,发布单位
                                info.ID3v2Info.SetTextFrame("TPUB", "");//发布者,发布单位

                                // 保存到MP3中
                                if (ID3Version == 1)
                                {
                                    info.ID3v1Info.Save();
                                }
                                else
                                {
                                    //info.Save(3);
                                    info.ID3v2Info.PopularimeterFrames.Add(new ID3.ID3v2Frames.TextFrames.PopularimeterFrame(
                                                                               FrameFlags.TagAlterPreservation, "fm.douban.com", song.Rating, 0));//豆瓣评分
                                    info.ID3v2Info.Save(3);
                                }
                            }
                            else
                            {
                                //下载失败
                                Fail++;
                            }
                        }
                        if ((Success + Fail + Exist) >= Total)
                        {
                            Msg.Invoke(Success, Fail, Exist, "下载完成");
                            Stop();
                        }
                        else
                        {
                            Msg.Invoke(Success, Fail, Exist, "");
                        }
                    }
                }
                client.Skip();
                times++;
                if (times > 10000)
                {
                    Fail = Total - (Success + Exist);
                    Msg.Invoke(Success, Fail, Exist, "尝试次数过多,未成功下载歌曲请过几小时后再在原文件夹下载");
                    Stop();
                }
            }
            Msg.Invoke(Success, Fail, Exist, "下载完成");
        }