예제 #1
0
        private void ViewCell_Tapped(object sender, EventArgs e)
        {
            ReviewItem episodeResult = (ReviewItem)(((ViewCell)sender).BindingContext);

            MyEpisodeResultCollection.Remove(episodeResult);
            episodeResult.IsExpanded = !episodeResult.IsExpanded;
            MyEpisodeResultCollection.Insert(episodeResult.index, episodeResult);
            var _e = MyEpisodeResultCollection.ToList();

            Device.BeginInvokeOnMainThread(() => {
                MyEpisodeResultCollection.Clear();
                for (int i = 0; i < _e.Count; i++)
                {
                    MyEpisodeResultCollection.Add((ReviewItem)_e[i].Clone());
                }
                episodeView.SelectedItem = null;

                SetHeight();
            });
        }
예제 #2
0
        void TapCell(int index)
        {
            ReviewItem episodeResult = MyEpisodeResultCollection[index];

            MyEpisodeResultCollection.Remove(episodeResult);
            episodeResult.IsExpanded = !episodeResult.IsExpanded;
            MyEpisodeResultCollection.Insert(episodeResult.index, episodeResult);
            var _e = MyEpisodeResultCollection.ToList();

            Device.BeginInvokeOnMainThread(() => {
                MyEpisodeResultCollection.Clear();
                for (int i = 0; i < _e.Count; i++)
                {
                    MyEpisodeResultCollection.Add((ReviewItem)_e[i].Clone());
                }
                episodeView.SelectedItem = null;

                SetHeight();
            });
        }
