public PVContract CreatePVContract(HttpPostedFileBase file, IIdentity user, IUser loggedInUser) { var tempFile = Path.ChangeExtension(Path.GetTempFileName(), ImageHelper.GetExtensionFromMime(file.ContentType)); file.SaveAs(tempFile); var filename = Path.GetFileName(tempFile); var pv = new PVContract { Service = PVService.LocalFile, PVId = filename }; using (var mp3 = TagLib.File.Create(tempFile, file.ContentType, ReadStyle.Average)) { pv.Name = mp3.Tag.Title; pv.Author = user.Name; pv.Length = (int)mp3.Properties.Duration.TotalSeconds; } pv.CreatedBy = loggedInUser.Id; if (string.IsNullOrEmpty(pv.Name)) { pv.Name = Path.GetFileNameWithoutExtension(file.FileName); } return(pv); }
public ActionResult EmbedSong(int songId = invalidId, int pvId = invalidId, int?w = null, int?h = null, ContentLanguagePreference lang = ContentLanguagePreference.Default) { if (songId == invalidId) { return(NoId()); } var song = songService.GetSongForApi(songId, SongOptionalFields.AdditionalNames | SongOptionalFields.PVs, lang); PVContract current = null; if (pvId != invalidId) { current = song.PVs.FirstOrDefault(p => p.Id == pvId); } if (current == null) { current = PVHelper.PrimaryPV(song.PVs); } var viewModel = new EmbedSongViewModel { Song = song, CurrentPV = current, Width = w, Height = h }; return(PartialView(viewModel)); }
public PVForSong(Song song, PVContract contract) : base(contract) { Song = song; Length = contract.Length; ThumbUrl = contract.ThumbUrl ?? string.Empty; }
protected GenericPV(TEntry entry, PVContract contract) : base(contract) { Entry = entry; Length = contract.Length; PublishDate = contract.PublishDate; }
private PVForSong CreatePV(PVContract contract) { return(new PVForSong(new Song(), contract) { Id = contract.Id }); }
public virtual void CopyMetaFrom(PVContract contract) { ParamIs.NotNull(() => contract); Author = contract.Author; Name = contract.Name; PVType = contract.PVType; }
public virtual bool ContentEquals(PVContract pv) { if (pv == null) { return(false); } return(Name == pv.Name); }
public PVForSong(Song song, PVContract contract) : base(contract) { Song = song; Length = contract.Length; ThumbUrl = contract.ThumbUrl ?? string.Empty; CreatedBy = contract.CreatedBy; Disabled = contract.Disabled; }
public EmbedPVViewModel(PVContract pv, int width = 560, int height = 315, bool autoplay = false, bool enableApi = false, string id = null) { PV = pv; Width = width; Height = height; Autoplay = autoplay; EnableApi = enableApi; Id = id; }
public void SetUp() { manager = new PVManager <PVForSong>(); pvContract = new PVContract { Id = 1, Author = "Miku!", Name = "A cool Miku PV", PVId = "3939", ThumbUrl = "http://youtube.com/thumb", Url = "http://youtube.com/39" }; pvContract2 = new PVContract { Id = 2, Author = "Luka!", Name = "A cool Luka PV", PVId = "0303", ThumbUrl = "http://youtube.com/thumb3", Url = "http://youtube.com/3" }; }
public virtual PVForAlbum CreatePV(PVContract contract) { ParamIs.NotNull(() => contract); var pv = new PVForAlbum(this, contract); PVs.Add(pv); return(pv); }
public PV(PVContract contract) : this() { ParamIs.NotNull(() => contract); Service = contract.Service; PVId = contract.PVId; PVType = contract.PVType; Name = contract.Name ?? string.Empty; Author = contract.Author ?? string.Empty; }
public SongWithAlbumAndPVsContract(Song song, ContentLanguagePreference languagePreference, bool getPVs) : base(song, languagePreference) { if (getPVs) { PVs = song.PVs.Select(p => new PVContract(p)).ToArray(); } else { PVs = new PVContract[] { } }; }
public virtual PVForSong CreatePV(PVContract contract) { ParamIs.NotNull(() => contract); var pv = new PVForSong(this, contract); PVs.Add(pv); UpdateNicoId(); UpdatePVServices(); return(pv); }
public PV(PVContract contract) : this() { ParamIs.NotNull(() => contract); Service = contract.Service; PVId = contract.PVId; PVType = contract.PVType; Name = contract.Name ?? string.Empty; PublishDate = contract.PublishDate; Author = contract.Author ?? string.Empty; ExtendedMetadata = contract.ExtendedMetadata; }
public ActionResult ParsePVUrl(string pvUrl, string callback, DataFormat format = DataFormat.Auto) { var result = VideoServiceHelper.ParseByUrl(pvUrl, true, LoginManager); if (!result.IsOk) { return(Json(new GenericResponse <string>(false, result.Exception.Message))); } var contract = new PVContract(result, PVType.Original); return(Object(contract, format, callback)); }
public void Sync_Contracts_Removed() { manager.PVs.Add(CreatePV(pvContract)); var newLinks = new PVContract[] { }; var result = manager.Sync(newLinks, CreatePV); Assert.IsNotNull(result, "result is not null"); Assert.IsTrue(result.Changed, "is changed"); Assert.AreEqual(0, result.Added.Length, "none added"); Assert.AreEqual(0, result.Edited.Length, "none edited"); Assert.AreEqual(1, result.Removed.Length, "1 removed"); Assert.AreEqual(0, result.Unchanged.Length, "none unchanged"); Assert.IsTrue(result.Removed.First().ContentEquals(pvContract), "removed link matches contract"); }
public void Sync_Contracts_Removed() { _manager.PVs.Add(CreatePV(_pvContract)); var newLinks = new PVContract[] { }; var result = _manager.Sync(newLinks, CreatePV); result.Should().NotBeNull("result is not null"); result.Changed.Should().BeTrue("is changed"); result.Added.Length.Should().Be(0, "none added"); result.Edited.Length.Should().Be(0, "none edited"); result.Removed.Length.Should().Be(1, "1 removed"); result.Unchanged.Length.Should().Be(0, "none unchanged"); result.Removed.First().ContentEquals(_pvContract).Should().BeTrue("removed link matches contract"); }
public ActionResult CreatePVForAlbumByUrl(int albumId, string pvUrl) { var result = VideoServiceHelper.ParseByUrl(pvUrl, true); if (!result.IsOk) { return(Json(new GenericResponse <string>(false, result.Exception.Message))); } var contract = new PVContract(result, PVType.Other); var view = RenderPartialViewToString("PVForSongEditRow", contract); return(Json(new GenericResponse <string>(view))); }
public virtual PVForSong CreatePV(PVContract contract) { ParamIs.NotNull(() => contract); var pv = new PVForSong(this, contract); PVs.Add(pv); UpdateNicoId(); UpdatePVServices(); if (LengthSeconds <= 0) { LengthSeconds = GetLengthFromPV(); } return(pv); }
public async Task <ActionResult <PVContract> > GetPVByUrl(string pvUrl, PVType type = PVType.Original, bool getTitle = true) { if (string.IsNullOrEmpty(pvUrl)) { return(BadRequest()); } var result = await _pvParser.ParseByUrlAsync(pvUrl, getTitle, _permissionContext); if (!result.IsOk) { var msg = result.Exception.Message; return(BadRequest(msg)); } var contract = new PVContract(result, type); return(contract); }
public PVContract GetPVByUrl(string pvUrl, PVType type = PVType.Original) { if (string.IsNullOrEmpty(pvUrl)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var result = pvParser.ParseByUrl(pvUrl, true, permissionContext); if (!result.IsOk) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = result.Exception.Message }); } var contract = new PVContract(result, type); return(contract); }
public async Task <PVContract> GetPVByUrl(string pvUrl, PVType type = PVType.Original, bool getTitle = true) { if (string.IsNullOrEmpty(pvUrl)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var result = await pvParser.ParseByUrlAsync(pvUrl, getTitle, permissionContext); if (!result.IsOk) { var msg = result.Exception.Message; throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = msg, Content = new StringContent(msg) }); } var contract = new PVContract(result, type); return(contract); }
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 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 EmbedPiaproViewModel(PVContract pv, string widthStr, string heightStr) { PV = pv; WidthStr = widthStr; HeightStr = heightStr; }
public ReleaseEventDetailsContract() { Artists = new ArtistForEventContract[0]; PVs = new PVContract[0]; WebLinks = new WebLinkContract[0]; }
public PVForEvent(ReleaseEvent entry, PVContract contract) : base(entry, contract) { }
public EmbedBiliViewModel(PVContract pv, int width, int height) { PV = pv; Width = width; Height = height; }
public override void CopyMetaFrom(PVContract contract) { base.CopyMetaFrom(contract); ThumbUrl = contract.ThumbUrl; }