Beispiel #1
0
        public EntryForApiContract(Song song, ContentLanguagePreference languagePreference, EntryOptionalFields includedFields)
            : this((IEntryWithNames)song, languagePreference)
        {
            ArtistString = song.ArtistString[languagePreference];
            CreateDate   = song.CreateDate;
            SongType     = song.SongType;
            Status       = song.Status;

            var thumb = VideoServiceHelper.GetThumbUrl(song.PVs.PVs);

            if (includedFields.HasFlag(EntryOptionalFields.MainPicture) && !string.IsNullOrEmpty(thumb))
            {
                MainPicture = new EntryThumbForApiContract {
                    UrlSmallThumb = thumb, UrlThumb = thumb, UrlTinyThumb = thumb
                };
            }

            if (includedFields.HasFlag(EntryOptionalFields.Names))
            {
                Names = song.Names.Select(n => new LocalizedStringContract(n)).ToArray();
            }

            if (includedFields.HasFlag(EntryOptionalFields.Tags))
            {
                Tags = song.Tags.Usages.Select(u => new TagUsageForApiContract(u)).ToArray();
            }

            if (includedFields.HasFlag(EntryOptionalFields.WebLinks))
            {
                WebLinks = song.WebLinks.Select(w => new ArchivedWebLinkContract(w)).ToArray();
            }
        }
        public void GetThumbUrl_HasOnlyReprint()
        {
            var pvs = new[] { reprintWithThumb };

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            Assert.AreEqual("reprint", result, "result");
        }
        public void GetThumbUrl_HasOriginalWithThumb()
        {
            var pvs = new[] { reprintWithThumb, originalWithThumb };

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            Assert.AreEqual("original", result, "result");
        }
        public void GetThumbUrl_PreferNotNico()
        {
            var pvs = new[] { _reprintWithThumb, _originalWithThumb };

            var result = VideoServiceHelper.GetThumbUrlPreferNotNico(pvs);

            result.Should().Be("reprint", "result");
        }
        public void GetThumbUrl_PreferNotNico()
        {
            var pvs = new[] { reprintWithThumb, originalWithThumb };

            var result = VideoServiceHelper.GetThumbUrlPreferNotNico(pvs);

            Assert.AreEqual("reprint", result, "result");
        }
        public void GetThumbUrl_HasOnlyReprint()
        {
            var pvs = new[] { _reprintWithThumb };

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            result.Should().Be("reprint", "result");
        }
        public void GetThumbUrl_HasOriginalWithThumb()
        {
            var pvs = new[] { _reprintWithThumb, _originalWithThumb };

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            result.Should().Be("original", "result");
        }
Beispiel #8
0
 public SongContract(Song song, ContentLanguagePreference languagePreference, bool getThumbUrl = true)
     : this(song, languagePreference, string.Empty)
 {
     if (getThumbUrl)
     {
         // TODO: Used on the front page. Should be moved elsewhere.
         ThumbUrl = VideoServiceHelper.GetThumbUrl(song.PVs.PVs);
     }
 }
        public void GetThumbUrl_Disabled()
        {
            _originalWithThumb.Disabled = true;
            var pvs = new[] { _reprintWithThumb, _originalWithThumb };

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            result.Should().Be("reprint", "result");
        }
Beispiel #10
0
        public PVContract PrimaryPVForSong(int songId, PVServices?pvServices)
        {
            return(HandleQuery(ctx => {
                var pvs = ctx.Load(songId).PVs.Where(pv => pvServices == null || (pvServices.Value & (PVServices)pv.Service) == (PVServices)pv.Service);
                var primaryPv = VideoServiceHelper.PrimaryPV(pvs, PermissionContext.IsLoggedIn ? (PVService?)PermissionContext.LoggedUser.PreferredVideoService : null);

                return primaryPv != null ? new PVContract(primaryPv) : null;
            }));
        }
        public void GetThumbUrl_HasReprintWithThumb()
        {
            _originalWithThumb.ThumbUrl = string.Empty;
            var pvs = new[] { _reprintWithThumb, _originalWithThumb };

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            result.Should().Be("reprint", "result");
        }
        public void GetThumbUrl_HasReprintWithThumb()
        {
            originalWithThumb.ThumbUrl = string.Empty;
            var pvs = new[] { reprintWithThumb, originalWithThumb };

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            Assert.AreEqual("reprint", result, "result");
        }
        public void GetThumbUrl_Disabled()
        {
            originalWithThumb.Disabled = true;
            var pvs = new[] { reprintWithThumb, originalWithThumb };

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            Assert.AreEqual("reprint", result, "result");
        }
