예제 #1
0
        /// <summary>
        /// Load the picture data from the file,
        /// if not done yet.
        /// </summary>
        public void Load()
        {
            // Already loaded ?
            if (file == null)
            {
                return;
            }

            // Load the picture from the stream

            Stream     stream = null;
            ByteVector data   = null;

            try {
                if (stream_size == 0)
                {
                    data = new ByteVector();
                }
                else if (stream_size > 0)
                {
                    stream = file.ReadStream;
                    stream.Seek(stream_offset, SeekOrigin.Begin);

                    int    count = 0, read = 0, needed = (int)stream_size;
                    byte[] buffer = new byte[needed];

                    do
                    {
                        count = stream.Read(buffer, read, needed);

                        read   += count;
                        needed -= count;
                    } while (needed > 0 && count != 0);


                    data = new ByteVector(buffer, read);
                }
                else
                {
                    stream = file.ReadStream;
                    stream.Seek(stream_offset, SeekOrigin.Begin);

                    data = ByteVector.FromStream(stream);
                }
            } finally {
                // Free the resources
                if (stream != null && file != null)
                {
                    file.CloseStream(stream);
                }

                file = null;
            }

            // Decode the raw data if required, by using FieldData
            raw_data = FieldData(data, -(int)FrameHeader.Size(raw_version), raw_version);

            // Get the actual data
            ParseRawData();
        }
예제 #2
0
 public AlbumArt(Stream stream)
 {
     Data        = ByteVector.FromStream(stream);
     Description = "AlbumArt";
     MimeType    = "image/jpeg";
     Type        = PictureType.FrontCover;
 }
예제 #3
0
 private Picture CreatePicture(byte[] bytes)
 {
     using (var ms = new MemoryStream(bytes))
     {
         return(new Picture()
         {
             Data = ByteVector.FromStream(ms),
             Type = PictureType.FrontCover,
             MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg,
             Description = "Cover",
         });
     }
 }
예제 #4
0
        public void SetCover(Bitmap bitmap)
        {
            var ms = new MemoryStream();

            bitmap.Save(ms, ImageFormat.Jpeg);
            ms.Position = 0;
            var pic = new Picture
            {
                Type        = PictureType.FrontCover,
                Description = "Cover",
                Data        = ByteVector.FromStream(ms)
            };

            TagFile.Tag.Pictures = new IPicture[] { pic };
            TagFile.Save();
        }
예제 #5
0
 public static async Task AddTags(IStorageFile resultFile, Song downloadSong)
 {
     using (var tagTemp = TagLib.File.Create(resultFile.Path))
     {
         tagTemp.Tag.Title            = downloadSong.Title;
         tagTemp.Tag.Album            = downloadSong.Album;
         tagTemp.Tag.AlbumArtists     = downloadSong.AlbumArtists;
         tagTemp.Tag.AlbumArtistsSort = downloadSong.AlbumArtistsSort;
         tagTemp.Tag.AlbumSort        = downloadSong.AlbumSort;
         tagTemp.Tag.TitleSort        = downloadSong.TitleSort;
         tagTemp.Tag.Track            = downloadSong.Track;
         tagTemp.Tag.TrackCount       = downloadSong.TrackCount;
         tagTemp.Tag.Disc             = downloadSong.Disc;
         tagTemp.Tag.Composers        = downloadSong.Composers;
         tagTemp.Tag.ComposersSort    = downloadSong.ComposersSort;
         tagTemp.Tag.Conductor        = downloadSong.Conductor;
         tagTemp.Tag.DiscCount        = downloadSong.DiscCount;
         tagTemp.Tag.Copyright        = downloadSong.Copyright;
         tagTemp.Tag.PerformersSort   = downloadSong.Genres;
         tagTemp.Tag.Lyrics           = downloadSong.Lyrics;
         tagTemp.Tag.Performers       = downloadSong.Performers;
         tagTemp.Tag.PerformersSort   = downloadSong.PerformersSort;
         tagTemp.Tag.Year             = downloadSong.Year;
         if (downloadSong.PicturePath != null)
         {
             if (tagTemp.Tag.Pictures != null && tagTemp.Tag.Pictures.Length > 0)
             {
             }
             else
             {
                 using (var referen = await(RandomAccessStreamReference.CreateFromUri(new Uri(downloadSong.PicturePath))).OpenReadAsync())
                 {
                     var p = new List <Picture>
                     {
                         new Picture(ByteVector.FromStream(referen.AsStream()))
                     };
                     tagTemp.Tag.Pictures = p.ToArray();
                 }
             }
         }
         tagTemp.Save();
     }
 }
