public ReleaseHelper(Release release, MusicBrainzClient musicBrainzClient) { Tags = new List <Tag>(); UsedTags = new List <string>(); _release = release; client = musicBrainzClient; }
private static async Task RunExamples() { // Make sure that TLS 1.2 is available. ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; // Get path for local file cache. var location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var client = new MusicBrainzClient() { Cache = new FileRequestCache(Path.Combine(location, "cache")) }; Header("Example 1"); await Example1.Run(client); Header("Example 2"); await Example2.Run(client); Header("Example 3"); await Example3.Run(client); Header("Example 4"); await Example4.Run(client); Header("Example 5"); await Example5.Run(client); Header("Example 6"); await Example6.Run(client); }
internal SearchRequest(MusicBrainzClient client, UrlBuilder builder, string query, string entity) { this.client = client; this.builder = builder; this.query = query; EntityName = entity; }
internal LookupRequest(MusicBrainzClient client, UrlBuilder builder, string id, string entity) { this.client = client; this.builder = builder; this.id = id; EntityName = entity; }
public static async Task Search(MusicBrainzClient client, string genre, int limit) { Console.WriteLine("Getting bands from the UK matching tag '{0}'", genre); var query = new QueryParameters <Artist>() { { "tag", genre }, { "type", "group" }, { "country", "GB" } }; // Search for artist. var artists = await client.Artists.Search(query).Limit(limit).GetAsync(); Console.WriteLine(); Console.WriteLine("The first {0} of {1} bands:", limit, artists.Count); Console.WriteLine(); DisplayArtists(artists); var artist = artists.Items[DateTime.Now.Second % artists.Items.Count]; Console.WriteLine(); Console.WriteLine("Choose random artist '{0}' and browse official album releases:", artist.Name); // Create request. var request = client.ReleaseGroups.Browse("artist", artist.Id).Limit(limit).Type("album"); // Browse release-groups. var groups = await request.GetAsync(); int pages = Math.Max(1, groups.Count / limit); // Print the first page DisplayReleases(groups, 1, pages); const int MAX_PAGES = 5; int i = 1; for (; i < pages && i < MAX_PAGES; i++) { // Advance browse offset and fetch results. groups = await request.Offset(i *limit).GetAsync(); DisplayReleases(groups, i + 1, pages); // Try to avoid rate limit ... await Task.Delay(500); } if (i == MAX_PAGES) { Console.WriteLine(); Console.WriteLine("Stopping at page {0} ...", i); } }
public static async Task Search(MusicBrainzClient client, string band, string album) { // Build an advanced query to search for the release. var query = new QueryParameters <ReleaseGroup>() { { "artist", band }, { "releasegroup", album }, { "type", "album" }, { "status", "official" } }; // Search for an release-group by title. var groups = await client.ReleaseGroups.SearchAsync(query); Console.WriteLine("Total matches for '{0} - {1}': {2}", band, album, groups.Count); // Get best match. var group = groups.Items.First(); // Get detailed information of the release-group, including artists, releases and related urls. group = await client.ReleaseGroups.GetAsync(group.Id, "artists", "releases", "url-rels"); var artist = group.Credits.First().Artist; Console.WriteLine(); Console.WriteLine("Official album releases of '{0} - {1}':", artist.Name, group.Title); Console.WriteLine(); foreach (var item in group.Releases.OrderBy(r => r.Date)) { Console.WriteLine(" {0} - {1} {2}", item.Date.ToShortDate(), item.Id, item.Country); } // Check if there are lyrcis available for the album. var lyrics = group.Relations.Where(r => r.Type == "lyrics"); if (lyrics.Count() > 0) { Console.WriteLine(); Console.WriteLine("You can find lyrics for '{0} - {1}' at", artist.Name, group.Title); Console.WriteLine(); Console.WriteLine(" {0}", lyrics.First().Url.Resource); Console.WriteLine(); } // Check if there's a wikipedia page for the album. var wiki = group.Relations.Where(r => r.Type == "wikipedia"); if (wiki.Count() > 0) { Console.WriteLine(); Console.WriteLine("More info for '{0} - {1}' at", artist.Name, group.Title); Console.WriteLine(); Console.WriteLine(" {0}", wiki.First().Url.Resource); Console.WriteLine(); } }
public static async Task <ReleaseList> BrowseAsync(string entity, string id, string type, string status = null, int limit = 25, int offset = 0, params string[] inc) { var client = new MusicBrainzClient(Configuration.Proxy) { Cache = Configuration.Cache }; return(await client.Releases.BrowseAsync(entity, id, type, status, limit, offset, inc)); }
internal BrowseRequest(MusicBrainzClient client, UrlBuilder builder, string id, string relatedEntity, string entity) { this.client = client; this.builder = builder; this.relatedEntity = relatedEntity; this.id = id; EntityName = entity; }
public static async Task <ArtistList> BrowseAsync(string entity, string id, int limit = 25, int offset = 0, params string[] inc) { var client = new MusicBrainzClient(Configuration.Proxy) { Cache = Configuration.Cache }; return(await client.Artists.BrowseAsync(entity, id, limit, offset, inc)); }
protected override async Task <ReleaseList> BrowseAsync(MusicBrainzClient client, CancellationToken ct) { string url = builder.CreateBrowseUrl(EntityName, relatedEntity, id, type, status, limit, offset, include); var list = await client.GetAsync <ReleaseListBrowse>(url, ct); return(new ReleaseList() { Items = list.Items, Count = list.Count, Offset = list.Offset }); }
public static async Task Search(MusicBrainzClient client, string artist, string album, string song) { // Build an advanced query to search for the recording. var query = new QueryParameters <Recording>() { { "artist", artist }, { "release", album }, { "recording", song } }; // Search for a recording by title. var recordings = await client.Recordings.SearchAsync(query); Console.WriteLine("Total matches for '{0} ({1}) {2}': {3}", artist, album, song, recordings.Count); // Get exact matches. var matches = recordings.Items.Where(r => r.Title == song && r.Releases.Any(s => s.Title == album)); // Get the best match (in this case, we use the recording that has the most releases associated). var recording = matches.OrderByDescending(r => r.Releases.Count).First(); // Get the first official release. var release = recording.Releases.Where(r => r.Title == album && IsOfficial(r)).OrderBy(r => r.Date).First(); // Get detailed information of the recording, including related works. recording = await client.Recordings.GetAsync(recording.Id, "work-rels"); if (recording.Relations.Count == 0) { Console.WriteLine(); Console.WriteLine("No lyrics available :-("); Console.WriteLine(); return; } // Expect only a single work related to recording. var work = recording.Relations.First().Work; // Get detailed information of the work, including related urls. work = await client.Work.GetAsync(work.Id, "url-rels"); // Check if there are lyrcis available for the recording. var lyrics = work.Relations.Where(r => r.Type == "lyrics"); if (lyrics.Count() > 0) { Console.WriteLine(); Console.WriteLine("You can find lyrics for '{0} - {1} ({2})' at", artist, recording.Title, release.Date.ToShortDate()); Console.WriteLine(); Console.WriteLine(" {0}", lyrics.First().Url.Resource); Console.WriteLine(); } }
public IHttpActionResult Get(string id) { var artist = _service.GetOne(id); if (artist == null) { return(NotFound()); } var realeases = MusicBrainzClient.GetReleases(artist.ID.ToString()); return(Ok(realeases)); }
public ArtistController(MusicBrainzClient musicBrainzClient, WikiDataClient wikiDataClient, WikipediaClient wikipediaClient, CoverArtService coverArtService, ILogger <ArtistController> logger) { _musicBrainzClient = musicBrainzClient; _wikiDataClient = wikiDataClient; _wikipediaClient = wikipediaClient; _coverArtService = coverArtService; _logger = logger; }
public static async Task Search(MusicBrainzClient client, string name) { // Search for an artist by name (limit to 20 matches). var artists = await client.Artists.SearchAsync(name.Quote(), 20); Console.WriteLine("Total matches for '{0}': {1}", name, artists.Count); // Count matches with score 100. int count = artists.Items.Count(a => a.Score == 100); Console.WriteLine("Exact matches for '{0}': {1}", name, count); // By default, search results will be ordered by score, so to get the // best match you could do artists.Items.First(). Sometimes this method // won't work (example: search for 'U2'). // // If the search string is the exact name, it might be better to compare // to that string or to order by similarity, like done here: var artist = artists.Items.OrderByDescending(a => Levenshtein.Similarity(a.Name, name)).First(); // Get detailed information of the artist, including band-members and related urls. artist = await client.Artists.GetAsync(artist.Id, "artist-rels", "url-rels"); Console.WriteLine(); Console.WriteLine("Current band members of '{0}':", artist.Name); Console.WriteLine(); // Band members are represented as artist-artist relationships. To filter relations, // inspect "TargetType" and "Type" properties. var members = artist.Relations.Where(r => r.TargetType == "artist" && r.Type.Contains("member")); foreach (var relation in members.Where(r => !(bool)r.Ended)) { Console.WriteLine(" {0}", relation.Artist.Name); } // Lyric are represented as artist-url relationships. var lyrics = artist.Relations.Where(r => r.TargetType == "url" && r.Type == "lyrics"); if (lyrics.Count() > 0) { Console.WriteLine(); Console.WriteLine("You can find lyrics for '{0}' at", artist.Name); Console.WriteLine(); foreach (var relation in lyrics) { Console.WriteLine(" {0}", relation.Url.Resource); } } }
public static async Task <ReleaseList> SearchAsync(string query, int limit = 25, int offset = 0) { if (string.IsNullOrEmpty(query)) { throw new ArgumentException(string.Format(Resources.Messages.MissingParameter, "query")); } var client = new MusicBrainzClient(Configuration.Proxy) { Cache = Configuration.Cache }; return(await client.Releases.SearchAsync(query, limit, offset)); }
public static async Task <Release> GetAsync(string id, params string[] inc) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException(string.Format(Resources.Messages.MissingParameter, "id")); } var client = new MusicBrainzClient(Configuration.Proxy) { Cache = Configuration.Cache }; return(await client.Releases.GetAsync(id, inc)); }
private static async Task Browse(MusicBrainzClient client, string name) { // Search for an artist by name (limit to 20 matches). var artists = await client.Artists.SearchAsync(name.Quote(), 20); Console.WriteLine("Browsing release-groups of '{0}'", name); var artist = artists.Items.OrderByDescending(a => Levenshtein.Similarity(a.Name, name)).First(); int limit = 50; // Browse the first 50 release-groups of given artist, include ratings. var groups = await client.ReleaseGroups.BrowseAsync("artist", artist.Id, limit, 0, "ratings"); Console.WriteLine(); Console.WriteLine("Album"); Console.WriteLine(); // Show official albums. foreach (var item in groups.Items.Where(g => IsOfficial(g)).OrderBy(g => g.FirstReleaseDate)) { Console.WriteLine(" {0} - {1} {2} {3}", item.FirstReleaseDate.ToShortDate(), item.Id, GetRating(item.Rating, 10), item.Title); } Console.WriteLine(); Console.WriteLine("Album + Compilation"); Console.WriteLine(); // Show compilations. foreach (var item in groups.Items.Where(g => IsCompilation(g)).OrderBy(g => g.FirstReleaseDate)) { Console.WriteLine(" {0} - {1} {2} {3}", item.FirstReleaseDate.ToShortDate(), item.Id, GetRating(item.Rating, 10), item.Title); } Console.WriteLine(); if (groups.Items.Count == limit) { Console.WriteLine("There are probably more items to browse ({0} release-groups total) ...", groups.Count); } Console.WriteLine(); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var entry = value as ILibraryEntry; if (entry != null) { try { return(MusicBrainzClient.Query(entry)); } catch (Exception) { return(value); } } return(value); }
public static async Task Search(MusicBrainzClient client, string band, string album) { // Search for an artist by name. var artists = await client.Artists.SearchAsync(band.Quote()); var artist = artists.Items.First(); // Build an advanced query to search for the release. var query = new QueryParameters <Release>() { { "arid", artist.Id }, { "release", album }, { "type", "album" }, { "status", "official" } }; // Search for a release by title. var releases = await client.Releases.SearchAsync(query); Console.WriteLine("Total matches for '{0}': {1}", album, releases.Count); // Get the oldest release (remember to sort out items with no date set). var release = releases.Items.Where(r => r.Date != null && IsCompactDisc(r)).OrderBy(r => r.Date).First(); // Get detailed information of the release, including recordings. release = await client.Releases.GetAsync(release.Id, "recordings", "url-rels"); Console.WriteLine(); Console.WriteLine("Details for {0} - {1} ({2})", artist.Name, release.Title, release.Date); Console.WriteLine(); // Get the medium associated with the release. var medium = release.Media.First(); foreach (var track in medium.Tracks) { // The song length. var length = TimeSpan.FromMilliseconds((int)track.Length); Console.WriteLine("{0,3} {1} ({2:m\\:ss})", track.Number, track.Recording.Title, length); } }
public ReleaseGroupService(MusicBrainzClient client, UrlBuilder builder) { this.client = client; this.builder = builder; }
public static async Task Run(MusicBrainzClient client) { await Search(client, "Massive Attack", "Mezzanine"); }
/// <summary> /// Gets meta data / tag information from the music file itself and looks up any missing data /// using a MusicBrainz API implementation (for instance album cover art). /// </summary> public MusicDataFetcher() { ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; MusicBrainzClient = new MusicBrainzClient(); }
public static async Task Run(MusicBrainzClient client) { await Browse(client, "Britney Spears"); }
public static async Task Run(MusicBrainzClient client) { await Search(client, "alternative rock", 10); }
public WorkService(MusicBrainzClient client, UrlBuilder builder) { this.client = client; this.builder = builder; }
public static async Task Run(MusicBrainzClient client) { await Search(client, "The Rolling Stones"); }
/// <summary> /// Initiate the actual request. /// </summary> protected virtual Task <T> BrowseAsync(MusicBrainzClient client, CancellationToken ct) { throw new NotImplementedException(); }
public RecordingService(MusicBrainzClient client, UrlBuilder builder) { this.client = client; this.builder = builder; }
public ReleaseBrowseRequest(MusicBrainzClient client, UrlBuilder builder, string id, string relatedEntity, string entity) : base(client, builder, id, relatedEntity, entity) { }