Beispiel #14
0
        public PVContract PVForSongAndService(int songId, PVService service)
        {
            return(HandleQuery(ctx => {
                var pvs = ctx.OfType <PVForSong>().Query().Where(pv => pv.Song.Id == songId && pv.Service == service).ToArray();

                var primaryPv = VideoServiceHelper.PrimaryPV(pvs, service);

                return primaryPv != null ? new PVContract(primaryPv) : null;
            }));
        }
        public void GetThumbUrl_HasNoThumbs()
        {
            originalWithThumb.ThumbUrl = string.Empty;
            reprintWithThumb.ThumbUrl  = string.Empty;
            var pvs       = new[] { reprintWithThumb, originalWithThumb };
            var nicoThumb = VideoService.NicoNicoDouga.GetThumbUrlById(originalWithThumb.PVId);

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            Assert.AreEqual(nicoThumb, result, "result");
        }
        public void GetThumbUrl_HasNoThumbs()
        {
            _originalWithThumb.ThumbUrl = string.Empty;
            _reprintWithThumb.ThumbUrl  = string.Empty;
            var pvs       = new[] { _reprintWithThumb, _originalWithThumb };
            var nicoThumb = VideoService.NicoNicoDouga.GetThumbUrlById(_originalWithThumb.PVId);

            var result = VideoServiceHelper.GetThumbUrl(pvs);

            result.Should().Be(nicoThumb, "result");
        }
Beispiel #17
0
        private ParsedSongQuery ParseReferenceQuery(string trimmed, string query)
        {
            // Optimization: check prefix, in most cases the user won't be searching by URL
            if (trimmed.StartsWith("/s/", StringComparison.InvariantCultureIgnoreCase))
            {
                var entryId = entryUrlParser.Parse(trimmed, allowRelative: true);

                if (entryId.EntryType == EntryType.Song)
                {
                    return new ParsedSongQuery {
                               Id = entryId.Id
                    }
                }
                ;
            }
            else if (trimmed.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
            {
                // Test PV URL with services that don't require a web call
                var videoParseResult = VideoServiceHelper.ParseByUrl(query, false, null,
                                                                     VideoService.NicoNicoDouga, VideoService.Youtube, VideoService.Bilibili, VideoService.File, VideoService.LocalFile, VideoService.Vimeo);

                if (videoParseResult.IsOk)
                {
                    if (videoParseResult.Service == Domain.PVs.PVService.NicoNicoDouga)
                    {
                        return(new ParsedSongQuery {
                            NicoId = videoParseResult.Id
                        });
                    }
                    else
                    {
                        return(new ParsedSongQuery {
                            PV = new PVContract {
                                PVId = videoParseResult.Id, Service = videoParseResult.Service
                            }
                        });
                    }
                }

                var entryId = entryUrlParser.Parse(trimmed, allowRelative: false);

                if (entryId.EntryType == EntryType.Song)
                {
                    return new ParsedSongQuery {
                               Id = entryId.Id
                    }
                }
                ;
            }

            return(null);
        }
Beispiel #18
0
        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));
        }
Beispiel #19
0
        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)));
        }
Beispiel #20
0
        public SongForApiContract(Song song, ContentLanguagePreference languagePreference)
        {
            Albums  = song.Albums.Select(a => new AlbumContract(a.Album, languagePreference)).ToArray();
            Artists = song.Artists.Select(a => new ArtistForSongContract(a, languagePreference)).ToArray();
            Tags    = song.Tags.Tags.Select(t => t.Name).ToArray();

            CreateDate          = song.CreateDate;
            DefaultName         = song.DefaultName;
            DefaultNameLanguage = song.Names.SortNames.DefaultLanguage;
            FavoritedTimes      = song.FavoritedTimes;
            Id          = song.Id;
            Names       = song.Names.Select(n => new LocalizedStringContract(n)).ToArray();
            PVServices  = song.PVServices;
            RatingScore = song.RatingScore;
            SongType    = song.SongType;
            Status      = song.Status;
            ThumbUrl    = VideoServiceHelper.GetThumbUrl(song.PVs.PVs);
            Version     = song.Version;
        }