예제 #3
0
        void UpdateDownloaded()
        {
            print("UPDATE DOWNLOAD!!");
            if (inProgress)
            {
                return;
            }

            if (Settings.IS_TEST_BUILD)
            {
#pragma warning disable CS0162 // Unreachable code detected
                return;

#pragma warning restore CS0162 // Unreachable code detected
            }

            try {
                object clock = new object();

                Thread mThread = new Thread(() => {
                    if (inProgress)
                    {
                        return;
                    }
                    inProgress = true;
                    Thread.Sleep(100);

                    try {
                        //string[] keys = App.GetKeys<string>("DownloadIds");
                        string[] keysPaths = App.GetKeysPath("DownloadIds");

                        downloads.Clear();
                        downloadHeaders.Clear();
                        downloadHelper.Clear();

                        List <int> headerRemovers           = new List <int>();
                        Dictionary <int, bool> validHeaders = new Dictionary <int, bool>();

                        Parallel.For(0, keysPaths.Length, (i) => {
                            try {
                                // Thread.Sleep(1000);

                                //  for (int i = 0; i < keys.Count; i++) {
                                int id   = App.GetKey <int>(keysPaths[i], 0);
                                var info = App.GetDownloadInfo(id);

                                //if (!downloads.ContainsKey(id)) {
                                lock (clock) {
                                    downloads[id] = info;
                                }
                                //}
                                if (info.state.totalBytes == 0 && info.state.bytesDownloaded != 1)
                                {
                                    print("REMOVE HEADER INFO ID BC 0 data");
                                    RemoveDownloadCookie(id);
                                    App.UpdateDownload(id, 2);
                                    headerRemovers.Add(info.info.downloadHeader);
                                }
                                else
                                {
                                    int headerId = info.info.downloadHeader;
                                    print("HEADERSTAET::" + headerId);
                                    lock (clock) {
                                        validHeaders[headerId] = true;
                                    }
                                    bool containsKey;
                                    lock (clock) {
                                        containsKey = downloadHeaders.ContainsKey(headerId);
                                    }

                                    if (!containsKey)
                                    {
                                        var header = App.GetDownloadHeaderInfo(headerId);
                                        lock (clock) {
                                            downloadHeaders[headerId] = header;
                                        }
                                    }
                                    lock (clock) {
                                        bool containsHelperKey = downloadHelper.ContainsKey(headerId);

                                        if (!containsHelperKey)
                                        {
                                            downloadHelper[headerId] = new DownloadHeaderHelper()
                                            {
                                                infoIds = new List <int>()
                                                {
                                                    id
                                                }, bytesUsed = new List <long>()
                                                {
                                                    info.state.bytesDownloaded
                                                }, totalBytesUsed = new List <long>()
                                                {
                                                    info.state.totalBytes
                                                }
                                            };
                                        }
                                        else
                                        {
                                            var helper = downloadHelper[headerId];
                                            helper.infoIds.Add(id);
                                            helper.totalBytesUsed.Add(info.state.totalBytes);
                                            helper.bytesUsed.Add(info.state.bytesDownloaded);
                                            downloadHelper[headerId] = helper;
                                        }
                                    }
                                }
                            }
                            catch (Exception _ex) {
                                error("ERROR WHILE DOWNLOADLOADING::" + _ex);
                            }
                        });

                        for (int i = 0; i < headerRemovers.Count; i++)
                        {
                            if (!validHeaders.ContainsKey(headerRemovers[i]))
                            {
                                RemoveDownloadCookie(null, headerRemovers[i]);
                            }
                        }

                        // ========================== SET VALUES ==========================

                        //   List<EpisodeResult> eps = new List<EpisodeResult>();
                        var ckeys             = downloadHeaders.Keys.OrderBy(t => t).ToList();
                        EpisodeResult[] epres = new EpisodeResult[int.Parse(ckeys.Count.ToString())];
                        Parallel.For(0, ckeys.Count, i => {
                            int key;
                            lock (clock) {
                                key = ckeys[i];
                            }
                            // });
                            //  Parallel.ForEach(, key => {
                            //  foreach (var key in downloadHeaders.Keys) {
                            DownloadHeader val;
                            DownloadHeaderHelper helper;
                            lock (clock) {
                                val    = downloadHeaders[key];
                                helper = downloadHelper[key];
                            }

                            EpisodeResult ep = new EpisodeResult()
                            {
                                Title = val.name, PosterUrl = val.hdPosterUrl, Description = App.ConvertBytesToAny(helper.TotalBytes, 0, 2) + " MB", Id = key
                            };
                            ep.ExtraColor = Settings.ItemBackGroundColor.ToHex();

                            if (val.movieType == MovieType.TVSeries || val.movieType == MovieType.Anime || val.movieType == MovieType.YouTube)
                            {
                                int count      = helper.infoIds.Count;
                                ep.Description = count + $" {(val.movieType == MovieType.YouTube ? "Video" : "Episode")}{(count > 1 ? "s" : "")} | " + ep.Description;

                                int downloadingRn = 0;
                                foreach (var id in helper.infoIds)
                                {
                                    switch (downloads[id].state.state)
                                    {
                                    case App.DownloadState.Downloading:
                                        downloadingRn++;
                                        break;

                                    case App.DownloadState.Downloaded:
                                        break;

                                    case App.DownloadState.NotDownloaded:
                                        break;

                                    case App.DownloadState.Paused:
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                ep.ExtraDescription = downloadingRn == 0 ? "" : $"Downloading {downloadingRn} of {count}";                                  //extraString + (info.state.state == App.DownloadState.Downloaded ? "" : $" {(int)info.state.ProcentageDownloaded}%");
                            }

                            if (val.movieType == MovieType.Movie || val.movieType == MovieType.AnimeMovie)
                            {
                                var info = downloads[helper.infoIds[0]];

                                ep.Description     = (info.state.state == App.DownloadState.Downloaded ? "" : App.ConvertBytesToAny(helper.Bytes, 0, 2) + " MB of ") + ep.Description;
                                string extraString = GetExtraString(info.state.state);

                                ep.ExtraDescription = extraString + (info.state.state == App.DownloadState.Downloaded ? "" : $" {(int)info.state.ProcentageDownloaded}%");
                            }
                            else if (val.movieType == MovieType.YouTube)
                            {
                            }
                            else if (val.movieType == MovieType.TVSeries)
                            {
                                // redirect to real
                            }
                            else if (val.movieType == MovieType.Anime)
                            {
                                // redirect to real
                            }
                            ep.Episode = ConvertToSortOrder(val.movieType) * 1000 + i;
                            lock (clock) {
                                epres[i] = ep;
                            }
                        });

                        var _epres = ((EpisodeResult[])epres.Clone()).OrderBy(t => t.Episode).ToArray();                         // MOVIE -> ANIMEMOVIE -> TV-SERIES -> ANIME -> YOUTUBE

                        App.SetKey("Settings", "hasDownloads", _epres.Length != 0);

                        bool noDownloads = _epres.Length == 0;
                        Device.BeginInvokeOnMainThread(() => {
                            MyEpisodeResultCollection.Clear();
                            foreach (var ep in _epres)
                            {
                                ep.TapComThree = new Command(async() => {
                                    await HandleEpisodeAsync(ep);
                                    episodeView.SelectedItem = null;
                                });
                                try {
                                    MyEpisodeResultCollection.Add(ep);
                                }
                                catch (Exception _ex) {
                                    error("FATAL EX: " + _ex);
                                }
                            }
                            episodeView.FadeTo(noDownloads ? 0 : 1, 200, Easing.SinOut);

                            baseTxt.IsVisible = noDownloads;
                            baseImg.IsVisible = noDownloads;
                            SetHeight();
                        });
                    }
                    catch (Exception _ex) {
                        error(_ex);
                    }
                    finally {
                        inProgress = false;
                    }
                })
                {
                    Name = "EpisodeThread"
                };
                mThread.Start();
            }
            catch (Exception _ex) {
                error(_ex);
            }

            /*
             * foreach (var dload in downloads.Values) {
             * if (dload.info.dtype == App.DownloadType.YouTube) {
             * // ADD YOUTUBE EPISODE
             * }
             * else {
             *
             * }
             * }*/
        }
예제 #4
0
        void UpdateEpisodes()
        {
            var bgColor = Settings.ItemBackGroundColor.ToHex();

            MyEpisodeResultCollection.Clear();
            try {
                var header = Download.downloadHeaders[currentId];
                var helper = Download.downloadHelper[currentId];
                // App.GetDownloadHeaderInfo(currentId);
                List <EpisodeResult> activeEpisodes = new List <EpisodeResult>();

                foreach (var key in helper.infoIds)
                {
                    var info = App.GetDownloadInfo(key);                    //Download.downloads[key];
                    if (info != null)
                    {
                        Download.downloads[key] = info;
                        if (info.state.totalBytes == 0 && info.state.bytesDownloaded != 1)
                        {
                            Download.RemoveDownloadCookie(key);
                        }
                        else
                        {
                            int ep = info.info.episode;
                            int ss = info.info.season;

                            string fileUrl  = info.info.fileUrl;
                            string fileName = info.info.name;

                            int dloaded = (int)info.state.ProcentageDownloaded;
                            // string extra = (info.state.state == App.DownloadState.Downloaded ? "" : App.ConvertBytesToAny(info.state.bytesDownloaded, 0, 2) + " MB of " + App.ConvertBytesToAny(info.state.totalBytes, 0, 2) + " MB");
                            string extra = $" {dloaded }%";
                            //.TapCom = new Command(async (s) => {
                            long   pos;
                            long   len;
                            double _progress = 0;
                            if ((pos = App.GetViewPos(info.info.id)) > 0)
                            {
                                if ((len = App.GetViewDur(info.info.id)) > 0)
                                {
                                    _progress = (double)pos / (double)len;
                                }
                            }
                            var dPlaySource = App.GetImageSource("nexflixPlayBtt.png");

                            activeEpisodes.Add(new EpisodeResult()
                            {
                                OgTitle          = info.info.name,
                                ExtraColor       = bgColor,
                                ExtraDescription = $"{Download.GetExtraString(info.state.state)}{((info.state.state == App.DownloadState.Downloaded || dloaded == -1) ? "" : extra)}",
                                Title            = (ep != -1 ? $"S{ss}:E{ep} " : "") + info.info.name,
                                Description      = info.info.description,
                                Episode          = ep,
                                Season           = ss,
                                Id        = info.info.id,
                                PosterUrl = info.info.hdPosterUrl,
                                Progress  = _progress,
                                TapCom    = new Command(async(s) => {
                                    if (info.info.dtype == App.DownloadType.Normal)
                                    {
                                        MovieResult.SetEpisode("tt" + info.info.id);
                                    }
                                    if (MainChrome.IsConnectedToChromeDevice)
                                    {
                                        await Download.ChromeCastDownloadedFile(info.info.id);
                                    }
                                    else
                                    {
                                        Download.PlayDownloadedFile(info);
                                    }

                                    //Download.PlayDownloadedFile(fileUrl, fileName, info.info.episode, info.info.season, info.info.episodeIMDBId, info.info.source);
                                    // Download.PlayVLCFile(fileUrl, fileName, info.info.id.ToString());
                                }),
                                DownloadPlayBttSource = dPlaySource
                            });
                        }
                    }
                }

                activeEpisodes = activeEpisodes.OrderBy(t => (t.Episode + t.Season * 1000)).ToList();
                for (int i = 0; i < activeEpisodes.Count; i++)
                {
                    int _id = i;
                    activeEpisodes[i].TapComThree = new Command(async() => {
                        await HandleEpisode(MyEpisodeResultCollection[_id]);
                    });
                    MyEpisodeResultCollection.Add(activeEpisodes[i]);
                }

                episodeView.FadeTo(1, 200, Easing.SinOut);
            }
            catch (Exception _ex) {
                print("EXUpdateDEpisodes::: " + _ex);
            }
            SetHeight();

            if (MyEpisodeResultCollection.Count == 0)
            {
                Navigation.PopModalAsync();
            }
        }
예제 #5
0
        void TryGetNewReviews(bool firstTime = false, int tryc = 0)
        {
            if (tryc >= 5)
            {
                return;
            }
            if (holder.isSearchingforReviews)
            {
                return;
            }
            if (!firstTime && !holder.ajaxKey.IsClean())
            {
                return;
            }
            holder.isSearchingforReviews = true;



            TempThread tempThred = mainCore.CreateThread(9);

            mainCore.StartThread("Reviews Thread", () => {
                try {
                    var h = mainCore.GetReview(holder, mainId);
                    if (h != null)
                    {
                        holder = (ReviewHolder)h;
                    }
                    else
                    {
                        holder.ajaxKey = "";
                    }
                    //if (!GetThredActive(tempThred)) { return; }; // COPY UPDATE PROGRESS
                }
                finally {
                    mainCore.JoinThred(tempThred);
                    if (holder.reviews != null)
                    {
                        Device.BeginInvokeOnMainThread(() => {
                            MyEpisodeResultCollection.Clear();
                            int index = 0;
                            foreach (var rew in holder.reviews)
                            {
                                MyEpisodeResultCollection.Add(new ReviewItem()
                                {
                                    Author = rew.author, Date = rew.date, Rating = $"★ {rew.rating}", SpoilerText = rew.containsSpoiler ? "Contains Spoilers" : "", Text = rew.text, Title = rew.title, IsExpanded = false, index = index
                                });
                                index++;
                            }
                            SetHeight();
                            if (firstTime)
                            {
                                episodeView.FadeTo(1, 200);
                                MainLoading.IsEnabled = false;
                                MainLoading.IsVisible = false;
                            }
                            holder.isSearchingforReviews = false;
                        });
                    }
                    if (holder.reviews == null)
                    {
                        holder.isSearchingforReviews = false;
                        TryGetNewReviews(firstTime, tryc: ++tryc);
                    }

                    holder.isSearchingforReviews = false;
                }
            });
        }