public void UpdatePersonalDescription(int songId, SongDetailsContract data) { PermissionContext.VerifyLogin(); HandleTransaction(ctx => { var song = ctx.Load(songId); EntryPermissionManager.VerifyAccess(PermissionContext, song, EntryPermissionManager.CanEditPersonalDescription); song.PersonalDescriptionText = data.PersonalDescriptionText; song.PersonalDescriptionAuthorId = data.PersonalDescriptionAuthor?.Id; ctx.Update(song); ctx.AuditLogger.AuditLog(string.Format("updated personal description for {0}", entryLinkFactory.CreateEntryLink(song))); }); }
private string GetNicoMimiUrl(SongDetailsContract contract) { // Don't show nicomimi link for free songs. if (contract.Tags.Any(t => t.TagName.Equals(Model.Domain.Tags.Tag.CommonTag_Free, StringComparison.InvariantCultureIgnoreCase) || t.TagName.Equals(Model.Domain.Tags.Tag.CommonTag_Nicovideo_downloadmusic, StringComparison.InvariantCultureIgnoreCase))) { return(string.Empty); } var nicoId = contract.Song.NicoId; var nicoPvId = PVHelper.GetNicoId(contract.PVs, nicoId); if (!string.IsNullOrEmpty(nicoPvId)) { return(string.Format("http://www.nicomimi.net/play/{0}", nicoPvId)); } else { return(string.Empty); } }
public SongDetailsContract GetSongDetails(int songId, int albumId, string hostname, ContentLanguagePreference?languagePreference, IEnumerable <OptionalCultureCode> userLanguages) { return(HandleQuery(session => { var lang = languagePreference ?? PermissionContext.LanguagePreference; var song = session.Load <Song>(songId); var contract = new SongDetailsContract(song, lang, GetSongPools(session, songId), config.SpecialTags); var user = PermissionContext.LoggedUser; if (user != null) { var rating = session.Query <FavoriteSongForUser>() .FirstOrDefault(s => s.Song.Id == songId && s.User.Id == user.Id); contract.UserRating = (rating != null ? rating.Rating : SongVoteRating.Nothing); } contract.CommentCount = Comments(session).GetCount(songId); contract.LatestComments = session.Query <SongComment>() .Where(c => c.EntryForComment.Id == songId) .OrderByDescending(c => c.Created).Take(3).ToArray() .Select(c => new CommentForApiContract(c, userIconFactory)).ToArray(); contract.Hits = session.Query <SongHit>().Count(h => h.Song.Id == songId); contract.ListCount = session.Query <SongInList>().Count(l => l.Song.Id == songId); contract.Suggestions = GetSongSuggestions(session, song).Select(s => new SongForApiContract(s, lang, SongOptionalFields.AdditionalNames | SongOptionalFields.ThumbUrl)).ToArray(); contract.PreferredLyrics = LyricsHelper.GetDefaultLyrics(contract.LyricsFromParents, new OptionalCultureCode(CultureInfo.CurrentUICulture, true), userLanguages, new Lazy <IEnumerable <UserKnownLanguage> >(() => session.OfType <User>().GetLoggedUserOrNull(permissionContext)?.KnownLanguages, false)); if (albumId != 0) { var album = session.Load <Album>(albumId); var track = album.Songs.FirstOrDefault(s => song.Equals(s.Song)); if (track != null) { contract.Album = new DataContracts.Albums.AlbumContract(album, lang); contract.AlbumSong = new SongInAlbumContract(track, lang, false); var previousIndex = album.PreviousTrackIndex(track.Index); var previous = album.Songs.FirstOrDefault(s => s.Index == previousIndex); contract.PreviousSong = previous != null && previous.Song != null ? new SongInAlbumContract(previous, lang, false) : null; var nextIndex = album.NextTrackIndex(track.Index); var next = album.Songs.FirstOrDefault(s => s.Index == nextIndex); contract.NextSong = next != null && next.Song != null ? new SongInAlbumContract(next, lang, false) : null; } } if (song.Deleted) { var mergeEntry = GetMergeRecord(session, songId); contract.MergedTo = (mergeEntry != null ? new SongContract(mergeEntry.Target, lang) : null); } AddSongHit(session, song, hostname); return contract; })); }
public SongDetails(SongDetailsContract contract, IUserPermissionContext userContext, PVHelper pvHelper) { ParamIs.NotNull(() => contract); Contract = contract; AdditionalNames = contract.AdditionalNames; Albums = contract.Albums; AlternateVersions = contract.AlternateVersions.Where(a => a.SongType != SongType.Original).ToArray(); ArtistString = contract.ArtistString; BrowsedAlbumId = contract.Album?.Id; CanEdit = EntryPermissionManager.CanEdit(userContext, contract.Song); CanEditPersonalDescription = contract.CanEditPersonalDescription; CanRemoveTagUsages = contract.CanRemoveTagUsages; CommentCount = contract.CommentCount; CreateDate = contract.CreateDate; DefaultLanguageSelection = contract.TranslatedName.DefaultLanguage; Deleted = contract.Deleted; Draft = contract.Song.Status == EntryStatus.Draft; FavoritedTimes = contract.Song.FavoritedTimes; Hits = contract.Hits; Id = contract.Song.Id; IsFavorited = contract.UserRating != SongVoteRating.Nothing; LatestComments = contract.LatestComments; Length = contract.Song.LengthSeconds; LikedTimes = contract.LikeCount; ListCount = contract.ListCount; Lyrics = contract.LyricsFromParents; MergedTo = contract.MergedTo; Name = contract.Song.Name; NicoId = contract.Song.NicoId; Notes = contract.Notes; OriginalVersion = (contract.Song.SongType != SongType.Original ? contract.OriginalVersion : null); Pools = contract.Pools; PublishDate = contract.Song.PublishDate; RatingScore = contract.Song.RatingScore; ReleaseEvent = contract.ReleaseEvent; PersonalDescriptionText = contract.PersonalDescriptionText; PersonalDescriptionAuthor = contract.PersonalDescriptionAuthor; SongType = contract.Song.SongType; SongTypeTag = contract.SongTypeTag; Status = contract.Song.Status; Suggestions = contract.Suggestions; Tags = contract.Tags; UserRating = contract.UserRating; WebLinks = contract.WebLinks.ToList(); ContentFocus = SongHelper.GetContentFocus(SongType); Animators = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Animator)).ToArray(); Bands = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Band)).ToArray(); Illustrators = ContentFocus == ContentFocus.Illustration ? contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Illustrator)).ToArray() : null; Performers = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Vocalist)).ToArray(); Producers = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Producer)).ToArray(); var subjectsForThis = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Subject)).ToArray(); Subject = subjectsForThis.Any() ? subjectsForThis : contract.SubjectsFromParents; OtherArtists = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Circle) || a.Categories.HasFlag(ArtistCategories.Label) || a.Categories.HasFlag(ArtistCategories.Other) || (ContentFocus != ContentFocus.Illustration && a.Categories.HasFlag(ArtistCategories.Illustrator))).ToArray(); var pvs = contract.PVs; OriginalPVs = pvs.Where(p => p.PVType == PVType.Original).ToArray(); OtherPVs = pvs.Where(p => p.PVType != PVType.Original).ToArray(); PrimaryPV = pvHelper.PrimaryPV(pvs); ThumbUrl = VideoServiceHelper.GetThumbUrlPreferNotNico(pvs); ThumbUrlMaxSize = VideoServiceHelper.GetMaxSizeThumbUrl(pvs) ?? ThumbUrl; if (PrimaryPV == null && !string.IsNullOrEmpty(NicoId)) { PrimaryPV = new PVContract { PVId = NicoId, Service = PVService.NicoNicoDouga } } ; if (pvs.All(p => p.Service != PVService.Youtube)) { var nicoPV = VideoServiceHelper.PrimaryPV(pvs, PVService.NicoNicoDouga); var query = HttpUtility.UrlEncode((nicoPV != null && !string.IsNullOrEmpty(nicoPV.Name)) ? nicoPV.Name : $"{ArtistString} {Name}"); WebLinks.Add(new WebLinkContract($"http://www.youtube.com/results?search_query={query}", ViewRes.Song.DetailsStrings.SearchYoutube, WebLinkCategory.Other, disabled: false)); } JsonModel = new SongDetailsAjax(this, contract.PreferredLyrics, contract.Song.Version); MinMilliBpm = contract.MinMilliBpm; MaxMilliBpm = contract.MaxMilliBpm; }
public void PostPersonalDescription(int id, SongDetailsContract data) { queries.UpdatePersonalDescription(id, data); }
public SongDetails(SongDetailsContract contract) { ParamIs.NotNull(() => contract); AdditionalNames = contract.AdditionalNames; Albums = contract.Albums; AlternateVersions = contract.AlternateVersions.Where(a => a.SongType != SongType.Original).ToArray(); ArtistString = contract.ArtistString; CanEdit = EntryPermissionManager.CanEdit(MvcApplication.LoginManager, contract.Song); CommentCount = contract.CommentCount; CreateDate = contract.CreateDate; Deleted = contract.Deleted; Draft = contract.Song.Status == EntryStatus.Draft; FavoritedTimes = contract.Song.FavoritedTimes; Hits = contract.Hits; Id = contract.Song.Id; IsFavorited = contract.UserRating != SongVoteRating.Nothing; LatestComments = contract.LatestComments; LikedTimes = contract.LikeCount; Lyrics = contract.LyricsFromParents; Name = contract.Song.Name; NicoId = contract.Song.NicoId; Notes = contract.Notes; OriginalVersion = (contract.Song.SongType != SongType.Original ? contract.OriginalVersion : null); Pools = contract.Pools; RatingScore = contract.Song.RatingScore; SongType = contract.Song.SongType; Status = contract.Song.Status; Tags = contract.Tags; UserRating = contract.UserRating; WebLinks = contract.WebLinks.ToList(); Animators = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Animator)).ToArray(); Performers = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Vocalist)).ToArray(); Producers = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Producer)).ToArray(); OtherArtists = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Circle) || a.Categories.HasFlag(ArtistCategories.Label) || a.Categories.HasFlag(ArtistCategories.Other)).ToArray(); var pvs = contract.PVs; OriginalPVs = pvs.Where(p => p.PVType == PVType.Original).ToArray(); OtherPVs = pvs.Where(p => p.PVType != PVType.Original).ToArray(); PrimaryPV = PVHelper.PrimaryPV(pvs); if (PrimaryPV == null && !string.IsNullOrEmpty(NicoId)) { PrimaryPV = new PVContract { PVId = NicoId, Service = PVService.NicoNicoDouga } } ; var nicoPvId = PVHelper.GetNicoId(pvs, NicoId); if (!string.IsNullOrEmpty(nicoPvId)) { WebLinks.Add(new WebLinkContract(VideoServiceUrlFactory.NicoSound.CreateUrl(nicoPvId), ViewRes.Song.DetailsStrings.CheckNicoSound, WebLinkCategory.Other)); } if (pvs.All(p => p.Service != PVService.Youtube)) { var nicoPV = VideoServiceHelper.PrimaryPV(pvs, PVService.NicoNicoDouga); var query = (nicoPV != null && !string.IsNullOrEmpty(nicoPV.Name)) ? nicoPV.Name : string.Format("{0} {1}", ArtistString, Name); WebLinks.Add(new WebLinkContract(string.Format("http://www.youtube.com/results?search_query={0}", query), ViewRes.Song.DetailsStrings.SearchYoutube, WebLinkCategory.Other)); } }
public SongDetailsContract GetSongDetails(int songId, int albumId, string hostname) { return(HandleQuery(session => { var song = session.Load <Song>(songId); var contract = new SongDetailsContract(song, PermissionContext.LanguagePreference); int agentNum = 0; var user = PermissionContext.LoggedUser; if (user != null) { var rating = session.Query <FavoriteSongForUser>() .FirstOrDefault(s => s.Song.Id == songId && s.User.Id == user.Id); contract.UserRating = (rating != null ? rating.Rating : SongVoteRating.Nothing); agentNum = user.Id; } else if (!string.IsNullOrEmpty(hostname)) { agentNum = hostname.GetHashCode(); } contract.CommentCount = session.Query <SongComment>().Count(c => c.Song.Id == songId); contract.LatestComments = session.Query <SongComment>() .Where(c => c.Song.Id == songId) .OrderByDescending(c => c.Created).Take(3).ToArray() .Select(c => new CommentContract(c)).ToArray(); contract.Hits = session.Query <SongHit>().Count(h => h.Song.Id == songId); if (albumId != 0) { var album = session.Load <Album>(albumId); var track = album.Songs.FirstOrDefault(s => song.Equals(s.Song)); if (track != null) { contract.AlbumId = albumId; var previousIndex = album.PreviousTrackIndex(track.Index); var previous = album.Songs.FirstOrDefault(s => s.Index == previousIndex); contract.PreviousSong = previous != null && previous.Song != null ? new SongInAlbumContract(previous, LanguagePreference, false) : null; var nextIndex = album.NextTrackIndex(track.Index); var next = album.Songs.FirstOrDefault(s => s.Index == nextIndex); contract.NextSong = next != null && next.Song != null ? new SongInAlbumContract(next, LanguagePreference, false) : null; } } if (song.Deleted) { var mergeEntry = GetMergeRecord(session, songId); contract.MergedTo = (mergeEntry != null ? new SongContract(mergeEntry.Target, LanguagePreference) : null); } if (agentNum != 0) { using (var tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) { var isHit = session.Query <SongHit>().Any(h => h.Song.Id == songId && h.Agent == agentNum); if (!isHit) { var hit = new SongHit(song, agentNum); session.Save(hit); } tx.Commit(); } } return contract; })); }
public SongDetails(SongDetailsContract contract) { ParamIs.NotNull(() => contract); Contract = contract; AdditionalNames = contract.AdditionalNames; Albums = contract.Albums; AlternateVersions = contract.AlternateVersions.Where(a => a.SongType != SongType.Original).ToArray(); ArtistString = contract.ArtistString; CanEdit = EntryPermissionManager.CanEdit(MvcApplication.LoginManager, contract.Song); CommentCount = contract.CommentCount; CreateDate = contract.CreateDate; DefaultLanguageSelection = contract.TranslatedName.DefaultLanguage; Deleted = contract.Deleted; Draft = contract.Song.Status == EntryStatus.Draft; FavoritedTimes = contract.Song.FavoritedTimes; Hits = contract.Hits; Id = contract.Song.Id; IsFavorited = contract.UserRating != SongVoteRating.Nothing; LatestComments = contract.LatestComments; Length = contract.Song.LengthSeconds; LikedTimes = contract.LikeCount; ListCount = contract.ListCount; Lyrics = contract.LyricsFromParents; MergedTo = contract.MergedTo; Name = contract.Song.Name; NicoId = contract.Song.NicoId; Notes = contract.Notes; OriginalVersion = (contract.Song.SongType != SongType.Original ? contract.OriginalVersion : null); Pools = contract.Pools; RatingScore = contract.Song.RatingScore; SongType = contract.Song.SongType; Status = contract.Song.Status; Tags = contract.Tags; UserRating = contract.UserRating; WebLinks = contract.WebLinks.ToList(); Animators = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Animator)).ToArray(); Bands = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Band)).ToArray(); Performers = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Vocalist)).ToArray(); Producers = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Producer)).ToArray(); OtherArtists = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Circle) || a.Categories.HasFlag(ArtistCategories.Label) || a.Categories.HasFlag(ArtistCategories.Other)).ToArray(); var pvs = contract.PVs; OriginalPVs = pvs.Where(p => p.PVType == PVType.Original).ToArray(); OtherPVs = pvs.Where(p => p.PVType != PVType.Original).ToArray(); PrimaryPV = PVHelper.PrimaryPV(pvs); ThumbUrl = VideoServiceHelper.GetThumbUrlPreferNotNico(pvs); ThumbUrlMaxSize = VideoServiceHelper.GetMaxSizeThumbUrl(pvs) ?? ThumbUrl; /*var nicoMimiUrl = GetNicoMimiUrl(contract); * if (!string.IsNullOrEmpty(nicoMimiUrl)) { * WebLinks.Add(new WebLinkContract(nicoMimiUrl, ViewRes.Song.DetailsStrings.NicoMimiDownload, WebLinkCategory.Other)); * }*/ if (PrimaryPV == null && !string.IsNullOrEmpty(NicoId)) { PrimaryPV = new PVContract { PVId = NicoId, Service = PVService.NicoNicoDouga } } ; if (pvs.All(p => p.Service != PVService.Youtube)) { var nicoPV = VideoServiceHelper.PrimaryPV(pvs, PVService.NicoNicoDouga); var query = HttpUtility.UrlEncode((nicoPV != null && !string.IsNullOrEmpty(nicoPV.Name)) ? nicoPV.Name : string.Format("{0} {1}", ArtistString, Name)); WebLinks.Add(new WebLinkContract(string.Format("http://www.youtube.com/results?search_query={0}", query), ViewRes.Song.DetailsStrings.SearchYoutube, WebLinkCategory.Other)); } }