Beispiel #21
0
 public PVContract PrimaryPV(IEnumerable <PVContract> pvs)
 {
     return(VideoServiceHelper.PrimaryPV(pvs, PreferredVideoService));
 }
Beispiel #22
0
 public PVContract[] GetMainPVs(PVContract[] allPvs)
 {
     return(EnumVal <PVService> .Values.Select(service => VideoServiceHelper.GetPV(allPvs, service)).Where(p => p != null).ToArray());
 }
Beispiel #23
0
        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;
        }
Beispiel #24
0
 public virtual void UpdateThumbUrl()
 {
     ThumbUrl = VideoServiceHelper.GetThumbUrl(PVs.PVs);
 }
Beispiel #25
0
 /// <summary>
 /// Gets primary thumbnail URL for this song.
 /// For new songs this is saved directly to the song entry, but for older entries the PVs list needs to be loaded.
 /// Therefore, there might be some performance penalty.
 /// See <see cref="ThumbUrl"/>.
 /// </summary>
 /// <returns>
 /// Absolute URL to song thumbnail. For example, http://tn-skr1.smilevideo.jp/smile?i=12849032.
 /// Can be null or empty if no thumbnail is available.
 /// </returns>
 public virtual string GetThumbUrl()
 {
     return(!string.IsNullOrEmpty(ThumbUrl) ? ThumbUrl : VideoServiceHelper.GetThumbUrl(PVs.PVs));
 }
Beispiel #26
0
 private string GetSongThumbUrl(IEntryBase entry)
 {
     return(entry is Song ? VideoServiceHelper.GetThumbUrl(((Song)entry).PVs.PVs) : string.Empty);
 }
Beispiel #27
0
 public PartialFindResult <SongContract> FindWithThumbPreferNotNico(SongQueryParams queryParams)
 {
     return(Find(s => new SongContract(s, PermissionContext.LanguagePreference, VideoServiceHelper.GetThumbUrlPreferNotNico(s.PVs.PVs)), queryParams));
 }
Beispiel #28
0
        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));
            }
        }
Beispiel #29
0
        public SongForApiContract(Song song, SongMergeRecord mergeRecord, ContentLanguagePreference languagePreference,
                                  bool albums = true, bool artists = true, bool names = true, bool pvs = false, bool tags = true, bool thumbUrl = true, bool webLinks = false)
        {
            ArtistString        = song.ArtistString[languagePreference];
            CreateDate          = song.CreateDate;
            DefaultName         = song.DefaultName;
            DefaultNameLanguage = song.Names.SortNames.DefaultLanguage;
            FavoritedTimes      = song.FavoritedTimes;
            Id            = song.Id;
            LengthSeconds = song.LengthSeconds;
            Name          = song.Names.SortNames[languagePreference];
            PVServices    = song.PVServices;
            RatingScore   = song.RatingScore;
            SongType      = song.SongType;
            Status        = song.Status;
            Version       = song.Version;

            if (languagePreference != ContentLanguagePreference.Default)
            {
                AdditionalNames = song.Names.GetAdditionalNamesStringForLanguage(languagePreference);
                LocalizedName   = song.Names.SortNames[languagePreference];
            }

            if (albums)
            {
                Albums = song.Albums.Select(a => new AlbumContract(a.Album, languagePreference)).ToArray();
            }

            if (artists)
            {
                Artists = song.Artists.Select(a => new ArtistForSongContract(a, languagePreference)).ToArray();
            }

            if (names)
            {
                Names = song.Names.Select(n => new LocalizedStringContract(n)).ToArray();
            }

            if (pvs)
            {
                PVs = song.PVs.Select(p => new PVContract(p)).ToArray();
            }

            if (tags)
            {
                Tags = song.Tags.Usages.Select(u => new TagUsageForApiContract(u)).ToArray();
            }

            if (thumbUrl)
            {
                ThumbUrl = VideoServiceHelper.GetThumbUrl(song.PVs.PVs);
            }

            if (webLinks)
            {
                WebLinks = song.WebLinks.Select(w => new WebLinkContract(w)).ToArray();
            }

            if (mergeRecord != null)
            {
                MergedTo = mergeRecord.Target.Id;
            }
        }
        public void GetThumbUrl_Nothing()
        {
            var result = VideoServiceHelper.GetThumbUrl(new IPVWithThumbnail[0]);

            Assert.AreEqual(string.Empty, result, "result");
        }