Ejemplo n.º 1
0
        public ValueGroup CalculateBiggestMovie()
        {
            var movies = GetAllMovies();

            var    biggestMovie = new MediaBrowser.Controller.Entities.Movies.Movie();
            double maxSize      = 0;

            foreach (var movie in movies)
            {
                try
                {
                    var f = _fileSystem.GetFileSystemInfo(movie.Path);
                    if (maxSize >= f.Length)
                    {
                        continue;
                    }

                    maxSize      = f.Length;
                    biggestMovie = movie;
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            maxSize = maxSize / 1073741824; //Byte to Gb
            var valueLineOne = CheckMaxLength($"{maxSize:F1} Gb");
            var valueLineTwo = CheckMaxLength($"{biggestMovie.Name}");

            return(new ValueGroup
            {
                Title = Constants.BiggestMovie,
                ValueLineOne = valueLineOne,
                ValueLineTwo = valueLineTwo,
                Size = "half",
                Id = biggestMovie.Id.ToString()
            });
        }
Ejemplo n.º 2
0
        private Task<QueryResult<ServerItem>> GetMovieItems(Movie item)
        {
            var list = new List<BaseItem>();

            list.Add(item);

            list.AddRange(item.GetTrailerIds().Select(i => _libraryManager.GetItemById(i)).Where(i => i != null));
            list.AddRange(item.SpecialFeatureIds.Select(i => _libraryManager.GetItemById(i)).Where(i => i != null));

            var serverItems = list.Select(i => new ServerItem { Item = i, StubType = null })
                .ToList();

            serverItems.Add(new ServerItem
            {
                Item = item,
                StubType = StubType.People
            });

            return Task.FromResult(new QueryResult<ServerItem>
            {
                Items = serverItems.ToArray(),
                TotalRecordCount = serverItems.Count
            });
        }
Ejemplo n.º 3
0
//        /// <summary>
//        /// Return information about the user, including ratings format
//        /// </summary>
//        /// <param name="traktUser"></param>
//        /// <returns></returns>
//        public async Task<AccountSettingsDataContract> GetUserAccount(TraktUser traktUser)
//        {
//            var data = new Dictionary<string, string> { { "username", traktUser.UserName }, { "password", traktUser.Password } };
//
//            var response =
//                await
//                _httpClient.Post(TraktUris.AccountSettings, data, Plugin.Instance.TraktResourcePool,
//                                                                     CancellationToken.None).ConfigureAwait(false);
//
//            return _jsonSerializer.DeserializeFromStream<AccountSettingsDataContract>(response);
//        }
//
//
//
//        /// <summary>
//        /// Return a list of the users friends
//        /// </summary>
//        /// <param name="traktUser">The user who's friends you want to retrieve</param>
//        /// <returns>A TraktFriendDataContract</returns>
//        public async Task<TraktFriendDataContract> GetUserFriends(TraktUser traktUser)
//        {
//            var data = new Dictionary<string, string> { { "username", traktUser.UserName }, { "password", traktUser.Password } };
//
//            var response = await _httpClient.Post(string.Format(TraktUris.Friends, traktUser.UserName), data, Plugin.Instance.TraktResourcePool,
//                                                                     CancellationToken.None).ConfigureAwait(false);
//
//            return _jsonSerializer.DeserializeFromStream<TraktFriendDataContract>(response);
//            
//        }
//
//
//
        /// <summary>
        /// Report to trakt.tv that a movie is being watched, or has been watched.
        /// </summary>
        /// <param name="movie">The movie being watched/scrobbled</param>
        /// <param name="mediaStatus">MediaStatus enum dictating whether item is being watched or scrobbled</param>
        /// <param name="traktUser">The user that watching the current movie</param>
        /// <param name="progressPercent"></param>
        /// <returns>A standard TraktResponse Data Contract</returns>
        public async Task<TraktScrobbleResponse> SendMovieStatusUpdateAsync(Movie movie, MediaStatus mediaStatus, TraktUser traktUser, float progressPercent)
        {
            var movieData = new TraktScrobbleMovie
            {
                AppDate = DateTime.Today.ToString("yyyy-MM-dd"),
                AppVersion = _appHost.ApplicationVersion.ToString(),
                Progress = progressPercent,
                Movie = new TraktMovie
                {
                    Title = movie.Name,
                    Year = movie.ProductionYear,
                    Ids = new TraktMovieId
                    {
                        Imdb = movie.GetProviderId(MetadataProviders.Imdb),
                        Tmdb = movie.GetProviderId(MetadataProviders.Tmdb).ConvertToInt()
                    }
                }
            };

            string url;
            switch (mediaStatus)
            {
                case MediaStatus.Watching:
                    url = TraktUris.ScrobbleStart;
                    break;
                case MediaStatus.Paused:
                    url = TraktUris.ScrobblePause;
                    break;
                default:
                    url = TraktUris.ScrobbleStop;
                    break;
            }

            var response = await PostToTrakt(url, movieData, CancellationToken.None, traktUser);
            return _jsonSerializer.DeserializeFromStream<TraktScrobbleResponse>(response);
        }
Ejemplo n.º 4
0
        private void AttachSoundtrackIds(BaseItemDto dto, Movie item, User user)
        {
            var tmdb = item.GetProviderId(MetadataProviders.Tmdb);

            if (string.IsNullOrEmpty(tmdb))
            {
                return;
            }

            var recursiveChildren = user == null
                                        ? _libraryManager.RootFolder.RecursiveChildren
                                        : user.RootFolder.GetRecursiveChildren(user);

            dto.SoundtrackIds = recursiveChildren
                .Where(i =>
                {
                    if (!string.IsNullOrEmpty(tmdb) &&
                        string.Equals(tmdb, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase) &&
                        i is MusicAlbum)
                    {
                        return true;
                    }
                    return false;
                })
                .Select(GetClientItemId)
                .ToArray();
        }
 public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken)
 {
     return FetchAsync(item, cancellationToken);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Report to trakt.tv that a movie is being watched, or has been watched.
        /// </summary>
        /// <param name="movie">The movie being watched/scrobbled</param>
        /// <param name="mediaStatus">MediaStatus enum dictating whether item is being watched or scrobbled</param>
        /// <param name="traktUser">The user that watching the current movie</param>
        /// <returns>A standard TraktResponse Data Contract</returns>
        public async Task<TraktResponseDataContract> SendMovieStatusUpdateAsync(Movie movie, MediaStatus mediaStatus, TraktUser traktUser)
        {
            var data = new Dictionary<string,string>
                           {
                               {"username", traktUser.UserName},
                               {"password", traktUser.PasswordHash},
                               {"imdb_id", movie.GetProviderId(MetadataProviders.Imdb)}
                           };

            if (movie.ProviderIds != null && movie.ProviderIds.ContainsKey("Tmdb"))
            {
                data.Add("tmdb_id", movie.ProviderIds["Tmdb"]);
            }

            data.Add("title", movie.Name);
            data.Add("year", movie.ProductionYear != null ? movie.ProductionYear.ToString() : "");
            data.Add("duration", movie.RunTimeTicks != null ? ((int)((movie.RunTimeTicks / 10000000) / 60)).ToString(CultureInfo.InvariantCulture) : "");


            Stream response = null;

            if (mediaStatus == MediaStatus.Watching)
                response = await _httpClient.Post(TraktUris.MovieWatching, data, Plugin.Instance.TraktResourcePool, CancellationToken.None).ConfigureAwait(false);
            else if (mediaStatus == MediaStatus.Scrobble)
                response = await _httpClient.Post(TraktUris.MovieScrobble, data, Plugin.Instance.TraktResourcePool, CancellationToken.None).ConfigureAwait(false);

            return _jsonSerializer.DeserializeFromStream<TraktResponseDataContract>(response);
        }