public static AlbumTrackInfo GetPictureByWebService(Tag tag, string titleVk, string artistVk, string fileName) { string artist = string.Empty; string album = string.Empty; string track = string.Empty; var info = new AlbumTrackInfo(); if (tag != null) { if (string.IsNullOrEmpty(tag.Album) == false) { album = tag.Album.ToUtf8(); } if (string.IsNullOrEmpty(tag.Title) == false) { track = tag.Title.ToUtf8(); } if (string.IsNullOrEmpty(tag.Artists.FirstOrDefault()) == false) { var artistWithoutEncoding = tag.Artists.FirstOrDefault(); if (artistWithoutEncoding != null) { artist = artistWithoutEncoding.ToUtf8(); } } var albumTrackInfoByTag = CheckContent(artist, album, track); if (albumTrackInfoByTag != null) { return albumTrackInfoByTag; } } var albumTrackInfo = CheckContent(artistVk.ToUtf8(), "", titleVk.ToUtf8()); if (albumTrackInfo != null) { return albumTrackInfo; } albumTrackInfo = CheckContent("", "", fileName); if (albumTrackInfo != null) { return albumTrackInfo; } info.PicturePath = FilePathContainer.SongAlbumCoverPathPhysical + "default_song_album.jpg"; return info; //songAlbumPicturePath = TagsInformationGetter.SongAlbumPicturePath(audioFile, lastFm, songAlbumPicturePath, ref albumInfoContent); //ImageSaver.SongAlbumCoverPath + "default_song_album.jpg"; }
public AlbumTrackInfo GetAlbumInfo(string artist, string album) { string url = mainUrl + methodAlbumGetInfo + ApiKeyWithparam + "&artist=" + artist + "&album=" + album + "&lang=ru"; XDocument xDoc = new XDocument(); var albumInfo = new AlbumTrackInfo(); try { xDoc = XDocument.Load((url)); } catch (Exception exception) { return null; } if (xDoc.Root != null) { var image = xDoc.Root.Descendants("image") .FirstOrDefault(m => (string)m.Attribute("size") == "large"); if (image != null) { albumInfo.PicturePath = image.Value; } var wiki = xDoc.Root.Descendants("wiki").FirstOrDefault(); if (wiki != null) { var content = wiki.Elements("content").FirstOrDefault(); if (content != null) { albumInfo.Content = content.Value; albumInfo.Content = albumInfo.Content.Replace("<![CDATA[", string.Empty).Replace("]]>", string.Empty).Replace("<content>", string.Empty).Replace("</content>", string.Empty); } } } return albumInfo; }
public AlbumTrackInfo SearchTrackInfo(string track) { string url = mainUrl + methodTrackSearch + "&track=" + track + ApiKeyWithparam + "&limit=1"; XDocument xDoc = new XDocument(); var info = new AlbumTrackInfo(); try { xDoc = XDocument.Load((url)); } catch (Exception exception) { return null; } if (xDoc.Root != null) { var results = xDoc.Root.Elements("results").ToList(); var trackTag = results.Elements("trackmatches").Elements("track");//e("results ").ToList(); if (trackTag == null) { return null; } var image = trackTag.Elements("image").FirstOrDefault(m => (string)m.Attribute("size") == "large"); if (image != null) { info.PicturePath = image.Value; } else { var artistName = trackTag.Elements("artist").FirstOrDefault(); if (artistName != null && string.IsNullOrEmpty(artistName.Value) == false) { return GetTrackInfo(artistName.Value, track); } } var wiki = trackTag.Elements("wiki").FirstOrDefault(); if (wiki != null) { var content = wiki.Elements("content").FirstOrDefault(); if (content != null) { info.Content = content.Value; // albumInfo.Content = albumInfo.Content.Replace("<![CDATA[", string.Empty).Replace("]]>", string.Empty).Replace("<content>", string.Empty).Replace("</content>", string.Empty); } } } return info; }
public AlbumTrackInfo GetTrackInfo(string artist, string track) { string url = mainUrl + methodTrackGetInfo + ApiKeyWithparam + "&artist=" + artist + "&track=" + track; XDocument xDoc = new XDocument(); var info = new AlbumTrackInfo(); try { xDoc = XDocument.Load((url)); } catch (Exception exception) { return null; } if (xDoc.Root != null) { var trackElement = xDoc.Root.Elements("track").ToList(); var albumElement = trackElement.Elements("album").ToList(); var image = trackElement.Elements("image").FirstOrDefault(m => (string)m.Attribute("size") == "large"); if (image != null) { info.PicturePath = image.Value; } else { image = albumElement.Elements("image").FirstOrDefault(m => (string)m.Attribute("size") == "large"); if (image != null) { info.PicturePath = image.Value; } } var wiki = trackElement.Elements("wiki").FirstOrDefault(); if (wiki != null) { var content = wiki.Elements("content").FirstOrDefault(); if (content != null) { info.Content = content.Value; // albumInfo.Content = albumInfo.Content.Replace("<![CDATA[", string.Empty).Replace("]]>", string.Empty).Replace("<content>", string.Empty).Replace("</content>", string.Empty); } } } return info; }