public async Task <ArtistInfo> GetArtistInfo(string name) { var artistInfo = new ArtistInfo(); _artistUri = new Uri(_client.BaseAddress, $"/{name}"); var response = await _client.GetStringAsync($"/{name}"); if (response.Contains("Not found")) { return(null); } var parser = new HtmlParser(); var document = parser.Parse(response); artistInfo.Name = document.QuerySelector(".profile-bar__image").GetAttribute("alt"); foreach (var playerTrackElement in document.QuerySelectorAll("#tracks-container > .player-track")) { var trackNameElement = playerTrackElement.QuerySelector(".player-track__name"); if (trackNameElement == null) { continue; } var bareTrackInfo = new BareTrackInfo(_client, _artistUri); bareTrackInfo.Name = trackNameElement.TextContent; bareTrackInfo.Id = playerTrackElement.GetAttribute("id").Replace("track", string.Empty); artistInfo.BareTrackInfos.Add(bareTrackInfo); } return(artistInfo); }
public List <ArtistInfo> GetShowsByArtist(string artistName) { var artists = from a in db.Shows from d in a.ShowDetails where d.Artist.ArtistName.Equals(artistName) select new { d.Artist.ArtistName, a.ShowName, a.ShowTime, a.ShowDate, a.ShowTicketInfo }; List <ArtistInfo> artistList = new List <ArtistInfo>(); foreach (var a in artists) { ArtistInfo aInfo = new ArtistInfo(); aInfo.ArtistName = a.ArtistName; aInfo.ShowName = a.ShowName; aInfo.ShowTime = a.ShowTime.ToString(); aInfo.ShowDate = a.ShowDate.ToShortDateString(); artistList.Add(aInfo); } return(artistList); }
public async Task Do_Nothing_If_ArtistInfoDescriptionClient_Returns_Null() { // Arrange var artistInfo = new ArtistInfo() { Relations = new List <ArtistInfoRelation>() { new ArtistInfoRelation() { Type = "wikipedia", Url = new ArtistInfoRelationUrl() { Id = Guid.NewGuid(), Resource = "resource" } } } }; artistInfoClient.Setup(x => x.GetAsync(It.IsAny <Guid>())).Returns(Task.FromResult(artistInfo)); artistDescriptionClient.Setup(x => x.GetAsync(It.IsAny <string>())).Returns(Task.FromResult <string>(null)); // Act var result = await target.GetArtistInfoAsync(Guid.NewGuid()); // Assert Assert.IsNotNull(result); }
private ArtistInfo GetInfo(string cid, string referer = null) { try { var jfa = JsonConvert.DeserializeObject <JsonData_Fanbox_Artist>(GetWebCode($"https://api.fanbox.cc/creator.get?creatorId={cid}", referer)); if (null != jfa.body) { var ai = new ArtistInfo() { Id = jfa.body.user.userId, Cid = cid, AName = GlobalMethord.RemoveLastDot(GlobalMethord.ReplacePath(jfa.body.user.name)), PostUrl = referer ?? _referer }; foreach (var link in jfa.body.profileLinks) { if (link.Contains("twitter.com")) { ai.Twitter = $"{link}/status"; break; } } return(ai); } return(null); } catch { throw; } }
/// <inheritdoc /> public async Task <ImvdbSearchResponse <ImvdbArtist>?> GetSearchResponseAsync(ArtistInfo searchInfo, CancellationToken cancellationToken) { var url = $"{BaseUrl}/search/entities?q={searchInfo.Name}"; return(await GetResponseAsync <ImvdbSearchResponse <ImvdbArtist> >(url, cancellationToken) .ConfigureAwait(false)); }
public ActionResult Save(ArtistInfo artistInfo) { _siteMetaData.ArtistInfo = artistInfo; _metadataRepostory.Save(_siteMetaData); return(RedirectToAction("About", "Home")); }
public void filterGenre(CS_GenreInfo g) { if (g == null) { _genre = null; Reload(); } else if (_genre == null) { _genre = g; _artist = null; _composer = null; Reload(); } else { if (_genre.Genre == g.Genre) { // do nothing } else { _genre = g; _artist = null; _composer = null; Reload(); } } }
public async override Task<ResultMessage> GetArtistInfo(string url) { try { string ss = await GetWebCode("view-source:" + url); Match ma = _cidRegex.Match(ss); if (ma.Success) { string _cid = ma.Groups[1].Value; ss = ChangeUnicode(await GetAPI(string.Format(_artistUrl, _cid))); var jpa = JsonConvert.DeserializeObject<JsonData_Patreon_Artist>(ss); if (null != jpa.data) { var ai = new ArtistInfo() { Id = _cid, Cid = _cid, AName = GlobalMethord.RemoveLastDot(GlobalMethord.ReplacePath(jpa.data.attributes.name)), PostUrl = url, PayLow = GlobalData.VM_MA.Artist.PayLow, PayHigh = GlobalData.VM_MA.Artist.PayHigh }; return ResultHelper.NoError(ai); } return ResultHelper.IOError(); } return ResultHelper.PathError(); } catch (Exception ex) { GlobalMethord.ErrorLog(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + "-----------------------------------------------"); return ResultHelper.UnKnownError(); } }
public async Task Add(ArtistInfo artist) { if (!await Exists(int.Parse(artist.Id))) { await _set.AddAsync(_mapper.Map <Artist>(artist)); } }
public void ToggleGrid() { ArtistInfo aa = MySource.getAlbumModel().filterArtist(); CS_GenreInfo gg = MySource.getAlbumModel().filterGenre(); string fa = ""; bool in_tracks = false; MySource.getAlbumModel().filterAlbumOrTracks(out fa, out in_tracks); string a = "@@allartist@@"; if (aa != null) { a = aa.Name; } string g = "@@allgenre@@"; if (gg != null) { g = gg.Genre; } string f = "@@searchfilter@@"; if (fa != null) { f = fa; } string id = a + "-" + g + "-" + f; ToggleGrid(id); }
// GET: api/Album public string Get(string artist, string album) { string svar = string.Empty; try { string bildQuery = "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=c5e414764357baf4097c59e86df16154&artist=" + artist + "&album=" + album; XmlDocument dokument = new XmlDocument(); dokument.Load(bildQuery); /**/ List <ArtistInfo> A = new List <ArtistInfo>(); ArtistInfo a = new ArtistInfo(); a.artist = artist; a.artistBild = dokument.GetElementsByTagName("image")[3].InnerText; string b64 = img64.ConvertImageURLToBase64(a.artistBild); a.bild64 = b64; a.InfoArtist = dokument.GetElementsByTagName("content")[0].InnerText; A.Add(a); string sJson = JsonConvert.SerializeObject(A, Newtonsoft.Json.Formatting.Indented); return(sJson); } catch (Exception ex) { return("FEL"); } }
public static string GetMusicBrainzArtistId(this ArtistInfo info) { string id; info.ProviderIds.TryGetValue(MetadataProviders.MusicBrainzArtist.ToString(), out id); return(id); }
public ArtistInfo FetchInformation(string artistName) { ArtistInfo result = null; string url = BuildUrl(artistName); result = FetchDataFromWebsite(url); return(result); }
private IHttpActionResult RetrieveArtistInfo(string artist) { var artistInfo = ArtistInfo.FromRepositoryObject(repository.FindArtistInfo(artist)); if (!string.IsNullOrWhiteSpace(artistInfo.Name)) { return(Ok(artistInfo)); } return(NotFound()); }
public void FromRepositoryObject() { var lastfmArtistInfo = TestArtistInfo.Create(); var result = ArtistInfo.FromRepositoryObject(lastfmArtistInfo); Assert.That(result.Name, Is.EqualTo(lastfmArtistInfo.Name)); Assert.That(result.YearFormed, Is.EqualTo(lastfmArtistInfo.YearFormed)); Assert.That(result.PlaceFormed, Is.EqualTo(lastfmArtistInfo.PlaceFormed)); Assert.That(result.BioSummary, Is.EqualTo(lastfmArtistInfo.BioSummary)); }
/// <summary> /// Get the music brainz artist id. /// </summary> /// <param name="info">The artist info.</param> /// <returns>The artist id.</returns> public static string?GetMusicBrainzArtistId(this ArtistInfo info) { info.ProviderIds.TryGetValue(MetadataProvider.MusicBrainzArtist.ToString(), out var id); if (string.IsNullOrEmpty(id)) { return(info.SongInfos.Select(i => i.GetProviderId(MetadataProvider.MusicBrainzAlbumArtist)) .FirstOrDefault(i => !string.IsNullOrEmpty(i))); } return(id); }
public async Task <IHttpActionResult> GetArtistInfo(string id) { ArtistInfo info = await BuildArtistInfo(id); // Failed to find artist if (info == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Ok(info)); }
public void RavenTestArrayPatchingRemove() { using (GetNewServer()) using (var docStore = new DocumentStore { Url = "http://localhost:8079" }.Initialize()) { const string trackId = "tracks/3"; var artist295 = new ArtistInfo { Id = "artists/295", Name = "Bob Dylan" }; var artist296 = new ArtistInfo { Id = "artists/296", Name = "Roy Orbison" }; var track1 = new MultipleArtistTrack { Id = trackId, Name = "Handle With Care", Artists = new[] { artist295, artist296 } }; using (IDocumentSession session = docStore.OpenSession()) { session.Store(track1); session.SaveChanges(); } int removedPosition = 1; BatchResult[] result = docStore.DatabaseCommands.Batch(new[] { new PatchCommandData { Key = trackId, Patches = new[] { new PatchRequest { Type = PatchCommandType.Remove, Name = "Artists", Position = removedPosition //Value = RavenJToken.FromObject(artist296) } } }, }); using (IDocumentSession session = docStore.OpenSession()) { track1 = session.Load <MultipleArtistTrack>(trackId); } Assert.Equal(1, track1.Artists.Length); } }
public void EvtArtistActivated(object sender, RowActivatedArgs <ArtistInfo> args) { //Hyena.Log.Information("I'm here! "+sender+", "+args); ArtistInfo a = args.RowValue; if (MySource.getArtistModel().isNullArtist(a)) { a = null; } MySource.getAlbumModel().filterArtist(a); MySource.getComposerModel().filterArtist(a); SetGrid(); }
private List <ArtistInfo> GetArtistListFromWebCode(string free, int index = 1) { try { List <ArtistInfo> ais = new List <ArtistInfo>(); string sphtml = GetWebCode($"https://fantia.jp/mypage/users/plans?page={index}&type={free}free"); Match ma = _artIdName.Match(sphtml); while (ma.Success) { var cid = ma.Groups[1].Value; var ana = ma.Groups[2].Value; int ind = ana.IndexOf('('); if (ind != -1) { ana = ana.Substring(0, ind); } var ai = new ArtistInfo() { Id = cid, Cid = cid, AName = GlobalMethord.RemoveLastDot(GlobalMethord.ReplacePath(ana)), PostUrl = $"https://fantia.jp/fanclubs/{cid}", PayHigh = "0" }; ais.Add(ai); ma = ma.NextMatch(); } if (!string.IsNullOrEmpty(free)) { ma = _artPlan.Match(sphtml); int i = 0; while (ma.Success) { ais[i++].PayHigh = ma.Groups[1].Value.Replace(",", ""); ma = ma.NextMatch(); } } if (sphtml.IndexOf(_nextP) != -1) { index++; ais.AddRange(GetArtistListFromWebCode(free, index)); } return(ais); } catch { throw; } }
private void Lst_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0) { ArtistInfo ai = (ArtistInfo)e.AddedItems[0]; if (_selectF) { SetLastDate(ai.Id); } else { _selectF = true; } } }
public async Task <List <ItemCount> > GetSongPlayedAndOtherPlayed(AggregateTimeRange timeRange, int artistWorkId) { List <ItemCount> result = new List <ItemCount>(); string localStorageKey = LOCALSTORAGEKEY_ARTISTARTISTWORKSPLAYEDANDOTHERS + artistWorkId + "-" + timeRange; TimeCachedObject <List <ItemCount> > cachedObject = await _localStorageService.GetItemAsync <TimeCachedObject <List <ItemCount> > >(localStorageKey); if (cachedObject == null || cachedObject.NextUpdateHour < DateTimeOffset.UtcNow) { ArtistInfo info = (await _radiocomArtistWorkRepository.GetArtistWorkAsync(artistWorkId)).ArtistInfo; List <ItemCount> works = await GetArtistSongsPlayed(timeRange, info.Id); long otherCount = works.Where(x => x.ItemId != artistWorkId).Sum(x => x.Count); ItemCount work = works.FirstOrDefault(x => x.ItemId == artistWorkId); if (work != null) { result.Add(work); } else { result.Add(new ItemCount() { Count = 0, ItemId = artistWorkId, Name = info.Name }); } result.Add(new ItemCount() { Count = otherCount, Name = "Other", ItemId = -1 }); DateTimeOffset nextUpdate = TimeCachedObject <object> .CalculateNextUpdateHour(); cachedObject = new TimeCachedObject <List <ItemCount> >() { CachedObject = result, NextUpdateHour = nextUpdate }; await _localStorageService.SetItemAsync(localStorageKey, cachedObject); } else { result = cachedObject.CachedObject; } return(result); }
public override long UpdateArtist(ArtistInfo artist) { var sqlParam = new DynamicParameters(); sqlParam.Add("@ID", artist.ID); sqlParam.Add("@Email", artist.Email); sqlParam.Add("@Name", artist.Name); sqlParam.Add("@Token", artist.Token); sqlParam.Add("@Updated", artist.Updated); using (IDbConnection connection = NewDataConnection) { connection.Execute("[dbo].[ArtistUpdate]", sqlParam, null, null, CommandType.StoredProcedure); } return(artist.ID); }
private async void bGetTracks_Click(object sender, EventArgs e) { _artistInfo = await _provider.GetArtistInfo(textBox1.Text); if (_artistInfo == null) { Debug.WriteLine("Not found"); return; } Text = _artistInfo.Name; foreach (var bareTrackInfo in _artistInfo.BareTrackInfos) { clbTracks.Items.Add(bareTrackInfo); } }
public static ArtistInfo ParseArtistPage(string link, string bandName) { /* Get main info from artist page. * * * Input: SetlistInfo object of one artist. * * Output: ArtistInfo object * (see info in ArtistInfo.cs) */ List <string> songs = new List <string>(); Dictionary <string, string> tours = new Dictionary <string, string>(); List <string> albums = new List <string>(); string albumsLink = ""; HtmlWeb webDoc = new HtmlWeb(); HtmlDocument doc = webDoc.Load("https://www.setlist.fm/" + link); HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//a"); foreach (var tag in nodes) { if (tag.Attributes.Contains("class") && tag.Attributes["class"].Value == "songName" && !songs.Contains(tag.InnerText)) { var name = clean(tag.InnerText.Trim()); songs.Add(name); } if (tag.Attributes.Contains("title") && tag.Attributes["title"].Value.StartsWith("Show song statistics of the tour", StringComparison.Ordinal)) { var name = clean(tag.InnerText.Trim()); tours.Add(tag.Attributes["href"].Value.Replace("../", ""), name); } if (tag.Attributes.Contains("title") && tag.Attributes["title"].Value.EndsWith("albums", StringComparison.Ordinal)) { albumsLink = tag.Attributes["href"].Value.Replace("../", ""); } } albums = ParseAlbumPage(albumsLink); ArtistInfo artist = new ArtistInfo(bandName, songs, tours, albums); return(artist); }
public void RavenTestArrayPatchingRemove() { using(GetNewServer()) using (var docStore = new DocumentStore{Url = "http://localhost:8079"}.Initialize()) { const string trackId = "tracks/3"; var artist295 = new ArtistInfo {Id = "artists/295", Name = "Bob Dylan"}; var artist296 = new ArtistInfo {Id = "artists/296", Name = "Roy Orbison"}; var track1 = new MultipleArtistTrack {Id = trackId, Name = "Handle With Care", Artists = new[] {artist295, artist296}}; using (IDocumentSession session = docStore.OpenSession()) { session.Store(track1); session.SaveChanges(); } int removedPosition = 1; BatchResult[] result = docStore.DatabaseCommands.Batch(new[] { new PatchCommandData { Key = trackId, Patches = new[] { new PatchRequest { Type = PatchCommandType.Remove, Name = "Artists", Position = removedPosition //Value = RavenJToken.FromObject(artist296) } } }, }); using (IDocumentSession session = docStore.OpenSession()) { track1 = session.Load<MultipleArtistTrack>(trackId); } Assert.Equal(1, track1.Artists.Length); } }
private string GetArtistsMbid(ArtistInfo artistInfo) { string musicBrainzID = null; var dbAlbumArtistInfo = artistInfo as DatabaseAlbumArtistInfo; if (dbAlbumArtistInfo != null) { musicBrainzID = FanArtMusicBrainz.MBIDByArtistID(dbAlbumArtistInfo.DbId); } if (musicBrainzID == null) { musicBrainzID = FanArtMusicBrainz.MBIDByArtistName(artistInfo.Name); } return(musicBrainzID); }
public async override Task <ResultMessage> GetArtistList() { try { string ss = ChangeUnicode(await GetAPI(_pledgeUrl)); var jpp = JsonConvert.DeserializeObject <JsonData_Patreon_Pledge>(ss); if (null != jpp.data && null != jpp.included) { List <ArtistInfo> ais = new List <ArtistInfo>(); var tais = GlobalData.VM_MA.ArtistList.ToList(); if (tais.Count == 0) { tais.Add(new ArtistInfo()); } var incll = jpp.included.ToList(); for (int i = 0; i < jpp.data.Length; i++) { var inclu = incll.Find(x => x.id == jpp.data[i].relationships.campaign.data.id); var ai = new ArtistInfo() { Id = inclu.id, Cid = inclu.id, AName = GlobalMethord.RemoveLastDot(GlobalMethord.ReplacePath(inclu.attributes.name)), PostUrl = inclu.attributes.url, PayHigh = jpp.data[i].attributes.amount_cents.ToString() }; tais.Remove(ai); ais.Add(ai); } ais.AddRange(tais); return(ResultHelper.NoError(ais)); } if (ss == "{\"data\":[]}") { return(ResultHelper.NoError(new List <ArtistInfo>())); } return(ResultHelper.IOError()); } catch (Exception ex) { GlobalMethord.ErrorLog(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + "-----------------------------------------------"); return(ResultHelper.UnKnownError()); } }
public async Task <IEnumerable <IArtistInfo> > GetArtistInfosAsync(IEnumerable <int> ids) { List <IArtistInfo> result = new List <IArtistInfo>(); using IDbConnection conn = await _dbConnectionFactory.GetConnection(_sqlRadiocomArtistInfoRepositoryOptions.ConnectionString); foreach (int id in ids) { DynamicParameters dynamicParameters = new DynamicParameters(); dynamicParameters.Add("ArtistId", id, DbType.Int32); ArtistInfo artistInfo = conn.QuerySingleOrDefault <ArtistInfo>("SELECT * FROM dbo.Artist WHERE Id = @ArtistId;", dynamicParameters); if (artistInfo != null) { result.Add(artistInfo); } } return(result); }
public void SetGrid() { ArtistInfo aa = MySource.getAlbumModel().filterArtist(); CS_GenreInfo gg = MySource.getAlbumModel().filterGenre(); string fa = ""; bool in_tracks = false; MySource.getAlbumModel().filterAlbumOrTracks(out fa, out in_tracks); string a = "@@allartist@@"; if (aa != null) { a = aa.Name; } string g = "@@allgenre@@"; if (gg != null) { g = gg.Genre; } string f = "@@searchfilter@@"; if (fa != null) { f = fa; } string id = a + "-" + g + "-" + f; Hyena.Log.Information("SetGrid for id " + id); bool grid = MySource.getGridLayout(id); Hyena.Log.Information("Grid = " + grid); if (grid) { aview.EnableGrid(); } else { aview.DisableGrid(); } }
public static void OneSetlistInfo(string path) { SetlistInfo check = ParseSetlistPage(Globals.MainPageInfo[0].link, Globals.MainPageInfo[0].bandName); ArtistInfo artist = ParseArtistPage(check); string str = $"Artist name: {artist.bandName}\n\n"; str += "------------------------------"; str += "All songs\n"; foreach (var song in artist.songs) { str += song; str += "\n"; } str += "------------------------------"; str += "Tours\n"; foreach (KeyValuePair <string, List <string> > keyValue in artist.tours) { str += keyValue.Key; str += "\n"; foreach (var song in keyValue.Value) { str += $" {song}\n"; } str += "\n"; } str += "------------------------------"; str += "Albums\n"; foreach (var album in artist.albums) { str += album; str += "\n"; } str += "------------------------------"; str += "Setlist songs\n"; foreach (var song in check.songs) { str += song; str += "\n"; } File.WriteAllText(path, str); }
protected void UpdateSong(object sender, EventArgs e) { SqlDataReader sqlReader; int albumId; SONG_ID = Request.Params["SongId"]; mydb.newQuery("SELECT [Album].[album_id] FROM [Album] WHERE [Album].[album] like @album"); mydb.setParameter("album", album_box.Text.Trim()); sqlReader = mydb.ExecuteReader(); if (sqlReader.HasRows == true) { sqlReader.Read(); albumId = int.Parse(sqlReader["album_id"].ToString().Trim()); } else { mydb.newQuery("INSERT INTO [Album] (album) VALUES (@album)"); mydb.setParameter("album", album_box.Text.Trim()); mydb.ExecuteNonQuery(); albumId = mydb.GetLastInsertId(); } mydb.newQuery("UPDATE [Song] SET [Song].[song_name] = @songname , [Song].[artists] = @artist , [Song].[album] = @album , [Song].[album_id] = @albumid , [Song].[year] = @year , [Song].[genres] = @genres , [Song].[lyrics] = @lyrics WHERE [Song].[song_id] = @songid "); mydb.setParameter("songid", SONG_ID.Trim()); mydb.setParameter("songname", song_name_box.Text.Trim()); mydb.setParameter("artist", artists_box.Text.Trim()); mydb.setParameter("album", album_box.Text.Trim()); mydb.setParameter("albumid", albumId); mydb.setParameter("year", year_box.Text.Trim()); mydb.setParameter("genres", genres_box.Text.Trim()); mydb.setParameter("lyrics", lyrics_box.Text.Trim()); mydb.ExecuteNonQuery(); int songId = int.Parse(SONG_ID.Trim()); mydb.newQuery("DELETE FROM [HasGenre] WHERE [HasGenre].[song_id] = @id"); mydb.setParameter("id", SONG_ID.Trim()); mydb.ExecuteNonQuery(); String[] genres_words = genres_box.Text.Split(','); int[] genres_ids = new int[genres_words.Length]; int i = 0; while (i < genres_words.Length) { mydb.newQuery("SELECT [Genre].[genre_id] FROM [Genre] WHERE [Genre].[genre_name] like @gen"); mydb.setParameter("gen", genres_words[i].Trim()); sqlReader = mydb.ExecuteReader(); if (sqlReader.HasRows == true) { sqlReader.Read(); int genreid = int.Parse(sqlReader["genre_id"].ToString().Trim()); genres_ids[i] = genreid; //mydb.newQuery("SELECT * FROM [HasGenre] WHERE [HasGenre].[song_id] = @songid and [HasGenre].[genre_id] = @genid "); //mydb.setParameter("songid", songId); //mydb.setParameter("genid", genreid); //sqlReader = mydb.ExecuteReader(); //if (sqlReader.HasRows == false) //{ mydb.newQuery("INSERT INTO [HasGenre] (song_id,genre_id) VALUES (@songid,@genid)"); mydb.setParameter("songid", songId); mydb.setParameter("genid", genreid); mydb.ExecuteNonQuery(); //} } else { mydb.newQuery("INSERT INTO [Genre] (genre_name) VALUES (@gen)"); mydb.setParameter("gen", genres_words[i].Trim()); mydb.ExecuteNonQuery(); //aici trebuie facut altceva pentru a lua ultimul id ca e dubios asa int genreId = mydb.GetLastInsertId(); genres_ids[i] = genreId; mydb.newQuery("INSERT INTO [HasGenre] (song_id,genre_id) VALUES (@songid,@genid)"); mydb.setParameter("songid", songId); mydb.setParameter("genid", genreId); mydb.ExecuteNonQuery(); } i++; } mydb.newQuery("DELETE FROM [Sings] WHERE [Sings].[song_id] = @id"); mydb.setParameter("id", SONG_ID.Trim()); mydb.ExecuteNonQuery(); String[] artists_words = artists_box.Text.Split(','); int[] artists_ids = new int[artists_words.Length]; i = 0; while (i < artists_words.Length) { mydb.newQuery("SELECT [Artist].[artist_id] FROM [Artist] WHERE [Artist].[artist_name] like @art"); mydb.setParameter("art", artists_words[i].Trim()); sqlReader = mydb.ExecuteReader(); if (sqlReader.HasRows == true) { sqlReader.Read(); int artiid = int.Parse(sqlReader["artist_id"].ToString().Trim()); artists_ids[i] = artiid; //mydb.newQuery("SELECT * FROM [Sings] WHERE [Sings].[song_id] = @songid and [Sings].[artist_id] = @artid "); //mydb.setParameter("songid", songId); //mydb.setParameter("artid", artiid); //sqlReader = mydb.ExecuteReader(); //if (sqlReader.HasRows == false) //{ mydb.newQuery("INSERT INTO [Sings] (song_id,artist_id) VALUES (@songid,@artid)"); mydb.setParameter("songid", songId); mydb.setParameter("artid", artiid); mydb.ExecuteNonQuery(); //} } else { string artistName = artists_words[i].Trim(); mydb.newQuery("INSERT INTO [Artist] (artist_name) VALUES (@art)"); mydb.setParameter("art", artistName); mydb.ExecuteNonQuery(); //aici trebuie facut altceva pentru a lua ultimul id ca e dubios asa int artistId = mydb.GetLastInsertId(); artists_ids[i] = artistId; // modulul de sugestii calculeaza similaritatile pentru noul artist ArtistInfo NewArtist = new ArtistInfo(artistId, artistName); List<ArtistInfo> prevArtists = SimilarityGraph.GetArtists(mydb, artistId); SimilarityGraph.CalculateSimilarities(mydb, NewArtist, false, prevArtists); mydb.newQuery("INSERT INTO [Sings] (song_id,artist_id) VALUES (@songid,@artid)"); mydb.setParameter("songid", songId); mydb.setParameter("artid", artistId); mydb.ExecuteNonQuery(); } i++; } List<int> genre_ids = new List<int>(); mydb.newQuery("SELECT [HasGenre].[genre_id] FROM [HasGenre] WHERE [HasGenre].[song_id] = @id"); mydb.setParameter("id", SONG_ID.Trim()); sqlReader = mydb.ExecuteReader(); while (sqlReader.Read()) { genre_ids.Add(int.Parse(sqlReader["genre_id"].ToString().Trim())); } i = 0; while (i < genre_ids.Count) { mydb.newQuery("SELECT [ArtistsGenres].[songs_count] FROM [ArtistsGenres] WHERE [ArtistsGenres].[genre_id] = @genid"); mydb.setParameter("genid", genre_ids[i]); sqlReader = mydb.ExecuteReader(); if (sqlReader.HasRows == true) { sqlReader.Read(); int songcount = int.Parse(sqlReader["songs_count"].ToString().Trim()); songcount--; mydb.newQuery("UPDATE [ArtistsGenres] SET [ArtistsGenres].[songs_count]=@songcount WHERE [ArtistsGenres].[genre_id] = @gen_id "); mydb.setParameter("gen_id", genre_ids[i]); mydb.setParameter("songcount", songcount); mydb.ExecuteNonQuery(); } i++; } int j = 0; i = 0; while (i < artists_ids.Length) { while (j < genres_ids.Length) { mydb.newQuery("SELECT [ArtistsGenres].[songs_count] FROM [ArtistsGenres] WHERE [ArtistsGenres].[artist_id] = @art_id and [ArtistsGenres].[genre_id] = @gen_id "); mydb.setParameter("art_id", artists_ids[i]); mydb.setParameter("gen_id", genres_ids[j]); sqlReader = mydb.ExecuteReader(); if (sqlReader.HasRows == true) { sqlReader.Read(); int songcount = int.Parse(sqlReader["songs_count"].ToString().Trim()); songcount++; mydb.newQuery("UPDATE [ArtistsGenres] SET [ArtistsGenres].[songs_count]=@songcount WHERE [ArtistsGenres].[artist_id] = @art_id and [ArtistsGenres].[genre_id] = @gen_id "); mydb.setParameter("art_id", artists_ids[i]); mydb.setParameter("gen_id", genres_ids[j]); mydb.setParameter("songcount", songcount); mydb.ExecuteNonQuery(); } else { mydb.newQuery("INSERT INTO [ArtistsGenres] (artist_id,genre_id,songs_count) VALUES (@art_id,@gen_id,1)"); mydb.setParameter("art_id", artists_ids[i]); mydb.setParameter("gen_id", genres_ids[j]); mydb.ExecuteNonQuery(); } j++; } i++; j = 0; } mydb.newQuery("DELETE FROM [ArtistsGenres] WHERE [ArtistsGenres].[songs_count] = 0 "); mydb.ExecuteNonQuery(); //mydb.newQuery("DELETE FROM [Genre] WHERE 0 = (SELECT COUNT (*) FROM [HasGenre] WHERE [HasGenre].[genre_id] = [Genre].[genre_id]) "); //mydb.ExecuteNonQuery(); Response.Redirect("UploadSong.aspx"); }
/// <summary> /// Set the Artist information, override existing information /// </summary> /// <param name="mv"></param> /// <param name="artistInfo"></param> private void SetMusicVideoArtist(ref DBArtistInfo mv, ArtistInfo artistInfo, string strArtistHTML) { // Now fill in the data mv.Formed = mvCentralUtils.StripHTML(artistInfo.Formed); mv.Disbanded = mvCentralUtils.StripHTML(artistInfo.Disbanded); mv.Born = mvCentralUtils.StripHTML(artistInfo.Born); mv.Death = mvCentralUtils.StripHTML(artistInfo.Death); mv.bioSummary = getBioSummary(artistInfo.AMGBio, 50); mv.bioContent = artistInfo.AMGBio; mv.Genre = artistInfo.Genres; mv.Tones = artistInfo.Tones; mv.Styles = artistInfo.Styles; mv.YearsActive = artistInfo.YearsActive; }
/// <summary> /// Update missing Artist information /// </summary> /// <param name="mv"></param> /// <param name="artistInfo"></param> private void UpdateMusicVideoArtist(ref DBArtistInfo mv, ArtistInfo artistInfo, string strArtistHTML) { if (mv.Formed.Trim() == string.Empty) mv.Formed = mvCentralUtils.StripHTML(artistInfo.Formed); if (mv.Disbanded.Trim() == string.Empty) mv.Disbanded = mvCentralUtils.StripHTML(artistInfo.Disbanded); if (mv.Born.Trim() == string.Empty) mv.Born = mvCentralUtils.StripHTML(artistInfo.Born); if (mv.Death.Trim() == string.Empty) mv.Death = mvCentralUtils.StripHTML(artistInfo.Death); if (mv.bioSummary.Trim() == string.Empty) mv.bioSummary = getBioSummary(artistInfo.AMGBio, 50); if (mv.bioContent.Trim() == string.Empty) mv.bioContent = artistInfo.AMGBio; if (mv.Genre.Trim() == string.Empty) mv.Genre = artistInfo.Genres; if (mv.Tones.Trim() == string.Empty) mv.Tones = artistInfo.Tones; if (mv.Styles.Trim() == string.Empty) mv.Styles = artistInfo.Styles; if (mv.YearsActive.Trim() == string.Empty) mv.YearsActive = artistInfo.YearsActive; }
protected void InsertSong(object sender, EventArgs e) { if(Context.Session["is_uploader"].Equals("True")){ if (inputSong.HasFile && inputSong.FileName.EndsWith(".mp3", true, null)) { SqlDataReader sqlReader; int albumId; mydb.newQuery("SELECT [Album].[album_id] FROM [Album] WHERE [Album].[album] like @album"); mydb.setParameter("album", album_box.Text.Trim()); sqlReader = mydb.ExecuteReader(); if (sqlReader.HasRows == true) { sqlReader.Read(); albumId = int.Parse(sqlReader["album_id"].ToString().Trim()); } else { mydb.newQuery("INSERT INTO [Album] (album) VALUES (@album)"); mydb.setParameter("album", album_box.Text.Trim()); mydb.ExecuteNonQuery(); albumId = mydb.GetLastInsertId(); } //AICI DOWNLOADEZ POZA DE ALBUM !!!! GetAlbumArt(albumId.ToString(), album_box.Text.Trim(), album_artist_field.Value); //AICI DOWNLOADEZ POZA DE ALBUM !!!! mydb.newQuery("INSERT INTO [Song] (song_name,artists,album,album_id,year,genres,lyrics,uploader_id) VALUES (@songname,@artist,@album,@albumid,@year,@genres,@lyrics,@uploader_id) "); mydb.setParameter("songname", song_name_box.Text.Trim()); mydb.setParameter("artist", artists_box.Text.Trim()); mydb.setParameter("album", album_box.Text.Trim()); mydb.setParameter("albumid", albumId); mydb.setParameter("year", year_box.Text.Trim()); mydb.setParameter("genres", genres_box.Text.Trim()); mydb.setParameter("lyrics", lyrics_box.Text.Trim()); //added by bitza (to remove unauthorised uploads) mydb.setParameter("uploader_id", Context.Session["user_id"].ToString()); mydb.ExecuteNonQuery(); //mydb.newQuery("SELECT [Song].[song_id] FROM [Song] WHERE [Song].[song_name] like @songname and [Song].[artist] like @artist and [Song].[album] like @album "); //mydb.setParameter("songname", context.Request.Params["SongName"].ToString()); //mydb.setParameter("artist", context.Request.Params["Artists"].ToString()); //mydb.setParameter("album", context.Request.Params["Album"].ToString()); //sqlReader = mydb.ExecuteReader(); //var songId = sqlReader.Read(); int songId = mydb.GetLastInsertId(); SONG_ID = songId.ToString(); String[] genres_words = genres_box.Text.Split(','); int[] genres_ids = new int[genres_words.Length]; int i = 0; while (i < genres_words.Length) { mydb.newQuery("SELECT [Genre].[genre_id] FROM [Genre] WHERE [Genre].[genre_name] like @gen"); mydb.setParameter("gen", genres_words[i].Trim()); sqlReader = mydb.ExecuteReader(); if (sqlReader.HasRows == true) { sqlReader.Read(); int genreid = int.Parse(sqlReader["genre_id"].ToString().Trim()); genres_ids[i] = genreid; mydb.newQuery("INSERT INTO [HasGenre] (song_id,genre_id) VALUES (@songid,@genid)"); mydb.setParameter("songid", songId); mydb.setParameter("genid", genreid); mydb.ExecuteNonQuery(); } else { mydb.newQuery("INSERT INTO [Genre] (genre_name) VALUES (@gen)"); mydb.setParameter("gen", genres_words[i].Trim()); mydb.ExecuteNonQuery(); //aici trebuie facut altceva pentru a lua ultimul id ca e dubios asa int genreId = mydb.GetLastInsertId(); genres_ids[i] = genreId; mydb.newQuery("INSERT INTO [HasGenre] (song_id,genre_id) VALUES (@songid,@genid)"); mydb.setParameter("songid", songId); mydb.setParameter("genid", genreId); mydb.ExecuteNonQuery(); } i++; } String[] artists_words = artists_box.Text.Split(','); int[] artists_ids = new int[artists_words.Length]; i = 0; while (i < artists_words.Length) { mydb.newQuery("SELECT [Artist].[artist_id] FROM [Artist] WHERE [Artist].[artist_name] like @art"); mydb.setParameter("art", artists_words[i].Trim()); sqlReader = mydb.ExecuteReader(); if (sqlReader.HasRows == true) { sqlReader.Read(); int artiid = int.Parse(sqlReader["artist_id"].ToString().Trim()); artists_ids[i] = artiid; mydb.newQuery("INSERT INTO [Sings] (song_id,artist_id) VALUES (@songid,@artid)"); mydb.setParameter("songid", songId); mydb.setParameter("artid", artiid); mydb.ExecuteNonQuery(); } else { string artistName = artists_words[i].Trim(); mydb.newQuery("INSERT INTO [Artist] (artist_name) VALUES (@art)"); mydb.setParameter("art", artistName); mydb.ExecuteNonQuery(); //aici trebuie facut altceva pentru a lua ultimul id ca e dubios asa int artistId = mydb.GetLastInsertId(); artists_ids[i] = artistId; // modulul de sugestii calculeaza similaritatile pentru noul artist ArtistInfo NewArtist = new ArtistInfo(artistId, artistName); List<ArtistInfo> prevArtists = SimilarityGraph.GetArtists(mydb, artistId); SimilarityGraph.CalculateSimilarities(mydb, NewArtist, false, prevArtists); mydb.newQuery("INSERT INTO [Sings] (song_id,artist_id) VALUES (@songid,@artid)"); mydb.setParameter("songid", songId); mydb.setParameter("artid", artistId); mydb.ExecuteNonQuery(); } i++; } int j = 0; i = 0; while (i < artists_ids.Length) { while (j < genres_ids.Length) { mydb.newQuery("SELECT [ArtistsGenres].[songs_count] FROM [ArtistsGenres] WHERE [ArtistsGenres].[artist_id] = @art_id and [ArtistsGenres].[genre_id] = @gen_id "); mydb.setParameter("art_id", artists_ids[i]); mydb.setParameter("gen_id", genres_ids[j]); sqlReader = mydb.ExecuteReader(); if (sqlReader.HasRows == true) { sqlReader.Read(); int songcount = int.Parse(sqlReader["songs_count"].ToString()); songcount++; mydb.newQuery("UPDATE [ArtistsGenres] SET [ArtistsGenres].[songs_count]=@songcount WHERE [ArtistsGenres].[artist_id] = @art_id and [ArtistsGenres].[genre_id] = @gen_id "); mydb.setParameter("art_id", artists_ids[i]); mydb.setParameter("gen_id", genres_ids[j]); mydb.setParameter("songcount", songcount); mydb.ExecuteNonQuery(); } else { mydb.newQuery("INSERT INTO [ArtistsGenres] (artist_id,genre_id,songs_count) VALUES (@art_id,@gen_id,1)"); mydb.setParameter("art_id", artists_ids[i]); mydb.setParameter("gen_id", genres_ids[j]); mydb.ExecuteNonQuery(); } j++; } i++; j = 0; } // Response.Redirect("UploadSong.aspx?SongId="+SONG_ID+"&do_function=upload"); UploadSongOnServer(sender, e); } else { FileValidation.Text = "Select an mp3 file!"; } } else { FileValidation.Text = "You have no upload rights!"; } }
public async Task Returns_ArtistInfo_With_Description_And_AlbumCoverArtUrls() { // Arrange Guid artistGuid = Guid.NewGuid(); Guid album1Id = Guid.NewGuid(); Guid album2Id = Guid.NewGuid(); string artistDescriptionUrl = "descriptionUrl"; ArtistInfo artistInfo = new ArtistInfo() { Id = artistGuid, Description = string.Empty, Relations = new List<ArtistInfoRelation>() { new ArtistInfoRelation() { Type = "wikipedia", Url = new ArtistInfoRelationUrl() { Id = Guid.NewGuid(), Resource = artistDescriptionUrl } } }, ReleaseGroups = new List<ArtistInfoReleaseGroup>() { new ArtistInfoReleaseGroup() { Id = album1Id, CovertArtUrl = string.Empty, PrimaryType = "Album", Title = "Album1" }, new ArtistInfoReleaseGroup() { Id = album2Id, CovertArtUrl = string.Empty, PrimaryType = "Album", Title = "Album2" } } }; artistInfoClient.Setup(x => x.GetAsync(It.Is<Guid>(y => y == artistGuid))) .Returns(Task.FromResult(artistInfo)); artistDescriptionClient.Setup(x => x.GetAsync(It.Is<string>(y => y == artistDescriptionUrl))) .Returns(Task.FromResult("artistDescription")); albumCoverArtClient.Setup(x => x.GetAsync(It.Is<Guid>(y => y == album1Id))) .Returns(Task.FromResult("album1CoverUrl")); albumCoverArtClient.Setup(x => x.GetAsync(It.Is<Guid>(y => y == album2Id))) .Returns(Task.FromResult("album2CoverUrl")); // Act var result = await target.GetArtistInfoAsync(artistGuid); // Assert Assert.IsNotNull(result); Assert.AreEqual(result.Description, "artistDescription"); Assert.AreEqual(2, result.ReleaseGroups.Count()); Assert.IsTrue(result.ReleaseGroups.Any(x => x.CovertArtUrl == "album1CoverUrl")); Assert.IsTrue(result.ReleaseGroups.Any(x => x.CovertArtUrl == "album2CoverUrl")); }
public async Task Do_Nothin_If_AlbumCoverArtClient_Returns_Null() { // Arrange var artistInfo = new ArtistInfo() { ReleaseGroups = new List<ArtistInfoReleaseGroup>() { new ArtistInfoReleaseGroup() { Id = Guid.NewGuid() } } }; artistInfoClient.Setup(x => x.GetAsync(It.IsAny<Guid>())).Returns(Task.FromResult(artistInfo)); artistDescriptionClient.Setup(x => x.GetAsync(It.IsAny<string>())).Returns(Task.FromResult("Description")); albumCoverArtClient.Setup(x => x.GetAsync(It.IsAny<Guid>())).Returns(Task.FromResult<string>(null)); // Act var result = await target.GetArtistInfoAsync(Guid.NewGuid()); // Assert Assert.IsNotNull(result); }
public async Task Do_Nothing_If_ArtistInfoDescriptionClient_Returns_Null() { // Arrange var artistInfo = new ArtistInfo() { Relations = new List<ArtistInfoRelation>() { new ArtistInfoRelation() { Type = "wikipedia", Url = new ArtistInfoRelationUrl() { Id = Guid.NewGuid(), Resource = "resource" } } } }; artistInfoClient.Setup(x => x.GetAsync(It.IsAny<Guid>())).Returns(Task.FromResult(artistInfo)); artistDescriptionClient.Setup(x => x.GetAsync(It.IsAny<string>())).Returns(Task.FromResult<string>(null)); // Act var result = await target.GetArtistInfoAsync(Guid.NewGuid()); // Assert Assert.IsNotNull(result); }
public static Dictionary<int, double> CalculateSimilarities(MyDatabase mydb, ArtistInfo Artist, bool batchMode = false, List<ArtistInfo> prevArtists = null) { if (!batchMode) { mydb.newQuery("DELETE FROM ArtistSimilarity WHERE artist1_id=@artist_id OR artist2_id=@artist_id"); mydb.setParameter("artist_id", Artist.ArtistId); mydb.ExecuteNonQuery(); } Dictionary<String, int> similarArtists = new Dictionary<string, int>(); GetEchonestData(similarArtists, Artist.ArtistName); GetLastFMData(similarArtists, Artist.ArtistName); GetYahooData(similarArtists, Artist.ArtistName); if (!batchMode) prevArtists = GetArtists(mydb, Artist.ArtistId); Dictionary<int, double> similarityNumerator = new Dictionary<int, double>(); Dictionary<int, double> similarityDenominator = new Dictionary<int, double>(); Dictionary<int, double> similarity = new Dictionary<int, double>(); for (int i = 0; i < prevArtists.Count; ++i) { similarityNumerator.Add(prevArtists[i].ArtistId, 0); similarityDenominator.Add(prevArtists[i].ArtistId, 0); if (!similarArtists.ContainsKey(prevArtists[i].ArtistName)) similarity.Add(prevArtists[i].ArtistId, 0); else similarity.Add(prevArtists[i].ArtistId, initialSimilarity(similarArtists[prevArtists[i].ArtistName])); } foreach (KeyValuePair<string, int> entry in similarArtists) { double weight = initialSimilarity(entry.Value); weight *= weight; mydb.newQuery("SELECT s.artist2_id, s.similarity FROM Artist a, ArtistSimilarity s" + " WHERE s.artist1_id = a.artist_id AND a.artist_name=@artist_name AND s.artist2_id!=@artist_id"); mydb.setParameter("artist_name", entry.Key); mydb.setParameter("artist_id", Artist.ArtistId); SqlDataReader reader = mydb.ExecuteReader(); while (reader.Read()) { int artistId = Int32.Parse(reader["artist2_id"].ToString()); double sim = Double.Parse(reader["similarity"].ToString()); similarityNumerator[artistId] += sim * weight; similarityDenominator[artistId] += weight; } } for (int i = 0; i < prevArtists.Count; ++i) { int id = prevArtists[i].ArtistId; similarity[id] += transitiveSimilarity(similarity[id], similarityNumerator[id], similarityDenominator[id]); } for (int i = 0; i < prevArtists.Count; ++i) { StoreSimilarity(mydb, Artist.ArtistId, prevArtists[i].ArtistId, similarity[prevArtists[i].ArtistId]); StoreSimilarity(mydb, prevArtists[i].ArtistId, Artist.ArtistId, similarity[prevArtists[i].ArtistId]); } StoreSimilarity(mydb, Artist.ArtistId, Artist.ArtistId, 1); return similarity; }