Esempio n. 1
0
        /* NOW EVERYTHING RELATED TO SCROBBLING */
        public async void markAsWatched(BaseItemDto MediaInfo, string userToken)
        {
            SimklHistory history = new SimklHistory();

            _logger.Info("Scrobbling mediainfo: " + _json.SerializeToString(MediaInfo));
            if (MediaInfo.IsMovie == true || MediaInfo.Type == "Movie")
            {
                history.movies.Add(new SimklMovie(MediaInfo));
            }
            else if (MediaInfo.IsSeries == true || MediaInfo.Type == "Episode")
            {
                // TODO: TV Shows scrobbling (WIP)
                history.shows.Add(SimklShow.createFromEpisode(MediaInfo));
            }
            _logger.Info("Scrobbling " + _json.SerializeToString(history));
            try
            {
                await SyncHistoryAsync(history, userToken);
            }
            catch (MediaBrowser.Model.Net.HttpException e) when(e.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                _logger.Error("Invalid user token " + userToken + ", deleting");
                Plugin.Instance.Configuration.deleteUserToken(userToken);
            }
        }
Esempio n. 2
0
        /* NOW EVERYTHING RELATED TO SCROBBLING */
        public async Task <(bool success, BaseItemDto item)> markAsWatched(BaseItemDto item, string userToken)
        {
            SimklHistory        history = createHistoryFromItem(item);
            SyncHistoryResponse r       = await SyncHistoryAsync(history, userToken);

            _logger.Debug("Response: " + _json.SerializeToString(r));
            if (history.movies.Count == r.added.movies && history.shows.Count == r.added.shows)
            {
                return(true, item);
            }

            // If we are here, is because the item has not been found
            // let's try scrobbling from full path
            try {
                (history, item) = await getHistoryFromFileName(item, true);
            } catch (InvalidDataException) {
                // Let's try again but this time using only the FILE name
                _logger.Debug("Couldn't scrobble using full path, trying using only filename");
                (history, item) = await getHistoryFromFileName(item, false);
            }

            r = await SyncHistoryAsync(history, userToken);

            _logger.Debug("Response: " + _json.SerializeToString(r));

            return(history.movies.Count == r.added.movies && history.shows.Count == r.added.shows, item);
        }
Esempio n. 3
0
        public async Task <(SimklHistory history, BaseItemDto item)> getHistoryFromFileName(BaseItemDto item, bool fullpath = true)
        {
            string             fname = fullpath?item.Path:Path.GetFileName(item.Path);
            SearchFileResponse mo    = await getFromFile(fname);

            SimklHistory history = new SimklHistory();

            if (item.IsMovie == true || item.Type == "Movie")
            {
                if (mo.type != "movie")
                {
                    throw new InvalidDataException("type != movie (" + mo.type + ")");
                }
                item.Name           = mo.movie.title;
                item.ProductionYear = mo.movie.year;
                history.movies.Add(mo.movie);
            }
            else if (item.IsSeries == true || item.Type == "Episode")
            {
                if (mo.type != "episode")
                {
                    throw new InvalidDataException("type != episode (" + mo.type + ")");
                }
                item.Name              = mo.episode.title;
                item.SeriesName        = mo.show.title;
                item.IndexNumber       = mo.episode.episode;
                item.ParentIndexNumber = mo.episode.season;
                item.ProductionYear    = mo.show.year;
                history.episodes.Add(mo.episode);
            }

            return(history, item);
        }
