private void DownloadCoverart() { try { Query query = new Query(MUSICBRAINZ_HEAD); Guid artistMbid = query.FindArtists("artist:" + Artists).Results[0].MbId; Guid releaseMbid = query.FindReleases("recording:" + Title + " AND arid:" + artistMbid).Results[0].MbId; Album = query.LookupRelease(releaseMbid).Title; Year = query.LookupRelease(releaseMbid).Date.Year.ToString(); if (query.LookupRelease(releaseMbid).CoverArtArchive.Front) { CoverArt ca = new CoverArt(MUSICBRAINZ_HEAD); CoverArt = new Uri(Path.GetTempPath() + releaseMbid + ".jpg"); ca.FetchFront(releaseMbid).Decode().Save(CoverArt.LocalPath); foundCoverart = true; } else { CoverArt = new Uri(Environment.CurrentDirectory + @"\assets\savify-cover-default.jpg"); } } catch { CoverArt = new Uri(Environment.CurrentDirectory + @"\assets\savify-cover-default.jpg"); } }
private static CoverArt GetScaledCoverArt(Track track, string trackCoverArtPath) { var lockObject = ProcessingFiles.GetOrAdd(trackCoverArtPath, new object()); try { lock (lockObject) { if (!(File.Exists(trackCoverArtPath) && track.DateFileModified.ToUniversalTime() < File.GetLastWriteTimeUtc(trackCoverArtPath))) { return(null); } } } finally { ProcessingFiles.TryRemove(trackCoverArtPath, out lockObject); } // Return the album art on disk if the file exists and is newer than the last modified date of the track var coverArtData = ReadCoverArtFromDisk(trackCoverArtPath); var coverArtReturn = new CoverArt { CoverArtData = coverArtData, CoverArtType = CoverArtType.Front, MediaId = track.Id, Size = coverArtData.Length, MimeType = MimeType.GetMimeType(coverArtData, trackCoverArtPath) }; return(coverArtReturn); }
internal CovrAtom(CoverArt coverArt) { Contract.Requires(coverArt != null); Contract.Ensures(Value != null); CoverType = coverArt.MimeType == "image/png" ? CoverType.Png : CoverType.Jpeg; Value = coverArt.GetData(); }
///<summary> Переход в обычный режим. </summary> public void TurnOffPreviewMode() { // плавное проявление кавера var alphaOut = new DoubleAnimation(CoverArt.Opacity, 1, new Duration(TimeSpan.FromMilliseconds(fadeTime))); CoverArt.BeginAnimation(Image.OpacityProperty, alphaOut); alphaOut.Completed += (s, e) => { previewGrid.Visibility = Visibility.Hidden; }; }
///<summary> Переход в режим превью. </summary> public void TurnOnPreviewMode() { previewGrid.Visibility = Visibility.Visible; // плавное скрытие кавера var alphaIn = new DoubleAnimation(CoverArt.Opacity, 0, new Duration(TimeSpan.FromMilliseconds(fadeTime))); CoverArt.BeginAnimation(Image.OpacityProperty, alphaIn); }
/// <summary> /// Creates the player form and starts the task that monitors Spotify for /// changes to its window title. /// </summary> public PlayerForm() { InitializeComponent(); // Get the cover art folder location and filename _appFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _defaultCover = Path.Combine(_appFolder, "default_cover.png"); // Turn the full file path into a URI for the PictureBox Uri uri = new Uri(_defaultCover); _defaultCover = uri.AbsoluteUri; // Load the default CoverArt.Load(_defaultCover); Task.Run(() => { // Let the defaults load Thread.Sleep(1000); Process spotifyProcess = null; string spotifyTitle = string.Empty; // Look for the Spotify process and monitor its window title while (true) { if (spotifyProcess == null) { var processes = Process.GetProcessesByName("spotify"); if (processes.Length < 1) { Thread.Sleep(5000); continue; } spotifyProcess = processes[0]; } else { spotifyProcess.Refresh(); if (spotifyProcess.HasExited) { spotifyProcess = null; continue; } string title = spotifyProcess.MainWindowTitle; if (title != spotifyTitle) { spotifyTitle = title; SetLabel(title); } Thread.Sleep(5000); } } }); }
private void ReadCoverArt() { var coverArtList = new List <CoverArt>(); foreach (var picture in _fileTag.Tag.Pictures) { var coverArtType = CoverArtType.Other; switch (picture.Type) { case PictureType.Artist: coverArtType = CoverArtType.Artist; break; case PictureType.BackCover: coverArtType = CoverArtType.Back; break; case PictureType.Band: coverArtType = CoverArtType.Band; break; case PictureType.BandLogo: coverArtType = CoverArtType.BandLogo; break; case PictureType.FrontCover: coverArtType = CoverArtType.Front; break; case PictureType.LeadArtist: coverArtType = CoverArtType.LeadArtist; break; case PictureType.LeafletPage: coverArtType = CoverArtType.Leaflet; break; case PictureType.Media: coverArtType = CoverArtType.Media; break; } var coverArt = new CoverArt { MimeType = picture.MimeType, CoverArtType = coverArtType, CoverArtData = picture.Data.Data, Size = picture.Data.Data.Length }; coverArtList.Add(coverArt); } CoverArt = coverArtList; }
internal MetadataBlockPicture(CoverArt coverArt) { Type = PictureType.CoverFront; MimeType = coverArt.MimeType; Description = string.Empty; Width = (uint)coverArt.Width; Height = (uint)coverArt.Height; ColorDepth = (uint)coverArt.ColorDepth; Data = coverArt.GetData(); }
internal AtomToMetadataAdapter(Mp4 mp4, AtomInfo[] atoms) { Contract.Requires(mp4 != null); Contract.Requires(atoms != null); foreach (AtomInfo atom in atoms) { byte[] atomData = mp4.ReadAtom(atom); switch (atom.FourCC) { case "trkn": var trackNumberAtom = new TrackNumberAtom(atomData); Add("TrackNumber", trackNumberAtom.TrackNumber.ToString(CultureInfo.InvariantCulture)); if (trackNumberAtom.TrackCount > 0) { Add("TrackCount", trackNumberAtom.TrackCount.ToString(CultureInfo.InvariantCulture)); } break; case "©day": // The ©day atom may contain a full date, or only the year: var dayAtom = new TextAtom(atomData); DateTime result; if (DateTime.TryParse(dayAtom.Value, CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault, out result) && result.Year >= 1000) { base["Day"] = result.Day.ToString(CultureInfo.InvariantCulture); base["Month"] = result.Month.ToString(CultureInfo.InvariantCulture); base["Year"] = result.Year.ToString(CultureInfo.InvariantCulture); } else { base["Year"] = dayAtom.Value; } break; case "covr": try { CoverArt = new CoverArt(new CovrAtom(atomData).Value); } catch (UnsupportedCoverArtException) { } break; default: string mappedKey; if (_map.TryGetValue(atom.FourCC, out mappedKey)) { base[mappedKey] = new TextAtom(atomData).Value; } break; } } }
internal CoverArtToPictureBlockAdapter(CoverArt coverArt) { Contract.Requires(coverArt != null); SetData(coverArt.GetData()); SetType(PictureType.CoverFront); SetMimeType(coverArt.MimeType); SetWidth(coverArt.Width); SetHeight(coverArt.Height); SetColorDepth(coverArt.ColorDepth); }
internal CoverArtToFrameAdapter(CoverArt coverArt) : base("APIC") { Contract.Requires(coverArt != null); Contract.Ensures(PictureType == PictureTypeCode.CoverFront); Contract.Ensures(!string.IsNullOrEmpty(Mime)); Contract.Ensures(PictureData != null); Contract.Ensures(PictureData.Length > 0); PictureType = PictureTypeCode.CoverFront; Mime = coverArt.MimeType; PictureData = coverArt.GetData(); }
public ActionResult DeleteConfirmed(int id) { try { CoverArt coverArt = db.CoverArts.Find(id); db.CoverArts.Remove(coverArt); db.SaveChanges(); return(RedirectToAction("Index")); } catch (DataException) { return(RedirectToAction("Delete", new { id = id, saveChangesError = true })); } }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CoverArt coverArt = db.CoverArts.Find(id); if (coverArt == null) { return(HttpNotFound()); } return(View(coverArt)); }
public override int GetHashCode() { unchecked { var hashCode = SmallIcon != null?SmallIcon.GetHashCode() : 0; hashCode = hashCode * 397 ^ (Icon != null ? Icon.GetHashCode() : 0); hashCode = hashCode * 397 ^ (Featured != null ? Featured.GetHashCode() : 0); hashCode = hashCode * 397 ^ (Background != null ? Background.GetHashCode() : 0); hashCode = hashCode * 397 ^ (CoverArt != null ? CoverArt.GetHashCode() : 0); hashCode = hashCode * 397 ^ (Decal != null ? Decal.GetHashCode() : 0); return(hashCode); } }
// GET: CoverArts/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CoverArt coverArt = db.CoverArts.Find(id); if (coverArt == null) { return(HttpNotFound()); } ViewBag.MyGamesID = new SelectList(db.Games, "ID", "Name", coverArt.MyGamesID); return(View(coverArt)); }
public override int GetHashCode() { var hash = 13; var hashFactor = 7; hash = Id.GetHashCode(hash, hashFactor); hash = Artist.GetHashCode(hash, hashFactor); hash = Genre.GetHashCode(hash, hashFactor); hash = hash * hashFactor + Year.GetHashCode(); hash = hash * hashFactor + Rating.GetHashCode(); hash = hash * hashFactor + Starred.GetHashCode(); hash = hash * hashFactor + AlbumArtSize.GetHashCode(); hash = CoverArt.GetHashCode(hash, hashFactor); hash = hash * hashFactor + Child.GetHashCode(); return(hash); }
// GET: CoverArts/Delete/5 public ActionResult Delete(int?id, bool?saveChangesError = false) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (saveChangesError.GetValueOrDefault()) { ViewBag.ErrorMessage = "Delete failed. Try again, if the problem persists please contact the system administrator."; } CoverArt coverArt = db.CoverArts.Find(id); if (coverArt == null) { return(HttpNotFound()); } return(View(coverArt)); }
public ActionResult Edit([Bind(Include = "ID,MyGamesID,PhotoPath,AltText")] CoverArt coverArt) { try { if (ModelState.IsValid) { db.Entry(coverArt).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again. If problem persits contact the system administrator"); } ViewBag.MyGamesID = new SelectList(db.Games, "ID", "Name", coverArt.MyGamesID); return(View(coverArt)); }
protected override void ProcessRecord() { DirectoryInfo outputDirectory; try { outputDirectory = new DirectoryInfo(this.GetFileSystemPaths(Path, LiteralPath).First()); } catch (ItemNotFoundException e) { outputDirectory = new DirectoryInfo(e.ItemName); } if (ShouldProcess(System.IO.Path.Combine(outputDirectory.FullName, Name + CoverArt.Extension))) { CoverArt.Export(outputDirectory, Name, Replace); } if (PassThru) { WriteObject(CoverArt); } }
public StoryListViewModel GetTopStories(BaseInputModel inputModel) { if (!inputModel.Count.HasValue) inputModel.Count = 10; var stories = _storyService.GetTopStories((int) inputModel.Count); foreach (var storey in stories) { if (storey.CoverArt == null) { var coverArt = new CoverArt { Cover = ResizeImage.ResizeImageFile(@"Content\img\64x64.gif",32,32) }; storey.CoverArt = coverArt; } } return new StoryListViewModel(stories, CurrentUser); }
internal VorbisCommentToMetadataAdapter(VorbisComment vorbisComment) { var commentLengths = new int[vorbisComment.Comments]; Marshal.Copy(vorbisComment.CommentLengths, commentLengths, 0, commentLengths.Length); var commentPtrs = new IntPtr[vorbisComment.Comments]; Marshal.Copy(vorbisComment.UserComments, commentPtrs, 0, commentPtrs.Length); for (var i = 0; i < vorbisComment.Comments; i++) { var commentBytes = new byte[commentLengths[i]]; Marshal.Copy(commentPtrs[i], commentBytes, 0, commentLengths[i]); string[] comment = Encoding.UTF8.GetString(commentBytes).Split(new[] { '=' }, 2); Contract.Assert(comment.Length == 2); // The track number and count may be packed into the same comment: switch (comment[0]) { case "TRACKNUMBER": string[] segments = comment[1].Split('/'); base["TrackNumber"] = segments[0]; if (segments.Length > 1) { base["TrackCount"] = segments[1]; } break; case "DATE": case "YEAR": // The DATE comment may contain a full date, or only the year: DateTime result; if (DateTime.TryParse(comment[1], CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault, out result) && result.Year >= 1000) { base["Day"] = result.Day.ToString(CultureInfo.InvariantCulture); base["Month"] = result.Month.ToString(CultureInfo.InvariantCulture); base["Year"] = result.Year.ToString(CultureInfo.InvariantCulture); } else { base["Year"] = comment[1]; } break; case "METADATA_BLOCK_PICTURE": var picture = new MetadataBlockPicture(comment[1]); if (picture.Type == PictureType.CoverFront || picture.Type == PictureType.Other) { try { CoverArt = new CoverArt(picture.Data); } catch (UnsupportedCoverArtException) { } } break; case "COVERART": try { // Deprecated way to store cover art: CoverArt = new CoverArt(Convert.FromBase64String(comment[1])); } catch (UnsupportedCoverArtException) { } break; default: string mappedKey; if (_map.TryGetValue(comment[0], out mappedKey)) { base[mappedKey] = comment[1]; } break; } } }
/// <summary> /// Using the main window text passed in from the Spotify process, this method /// extracts the artist and song title. It then uses the audio scrobbler web /// service to download details about the song so that we display accurate /// information. We also use audio scrobbler's album cover art to update the /// album art displayed. /// </summary> /// <param name="label">The window label (main window text) of the Spotify /// process</param> public void SetLabel(string label) { if (InvokeRequired) { Invoke(new SetLabelDelegate(SetLabel), label); } else { // Get rid of the "Spotify - " prefix and then split out the artist // and song string noSpotify = label.Replace("Spotify - ", string.Empty); var parts = noSpotify.Split('–'); if (parts.Length < 2) { // Well. Damn. It appears we weren't passed any meaningful text, // so go back to the defaults. _title = "Song Title"; Artist.Text = "Artist"; CoverArt.Load(_defaultCover); return; } string artist = parts[0].Trim(); string title = parts[1].Trim(); _title = title; Artist.Text = artist; Invalidate(); // Let's try to get the song details from Audio Scrobbler string url = "http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key={0}&autocorrect=1&artist={1}&track={2}"; artist = HttpUtility.UrlEncode(artist); title = HttpUtility.UrlEncode(title); url = string.Format(url, _scrobblerApiKey, artist, title); using (WebClient client = new WebClient()) { // Download the audioscrobbler XML for the given artist and song string xml = client.DownloadString(url); XDocument xmlDoc = XDocument.Load(new StringReader(xml)); var imgUrls = from img in xmlDoc.XPathSelectElements("//album/image") where img.Attribute("size").Value == "large" select img.Value; string imgUrl = imgUrls.FirstOrDefault(); // If we can't find an image URL, just use the default cover if (imgUrl == null) { CoverArt.LoadAsync(_defaultCover); } else { // Download the image data from audio scrobbler and dispose the previous // cover art image (prevents a memory leak) byte[] imageData = client.DownloadData(imgUrl); using (Stream stream = new MemoryStream(imageData)) { Image image = Image.FromStream(stream); Image old = CoverArt.Image; CoverArt.Image = image; old.Dispose(); } } } // Perform a quick GC and compact the large-object heap GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; GC.Collect(); } }
internal TagModelToMetadataAdapter(TagModel tagModel) { Contract.Requires(tagModel != null); foreach (FrameBase frame in tagModel) { var frameText = frame as FrameText; if (frameText != null) { switch (frameText.FrameId) { // The TRCK frame contains the track number and (optionally) the track count: case "TRCK": string[] segments = frameText.Text.Split('/'); base["TrackNumber"] = segments[0]; if (segments.Length > 1) { base["TrackCount"] = segments[1]; } break; // The TDAT frame contains the day and the month: case "TDAT": base["Day"] = frameText.Text.Substring(0, 2); base["Month"] = frameText.Text.Substring(2); break; default: string mappedKey; if (_map.TryGetValue(frameText.FrameId, out mappedKey)) { base[mappedKey] = frameText.Text; } break; } } else { var framePicture = frame as FramePicture; if (framePicture != null && (framePicture.PictureType == PictureTypeCode.CoverFront || framePicture.PictureType == PictureTypeCode.Other)) { try { CoverArt = new CoverArt(framePicture.PictureData); } catch (UnsupportedCoverArtException) { } } else { var frameFullText = frame as FrameFullText; if (frameFullText != null && frameFullText.FrameId == "COMM" && frameFullText.Description == null) { base["Comment"] = frameFullText.Text; } else { var frameTextUserDef = frame as FrameTextUserDef; if (frameTextUserDef == null || frameTextUserDef.FrameId != "TXXX") { continue; } switch (frameTextUserDef.Description) { case "REPLAYGAIN_TRACK_GAIN": base["TrackGain"] = frameTextUserDef.Text; break; case "REPLAYGAIN_TRACK_PEAK": base["TrackPeak"] = frameTextUserDef.Text; break; case "REPLAYGAIN_ALBUM_GAIN": base["AlbumGain"] = frameTextUserDef.Text; break; case "REPLAYGAIN_ALBUM_PEAK": base["AlbumPeak"] = frameTextUserDef.Text; break; } } } } } }