Beispiel #1
0
 public static CoverBuilder CreateRole(VideoRole role)
 {
     return(new CoverBuilder(role)
     {
         CoverType = CoverType.Role
     });
 }
        public VideoRoleViewModel(VideoRole source, VideoRoleCollectionViewModel parent, IImdbItem imdbItem, bool isMajor)
            : base(source)
        {
            this.parent   = parent;
            this.ImdbItem = imdbItem;
            this.IsMajor  = isMajor;

            this.CoverViewModel.AutoGenerateCoverProvider = new AutoGenerateCoverProvider()
            {
                ImdbItem    = imdbItem,
                TheTVDBItem = this.ImdbItem as ITheTVDBItem
            };
        }
Beispiel #3
0
        public static bool Edit(Window parent, VideoRole role)
        {
            var window = new RoleEditorWindow()
            {
                Owner = parent
            };

            window.ViewModel.ReadFromObject(role);
            if (window.ShowDialog() == true)
            {
                window.ViewModel.WriteToObject(role);
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// return true if upgrade success
        /// </summary>
        /// <param name="dataCenter"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public async Task <bool> UpgradeAsync(DataCenter dataCenter, VideoRoleCollection item)
        {
            foreach (var role in (item.MajorRoles ?? Empty <VideoRole> .Enumerable).Concat(item.MinorRoles ?? Empty <VideoRole> .Enumerable))
            {
                if (role.ActorId == null)
                {
                    role.ActorId = role.Id;
                    role.Id      = VideoRole.NewGuid();
                    if (role.CoverId != null)
                    {
                        await CoverRenamekeyAsync(dataCenter, role.CoverId, role.Id);

                        role.CoverId = null;
                    }
                }
            }
            return(true);
        }
            private void CombineTo(VideoRole source, VideoRole dest)
            {
                Debug.Assert(source != null && dest != null);

                var coverId = (source as ICoverParent).CoverId;

                if (coverId != null)
                {
                    this.RemovedCoverId.Add(coverId);
                }

                if (source.RoleName != null)
                {
                    dest.RoleName = dest.RoleName == null
                        ? source.RoleName.ToList()
                        : source.RoleName.Concat(dest.RoleName).Distinct().ToList();
                }
            }
Beispiel #6
0
        public async Task <bool> AutoCreateVideoRoleAsync(string id, RemoteId remoteId)
        {
            var collection = await this.FindAsync(id);

            if (collection.MajorRoles != null || collection.MinorRoles != null)
            {
                return(false);
            }

            var client = JryVideoCore.Current.TheTVDBHost.LastClientInstance;

            if (client == null)
            {
                return(false);
            }

            var theTVDBId = await client.TryGetTheTVDBSeriesIdByRemoteIdAsync(remoteId);

            if (theTVDBId == null)
            {
                return(false);
            }

            var actors = (await client.GetActorsBySeriesIdAsync(theTVDBId)).ToArray();

            if (actors.Length == 0)
            {
                return(false);
            }
            var major = actors.Select(z => z.SortOrder).Min();

            collection = await this.FindAsync(id); // sure collection was newest.

            if (collection.MajorRoles != null || collection.MinorRoles != null)
            {
                return(false);
            }

            foreach (var actor in actors)
            {
                var artist = (await this.artistManager.Source.QueryAsync(new Artist.QueryParameter()
                {
                    TheTVDBId = actor.Id
                }, 0, int.MaxValue)).FirstOrDefault();

                if (artist == null && !actor.Name.IsNullOrWhiteSpace())
                {
                    artist = new Artist()
                    {
                        TheTVDBId = actor.Id,
                        Names     = new List <string>()
                        {
                            actor.Name.Trim()
                        }
                    };
                    artist.BuildMetaData();
                    await this.artistManager.InsertAsync(artist);
                }

                if (artist != null)
                {
                    var role = VideoRole.Create();
                    role.ActorId = artist.Id;
                    if (!actor.Role.IsNullOrWhiteSpace())
                    {
                        role.RoleName = new List <string>()
                        {
                            actor.Role.Trim()
                        };
                    }

                    (actor.SortOrder == major
                        ? (collection.MajorRoles ?? (collection.MajorRoles = new List <VideoRole>()))
                        : (collection.MinorRoles ?? (collection.MinorRoles = new List <VideoRole>()))).Add(role);
                }
            }
            await this.UpdateAsync(collection);

            return(true);
        }
            private async Task <bool> TryAutoAddCoverAsync(DataCenter dataCenter, TheTVDBClient client, RemoteId removeId, VideoRole role)
            {
                var theTVDBId = await client.TryGetTheTVDBSeriesIdByRemoteIdAsync(removeId);

                if (theTVDBId == null)
                {
                    return(false);
                }
                var actor = await dataCenter.ArtistManager.FindAsync(role.ActorId);

                if (actor == null)
                {
                    return(false);
                }
                var actors = (await client.GetActorsBySeriesIdAsync(theTVDBId)).ToArray();

                actors = actors.Where(z => z.Id == actor.TheTVDBId).ToArray();
                if (actors.Length != 1)
                {
                    return(false);
                }
                if (!actors[0].HasBanner)
                {
                    return(false);
                }
                var url     = actors[0].BuildUrl(client);
                var builder = CoverBuilder.CreateRole(role);

                builder.Uri.Add(url);
                return(await dataCenter.CoverManager.BuildCoverAsync(builder));
            }
 private static bool Exchange(VideoRoleCollection source, VideoRoleCollection dest, VideoRole role)
 {
     if (source.MajorRoles?.Contains(role) == true)
     {
         source.MajorRoles.Remove(role);
         (dest.MajorRoles ?? (dest.MajorRoles = new List <VideoRole>())).Add(role);
         return(true);
     }
     if (source.MinorRoles?.Contains(role) == true)
     {
         source.MinorRoles.Remove(role);
         (dest.MinorRoles ?? (dest.MinorRoles = new List <VideoRole>())).Add(role);
         return(true);
     }
     return(false);
 }