Esempio n. 1
0
        public Download()
        {
            InitializeComponent();
            OffBar.Source = App.GetImageSource("gradient.png"); OffBar.HeightRequest = 3; OffBar.HorizontalOptions = LayoutOptions.Fill; OffBar.ScaleX = 100; OffBar.Opacity = 0.3; OffBar.TranslationY = 9;

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

#pragma warning restore CS0162 // Unreachable code detected
            }
            try {
                baseImg.Source = App.GetImageSource("NoDownloads.png");

                bool hasDownloads = App.GetKey("Settings", "hasDownloads", false);

                baseTxt.IsVisible = !hasDownloads;
                baseImg.IsVisible = !hasDownloads;

                /*
                 * RefreshView refresh = new RefreshView() { BackgroundColor = Color.Black, RefreshColor = Color.Blue, Command = RefreshCommand };
                 * refresh.SetBinding(RefreshView.IsRefreshingProperty, new Binding(nameof(IsRefreshing)));
                 * ScrollView scrollView = new ScrollView();
                 * scrollView.Content = episodeView;
                 * refresh.Content = episodeView;*/

                // ytBtt.Source = App.GetImageSource("round_movie_white_48dp.png");
                ytBtt.Source = App.GetImageSource("ytIcon.png");

                ytrealBtt.Clicked += async(o, e) => {
                    string txt = await Clipboard.GetTextAsync();

                    string ytUrl = await ActionPopup.DisplayEntry(InputPopupResult.url, "https://youtu.be/", "Youtube link", confirmText : "Download");

                    if (!ytUrl.IsClean() || ytUrl == "Cancel")
                    {
                        return;
                    }
                    await YouTube.HandleDownload(ytUrl);
                };

                MyEpisodeResultCollection = new ObservableCollection <EpisodeResult>();
                BindingContext            = this;
                BackgroundColor           = Settings.BlackRBGColor;
                ChangeStorage();
            }
            catch (Exception _ex) {
                error(_ex);
            }
        }
Esempio n. 2
0
        public Download()
        {
            InitializeComponent();
            OffBar.Source = App.GetImageSource("gradient.png"); OffBar.HeightRequest = 3; OffBar.HorizontalOptions = LayoutOptions.Fill; OffBar.ScaleX = 100; OffBar.Opacity = 0.3; OffBar.TranslationY = 9;

            if (Settings.IS_TEST_BUILD)
            {
                return;
            }
            try {
                baseImg.Source = App.GetImageSource("NoDownloads.png");

                bool hasDownloads = App.GetKey("Settings", "hasDownloads", false);

                baseTxt.IsVisible = !hasDownloads;
                baseImg.IsVisible = !hasDownloads;

                /*
                 * RefreshView refresh = new RefreshView() { BackgroundColor = Color.Black, RefreshColor = Color.Blue, Command = RefreshCommand };
                 * refresh.SetBinding(RefreshView.IsRefreshingProperty, new Binding(nameof(IsRefreshing)));
                 * ScrollView scrollView = new ScrollView();
                 * scrollView.Content = episodeView;
                 * refresh.Content = episodeView;*/

                // ytBtt.Source = App.GetImageSource("round_movie_white_48dp.png");
                ytBtt.Source = App.GetImageSource("ytIcon.png");

                ytrealBtt.Clicked += async(o, e) => {
                    string txt = await Clipboard.GetTextAsync();

                    string ytUrl = await ActionPopup.DisplayEntry(InputPopupResult.url, "https://youtu.be/", "Youtube link", confirmText : "Download");

                    if (!ytUrl.IsClean() || ytUrl == "Cancel")
                    {
                        return;
                    }
                    await Device.InvokeOnMainThreadAsync(async() => {
                        //string ytUrl = t.Text;
                        Video v = null;
                        const string errorTxt = "Error Downloading YouTube Video";
                        try {
                            v = await YouTube.GetYTVideo(ytUrl);
                        }
                        catch (Exception) {
                            App.ShowToast(errorTxt);
                        }
                        if (v == null)
                        {
                            App.ShowToast(errorTxt);
                        }
                        else
                        {
                            try {
                                //   string dpath = YouTube.GetYTPath(v.Title);
                                var author = await YouTube.GetAuthorFromVideoAsync(v);
                                var data   = await YouTube.GetInfoAsync(v);
                                int id     = ConvertStringToInt(v.Id);


                                string vId = v.Id.Value;
                                var t      = mainCore.CreateThread(4);
                                mainCore.StartThread("Sponsorblock", () => {
                                    try {
                                        string _d = mainCore.DownloadString("https://sponsor.ajay.app/api/skipSegments?videoID=" + vId, t);
                                        if (_d != "")
                                        {
                                            var smgs = JsonConvert.DeserializeObject <List <YTSponsorblockVideoSegments> >(_d);
                                            App.SetKey("Sponsorblock", v.Id.Value.ToString(), smgs);
                                        }
                                    }
                                    catch (Exception) { }
                                });
                                double mb = App.ConvertBytesToAny(data.Size.TotalBytes, 5, 2);

                                ImageService.Instance.LoadUrl(v.Thumbnails.HighResUrl, TimeSpan.FromDays(30));                                 // CASHE IMAGE

                                DownloadHeader header = new DownloadHeader()
                                {
                                    movieType = MovieType.YouTube, id = author.Id, name = author.Title, hdPosterUrl = author.LogoUrl, posterUrl = author.LogoUrl, ogName = author.Title
                                };                                                                                                                                                                                                                                    //description = v.Description,hdPosterUrl=v.Thumbnails.HighResUrl, };//ConvertTitleToHeader(title);

                                string filePath = YouTube.DownloadVideo(data, v.Title, data, v, id, header, true);

                                //  YouTube.client.Videos.ClosedCaptions.GetManifestAsync().Result.Tracks.
                                // YouTube.client.Videos.ClosedCaptions.DownloadAsync(v.,)

                                App.ShowToast("YouTube download started");
                                App.SetKey(nameof(DownloadHeader), "id" + header.RealId, header);
                                App.SetKey(nameof(DownloadEpisodeInfo), "id" + id, new DownloadEpisodeInfo()
                                {
                                    dtype = DownloadType.YouTube, source = v.Url, description = v.Description, downloadHeader = header.RealId, episode = -1, season = -1, fileUrl = filePath, id = id, name = v.Title, hdPosterUrl = v.Thumbnails.HighResUrl
                                });
                                App.SetKey("DownloadIds", id.ToString(), id);
                                await YouTube.DownloadSubtitles(v, filePath.Replace(".mp4", ".srt"));
                            }
                            catch (Exception _ex) {
                                print("MAINERROR:: " + _ex);
                                App.ShowToast(errorTxt);
                            }
                        }
                    });
                };

                MyEpisodeResultCollection = new ObservableCollection <EpisodeResult>();
                BindingContext            = this;
                BackgroundColor           = Settings.BlackRBGColor;
                ChangeStorage();
            }
            catch (Exception _ex) {
                error(_ex);
            }
        }