示例#1
0
        /// <summary>
        ///     Megjelöl egy epizódot, mint elkezdett epizód.
        /// </summary>
        public async Task MarkEpisodeStarted(InternalEpisodeStartedModel episodeStartedModel)
        {
            //TODO obsolete things
            //bool isNull = episodeStartedModel.GetType().GetProperties()
            //    .All(p => p.GetValue(episodeStartedModel) != null);

            //var episodeStartedDao = _episodeStartedMapper.Map(episodeStartedModel); //needed
            //await EpisodeStarted.InsertOneAsync(episodeStartedDao);  //needed

            //await EpisodeStarted.InsertOneAsync(new EpisodeStartedDao
            //{
            //    Date = episodeStartedModel.Date,
            //    EpisodeNumber = episodeStartedModel.EpisodeNumber,
            //    SeasonNumber = episodeStartedModel.SeasonNumber,
            //    HoursElapsed = episodeStartedModel.HoursElapsed,
            //    MinutesElapsed = episodeStartedModel.MinutesElapsed,
            //    SecondsElapsed = episodeStartedModel.SecondsElapsed,
            //    TmdbId = episodeStartedModel.TmdbId,
            //    TvMazeId = episodeStartedModel.TvMazeId,
            //    Userid = episodeStartedModel.Userid,
            //    WatchedPercentage = episodeStartedModel.WatchedPercentage
            //});

            //            if (!isNull) { return EpisodeStarted.InsertOneAsync(episodeStartedModel); } return null;
        }
示例#2
0
        public static async Task <bool> UpdateStartedSeries(InternalEpisodeStartedModel internalEpisode, string title)
        {
            var isUpdated =
                await new WebClientManager().Post <bool>($"http://localhost:5001/series/updateStartedEpisode/{title}",
                                                         internalEpisode);

            return(isUpdated);
        }
示例#3
0
        /// <summary>
        ///     Visszaadja, hogy egy epizódot elkezdtünk-e már.
        /// </summary>
        /// <param name="internalEpisodeStarted"></param>
        public async Task <bool> IsEpisodeStarted(InternalEpisodeStartedModel internalEpisodeStarted)
        {
            //var episodeStartedDao = _episodeStartedMapper.Map(internalEpisodeStarted);
            //var s = await EpisodeStarted.CountDocumentsAsync(
            //    ep => (ep.TvMazeId == episodeStartedDao.TvMazeId || ep.TmdbId == episodeStartedDao.TmdbId) &&
            //          ep.SeasonNumber == episodeStartedDao.SeasonNumber &&
            //          ep.EpisodeNumber == episodeStartedDao.EpisodeNumber);
            //return s > 0;

            return(true);
        }
示例#4
0
        public async Task <bool> Post <T>(string url, InternalEpisodeStartedModel body)
        {
            var c           = new HttpClient();
            var json        = JsonConvert.SerializeObject(body);
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
            var request     = await c.PostAsync(new Uri(url), httpContent);

            var response = await request.Content.ReadAsStringAsync();

            var res = JsonConvert.DeserializeObject <Result <bool> >(response);

            return(res.Data);
            //return bool.TryParse(response, out var result);
        }
示例#5
0
        /// <summary>
        ///     Egy elkezdett epizód frissítése. Frissített értékek: Eltelt óra, eltelt percek, eltelt másodpercek.
        /// </summary>
        /// <param name="internalEpisode"></param>
        public async Task <bool> UpdateStartedEpisode(InternalEpisodeStartedModel internalEpisode)
        {
            //var episodeDao = _episodeStartedMapper.Map(internalEpisode);
            //var updateDef = Builders<EpisodeStartedDao>.Update.Set(o => o.HoursElapsed, internalEpisode.HoursElapsed)
            //    .Set(o => o.MinutesElapsed, episodeDao.MinutesElapsed)
            //    .Set(o => o.SecondsElapsed, episodeDao.SecondsElapsed)
            //    .Set(o => o.WatchedPercentage, episodeDao.WatchedPercentage);

            //var s = await EpisodeStarted.UpdateOneAsync(
            //    episodeStarted => episodeStarted.TvMazeId == episodeDao.TvMazeId ||
            //                      episodeStarted.TmdbId == episodeDao.TmdbId, updateDef);

            //return s.ModifiedCount > 0;

            return(true);
        }
