Exemplo n.º 1
0
        public Download()
        {
            InitializeComponent();
            // 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();

                UserDialogs.Instance.Prompt(new PromptConfig()
                {
                    Title       = "YouTube Download",
                    CancelText  = "Cancel",
                    OkText      = "Download",
                    InputType   = InputType.Url,
                    Text        = txt,
                    Placeholder = "YouTube Link",
                    OnAction    = new Action <PromptResult>(async t => {
                        if (t.Ok)
                        {
                            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 data     = await YouTube.GetInfoAsync(v.GetUrl());
                                    double mb    = App.ConvertBytesToAny(data.Size, 5, 2);
                                    // (episodeResult.mirrosUrls[i], episodeResult.Title + ".mp4", true, "/" + GetPathFromType());
                                    //  string ppath = App.DownloadUrl(episodeResult.PosterUrl, "epP" + episodeResult.Title + ".jpg", false, "/Posters");
                                    // string mppath = App.DownloadUrl(currentMovie.title.hdPosterUrl, "hdP" + episodeResult.Title + ".jpg", false, "/TitlePosters");
                                    string mppath = v.Thumbnails.HighResUrl;
                                    string ppath  = v.Thumbnails.HighResUrl;

                                    string key = "_dpath=" + dpath + "|||_ppath=" + ppath + "|||_mppath=" + mppath + "|||_descript=" + v.Description + "|||_maindescript=" + v.Description + "|||_epCounter=" + "-1" + "|||_epId=" + v.Id + "|||_movieId=" + v.GetUrl() + "|||_title=" + v.Title + "|||_movieTitle=" + v.Title + "|||isYouTube=" + true + "|||UploadData=" + v.UploadDate.ToString() + "|||Author=" + v.Author + "|||Duration=" + v.Duration.TotalSeconds + "|||=EndAll";
                                    print("DKEY: " + key);
                                    App.SetKey("Download", v.Id, key);
                                    App.ShowToast("Download Started - " + Math.Round(mb, 1) + "MB");
                                    App.SetKey("DownloadSize", v.Id, Math.Round(mb, 2));
                                    YouTube.DownloadVideo(data, v.Title, "Download complete!", true, v.Title);
                                    // YouTube.DownloadVideo(data, v.Title);
                                }
                                catch (Exception) {
                                    App.ShowToast(errorTxt);
                                }
                            }
                        }
                    })
                });;
            };


            epView         = new MainEpisodeView();
            BindingContext = epView;

            BackgroundColor = Settings.BlackRBGColor;
        }
Exemplo 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);
            }
        }