Exemple #1
0
        public async Task <string> TryGetTheTVDBSeriesIdByRemoteIdAsync(RemoteId id)
        {
            switch (id.Type)
            {
            case RemoteIdType.TheTVDB:
                return(id.Id);

            case RemoteIdType.Imdb:
                return((await this.GetSeriesByImdbIdAsync(id.Id)).FirstOrDefault()?.SeriesId);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public IEnumerable <byte> GetMessage()
        {
            MessagePart payload =
                IdMarker().OfLength(1) +
                Payload().OfLength(4);

            var message =
                Preamble().OfLength(1) +
                (remoteId ?? RemoteId?.Invoke()).OfLength(3) +
                payload +
                Checksum(payload).OfLength(1) +
                Epilogue().OfLength(2);

            return(message);
        }
Exemple #3
0
        private async Task <bool> LoadFanartByImdbIdAsync(TheTVDBClient client, RemoteId id, string index = null)
        {
            var seriesId = await client.TryGetTheTVDBSeriesIdByRemoteIdAsync(id);

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

            var urls = (await client.GetBannersBySeriesIdAsync(seriesId)).Where(z => z.BannerType == BannerType.Fanart)
                       .Where(z => index == null || z.Season == index)
                       .Select(z => z.BuildUrl(client))
                       .ToArray();

            if (urls.Length > 0)
            {
                this.Load(urls);
                return(true);
            }
            return(false);
        }
Exemple #4
0
 public override int GetHashCode()
 {
     return(RemoteId?.GetHashCode() ?? 0);
 }
Exemple #5
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));
            }
 public override int GetHashCode()
 {
     return((269 + RemoteId.GetHashCode()) * 47 + Client.GetHashCode());
 }