Esempio n. 4
0
 /// <summary>
 /// Implements /sync/history method from simkl
 /// </summary>
 /// <param name="history">History object</param>
 /// <param name="userToken">User token</param>
 /// <returns></returns>
 public async Task <SyncHistoryResponse> SyncHistoryAsync(SimklHistory history, string userToken)
 {
     try {
         _logger.Info("Syncing History: " + _json.SerializeToString(history));
         return(_json.DeserializeFromStream <SyncHistoryResponse>(await _post("/sync/history", userToken, history)));
     } catch (MediaBrowser.Model.Net.HttpException e) when(e.StatusCode == System.Net.HttpStatusCode.Unauthorized)
     {
         _logger.Error("Invalid user token " + userToken + ", deleting");
         Plugin.Instance.deleteUserToken(userToken);
         throw new InvalidTokenException("Invalid user token " + userToken);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Implements /sync/history method from simkl.
 /// </summary>
 /// <param name="history">History object.</param>
 /// <param name="userToken">User token.</param>
 /// <returns>The sync history response.</returns>
 private async Task <SyncHistoryResponse?> SyncHistoryAsync(SimklHistory history, string userToken)
 {
     try
     {
         _logger.LogInformation("Syncing History");
         return(await Post <SyncHistoryResponse, SimklHistory>("/sync/history", userToken, history));
     }
     catch (HttpRequestException e) when(e.StatusCode == System.Net.HttpStatusCode.Unauthorized)
     {
         _logger.LogError(e, "Invalid user token {UserToken}, deleting", userToken);
         SimklPlugin.Instance?.Configuration.DeleteUserToken(userToken);
         throw new InvalidTokenException("Invalid user token " + userToken);
     }
 }
Esempio n. 6
0
        private static SimklHistory CreateHistoryFromItem(BaseItemDto item)
        {
            var history = new SimklHistory();

            if (item.IsMovie == true || item.Type == BaseItemKind.Movie)
            {
                history.Movies.Add(new SimklMovie(item));
            }
            else if (item.IsSeries == true || item.Type == BaseItemKind.Episode)
            {
                // TODO: TV Shows scrobbling (WIP)
                history.Shows.Add(new SimklShow(item));
            }

            return(history);
        }
Esempio n. 7
0
        private static SimklHistory createHistoryFromItem(BaseItemDto item)
        {
            SimklHistory history = new SimklHistory();

            if (item.IsMovie == true || item.Type == "Movie")
            {
                history.movies.Add(new SimklMovie(item));
            }
            else if (item.IsSeries == true || item.Type == "Episode")
            {
                // TODO: TV Shows scrobbling (WIP)
                history.shows.Add(new SimklShow(item));
            }

            return(history);
        }
Esempio n. 8
0
        private static SimklHistory CreateHistoryFromItem(BaseItemDto item)
        {
            var history = new SimklHistory();

            if (item.IsMovie == true || string.Equals(item.Type, nameof(Movie), StringComparison.OrdinalIgnoreCase))
            {
                history.Movies.Add(new SimklMovie(item));
            }
            else if (item.IsSeries == true || string.Equals(item.Type, nameof(Episode), StringComparison.OrdinalIgnoreCase))
            {
                // TODO: TV Shows scrobbling (WIP)
                history.Shows.Add(new SimklShow(item));
            }

            return(history);
        }
Esempio n. 9
0
        /// <summary>
        /// Get history from file name.
        /// </summary>
        /// <param name="item">Item.</param>
        /// <param name="fullpath">Full path.</param>
        /// <returns>Srobble history.</returns>
        private async Task <(SimklHistory history, BaseItemDto item)> GetHistoryFromFileName(BaseItemDto item, bool fullpath = true)
        {
            var fname = fullpath ? item.Path : Path.GetFileName(item.Path);
            var mo    = await GetFromFile(fname);

            if (mo == null)
            {
                throw new InvalidDataException("Search file response is null");
            }

            var history = new SimklHistory();

            if (mo.Movie != null &&
                (item.IsMovie == true || item.Type == BaseItemKind.Movie))
            {
                if (!string.Equals(mo.Type, "movie", StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidDataException("type != movie (" + mo.Type + ")");
                }

                item.Name           = mo.Movie.Title;
                item.ProductionYear = mo.Movie.Year;
                history.Movies.Add(mo.Movie);
            }
            else if (mo.Episode != null &&
                     mo.Show != null &&
                     (item.IsSeries == true || item.Type == BaseItemKind.Episode))
            {
                if (!string.Equals(mo.Type, "episode", StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidDataException("type != episode (" + mo.Type + ")");
                }

                item.Name              = mo.Episode.Title;
                item.SeriesName        = mo.Show.Title;
                item.IndexNumber       = mo.Episode.Episode;
                item.ParentIndexNumber = mo.Episode.Season;
                item.ProductionYear    = mo.Show.Year;
                history.Episodes.Add(mo.Episode);
            }

            return(history, item);
        }
Esempio n. 10
0
        /// <summary>
        /// Implements /sync/history method from simkl
        /// </summary>
        /// <param name="history">History object</param>
        /// <param name="userToken">User token</param>
        /// <returns></returns>
        public async Task <Stream> SyncHistoryAsync(SimklHistory history, string userToken)
        {
            return(await _post("/sync/history", userToken, history));

            // using (var r = await _get("/sync/history"))
        }