예제 #6
0
파일: MainForm.cs 프로젝트: cilles/SpotDown
        public void MusicTags(int num, int session)
        {
            PassArguments result = songArray[session][num];

            try
            {
                //===edit tags====
                TagLib.File f = TagLib.File.Create(_dir + EscapeFilename(result.PassedFileName) + ".mp3");
                f.Tag.Clear();
                f.Tag.AlbumArtists = new string[1] {
                    result.PassedArtist
                };
                f.Tag.Performers = new string[1] {
                    result.PassedArtist
                };
                f.Tag.Title = result.PassedSong;
                f.Tag.Album = result.PassedAlbum;
//                //                Log(result.passedFileName + " and " + result.passedAlbumID);
                Image   currentImage = GetAlbumArt(num, session);
                Picture pic          = new Picture();
                pic.Type        = PictureType.FrontCover;
                pic.MimeType    = System.Net.Mime.MediaTypeNames.Image.Jpeg;
                pic.Description = "Cover";
                MemoryStream ms = new MemoryStream();
                currentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); // <-- Error doesn't occur anymore
                ms.Position    = 0;
                pic.Data       = ByteVector.FromStream(ms);
                f.Tag.Pictures = new IPicture[1] {
                    pic
                };
                f.Save();
                ms.Close();
            }
            catch (Exception ex)
            {
                Log("[Error: x7] " + ex.Message + Environment.NewLine + Environment.NewLine + result.PassedFileName, true);
            }
        }
예제 #7
0
        private static void ProgressCallback(DownloadOperation obj)
        {
            if (obj.Progress.BytesReceived == obj.Progress.TotalBytesToReceive)
            {
                if (!DownloadLists.ContainsKey(obj))
                {
                    return;
                }
                _ = Task.Run((async() =>
                {
                    //下载歌词
                    (bool isOk, Newtonsoft.Json.Linq.JObject json) = await Common.ncapi.RequestAsync(CloudMusicApiProviders.Lyric,
                                                                                                     new Dictionary <string, object>()
                    {
                        { "id", DownloadLists[obj].sid }
                    });
                    if (isOk)
                    {
                        if (!(json.ContainsKey("nolyric") && json["nolyric"].ToString().ToLower() == "true") && !(json.ContainsKey("uncollected") && json["uncollected"].ToString().ToLower() == "true"))
                        {
                            var sf = await(await StorageFolder.GetFolderFromPathAsync(Common.Setting.downloadDir)).CreateFileAsync(
                                Path.GetFileName(Path.ChangeExtension(obj.ResultFile.Path, "lrc")), CreationCollisionOption.ReplaceExisting);
                            var lrc = Utils.ConvertPureLyric(json["lrc"]["lyric"].ToString());
                            Utils.ConvertTranslation(json["tlyric"]["lyric"].ToString(), lrc);
                            var lrctxt = string.Join("\r\n", lrc.Select(t =>
                            {
                                if (t.HaveTranslation)
                                {
                                    return("[" + t.LyricTime.ToString(@"mm\:ss\.ff") + "]" + t.PureLyric + " 「" + t.Translation + "」");
                                }
                                return("[" + t.LyricTime.ToString(@"mm\:ss\.ff") + "]" + t.PureLyric);
                            }));
                            await FileIO.WriteTextAsync(sf, lrctxt);
                        }
                    }


                    //写相关信息
                    var file = TagLib.File.Create(new UwpStorageFileAbstraction((StorageFile)obj.ResultFile));
                    file.Tag.Album = DownloadLists[obj].Album.name;
                    file.Tag.Performers = DownloadLists[obj].Artist.Select(t => t.name).ToArray();
                    file.Tag.Title = DownloadLists[obj].songname;
                    file.Tag.Pictures = new IPicture[] { new Picture(ByteVector.FromStream(RandomAccessStreamReference.CreateFromUri(new Uri(DownloadLists[obj].Album.cover)).OpenReadAsync().GetAwaiter().GetResult().AsStreamForRead())) };
                    The163KeyHelper.TrySetMusicInfo(file.Tag, DownloadLists[obj]);
                    file.Save();

                    ToastContent downloadToastContent = new ToastContent()
                    {
                        Visual = new ToastVisual()
                        {
                            BindingGeneric = new ToastBindingGeneric()
                            {
                                Children =
                                {
                                    new AdaptiveText()
                                    {
                                        Text = "下载完成",
                                        HintStyle = AdaptiveTextStyle.Header
                                    },
                                    new AdaptiveText()
                                    {
                                        Text = string.Join(';', DownloadLists[obj].Artist.Select(t => t.name).ToArray()) + " - " + DownloadLists[obj].songname
                                    }
                                }
                            }
                        },
                        Launch = "",
                        Scenario = ToastScenario.Reminder,
                        Audio = new ToastAudio()
                        {
                            Silent = true
                        }
                    };
                    var toast = new ToastNotification(downloadToastContent.GetXml())
                    {
                        Tag = "HyPlayerDownloadDone",
                        Data = new NotificationData()
                    };

                    toast.Data.SequenceNumber = 0;
                    ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
                    notifier.Show(toast);


                    //清理
                    DownloadLists.Remove(obj);
                }));
            }
        }
예제 #8
0
 private void SetBasicProperties(Tag target, string title, IEnumerable <string> genres, string description, Stream image)
 {
     SetPropertyIfValid(target, title, (d, e) => d.Title = e);
     SetPropertyIfValid(target, genres, d => d != null && d.Any(), (d, e) => d.Genres = e.ToArray());
     SetPropertyIfValid(target, description, (d, e) => d.Description        = e);
     SetPropertyIfValid(target, image, d => d != null, (d, e) => d.Pictures = new Picture[] { new Picture(ByteVector.FromStream(e)) });
 }