示例#6
0
        public async Task <bool> GetShow(InternalEpisodeStartedModel episodeStarted, string showTitle)
        {
            //var show = await _mongoSeriesCollection.FindAsynchronous(series => series.Title.ToLower() == showTitle.ToLower());

            //if (show != null)
            //{
            //    //var episode = await EpisodeStarted.FindAsynchronous(ep => ep.Seriesid == Int32.Parse(show[0].Id));

            //    var coll = EpisodeStarted.Database.GetCollection<EpisodeStartedDao>("EpisodeStarted")
            //        .AsQueryable();
            //    var series = new List<EpisodeStartedDao>();
            //    if (!coll.Empty())
            //        series = coll.Where(b => b.TvMazeId.ToString() == show[0].TvMazeId.ToString() ||
            //                                 b.TmdbId.ToString() == show[0].TmdbId.ToString()).ToList();

            //    if (series.Count > 0)
            //    {
            //        var ep = _episodeStartedMapper.Map(episodeStarted);

            //        await EpisodeStarted.ReplaceOneAsync(
            //            s => (s.TvMazeId == ep.TvMazeId || s.TmdbId == ep.TmdbId) &&
            //                 s.SeasonNumber == ep.SeasonNumber &&
            //                 s.EpisodeNumber == ep.EpisodeNumber, ep);
            //    }
            //    else
            //    {
            //        var episodestarted = new EpisodeStartedDao();

            //        await EpisodeStarted.InsertOneAsync(episodestarted);
            //    }
            //}
            //else
            //{
            //    await new TvMazeParser().ImportSeries(showTitle);
            //}

            //return false;

            return(true);
        }
示例#7
0
        public async Task MarkEpisodeStarted(InternalEpisodeStartedModel internalEpisodeStartedModel, string showName)
        {
            //var isStarted = await _repo.IsSeriesStarted(episodeStartedModel);
            //var isStarted = false;
            //if (!isStarted)
            //{
            //    await _repo.MarkEpisodeStarted(episodeStartedModel);
            //}
            //else
            //{
            //    throw new InternalException(604, "Series is already started by the user.");
            //}

            var series = GetSeriesByTitle(showName);

            if (series.Result.Count != 0)
            {
                internalEpisodeStartedModel.TvMazeId = int.Parse(series.Result[0].TvMazeId);
                internalEpisodeStartedModel.TmdbId   = int.Parse(series.Result[0].TmdbId);
            }

            await _seriesRepository.MarkEpisodeStarted(internalEpisodeStartedModel);
        }
示例#8
0
        public async Task <bool> IsEpisodeStarted(InternalEpisodeStartedModel episodeStarted)
        {
            var isItStarted = await _seriesRepository.IsEpisodeStarted(episodeStarted);

            return(isItStarted);
        }
示例#9
0
        public static async Task SavePosition(string showName, int seasonNum, int episodeNum,
                                              int actualSeenSecondsFromMPC, Times elapsedTimesInMedia)
        {
            //string positionPath = "(/html/body/p)[9]";
            //string durationPath = "(/html/body/p)[11]";

            //using (WebClient client = new WebClient())
            //{
            //    string htmlString = client.DownloadString(mpcVariablesSiteUrl);
            //    HtmlDocument htmlDocument = new HtmlDocument();
            //    htmlDocument.LoadHtml(htmlString);

            //    HtmlNode position = htmlDocument.DocumentNode.SelectSingleNode(positionPath);
            //    HtmlNode duration = htmlDocument.DocumentNode.SelectSingleNode(durationPath);

            //    var pos = Regex.Split(position.InnerText, ":");
            //    var dur = Regex.Split(duration.InnerText, ":");

            //double seenSeconds = Int32.Parse(pos[0]) * 60 * 60 + Int32.Parse(pos[1]) * 60 + Int32.Parse(pos[2]);
            var seenSeconds = 0.0;

            if (elapsedTimesInMedia != null)
            {
                seenSeconds = elapsedTimesInMedia.Position;
            }
            else
            {
                if (Math.Abs(actualSeenSecondsFromMPC - elapsedTimesInMedia.SeenSeconds) < 60)
                {
                    seenSeconds = actualSeenSecondsFromMPC;
                }
            }


            //double totalSeconds = Int32.Parse(dur[0]) * 60 * 60 + Int32.Parse(dur[1]) * 60 + Int32.Parse(dur[2]);
            //double percentage = (100 / totalSeconds) * seenSeconds;

            var percentage = 100.0 / elapsedTimesInMedia.Duration * seenSeconds;

            InternalEpisodeStartedModel episode = new InternalEpisodeStartedModel
            {
                Date              = DateTime.Now,
                EpisodeNumber     = episodeNum,
                SeasonNumber      = seasonNum,
                HoursElapsed      = elapsedTimesInMedia.SeenHours,
                MinutesElapsed    = elapsedTimesInMedia.SeenMinutes,
                SecondsElapsed    = Convert.ToInt32(seenSeconds),
                WatchedPercentage = percentage

                                    //még 3 mező nincs feltöltve: userid, tmdbid, tvmazeid
            };

            if (percentage <= 98)
            {
                await UpdateStartedSeries(episode, showName);
            }
            else
            {
                await MarkRequest(new InternalMarkRequest
                {
                    //IDE HA LESZ FELHASZNÁLÓ KELL A USERID
                    //átküldés után lekell kérni a showt névszerint
                    UserId        = 1,
                    TvMazeId      = "",
                    TmdbId        = "",
                    ShowName      = showName,
                    EpisodeNumber = episodeNum,
                    SeasonNumber  = seasonNum
                });
            }
            //}
        }