Пример #1
0
        public DownloadHandler(BLTEStream blte)
        {
            if (CASContainer.BuildConfig["download-size"][0] != null && blte.Length != long.Parse(CASContainer.BuildConfig["download-size"][0]))
            {
                CASContainer.Settings?.Logger.LogAndThrow(Logging.LogType.Critical, "Download File is corrupt.");
            }

            using (var br = new BinaryReader(blte))
            {
                Header = new DownloadHeader()
                {
                    Header       = br.ReadBytes(2),
                    Version      = br.ReadByte(),
                    ChecksumSize = br.ReadByte(),
                    Unknown      = br.ReadByte(),
                    NumEntries   = br.ReadUInt32BE(),
                    NumTags      = br.ReadUInt16BE(),
                };

                // entries
                for (int i = 0; i < Header.NumEntries; i++)
                {
                    var entry = new DownloadEntry()
                    {
                        Unknown     = Header.Version > 1 ? br.ReadByte() : (byte)0,                     // new V2 field
                        Hash        = new MD5Hash(br),
                        FileSize    = br.ReadUInt40BE(),
                        Stage       = br.ReadByte(),
                        UnknownData = br.ReadBytes(4)
                    };

                    Entries.Add(entry);
                }

                // tags
                int numMaskBytes = ((int)Header.NumEntries + 7) / 8;
                for (int i = 0; i < Header.NumTags; i++)
                {
                    var tag = new DownloadTag()
                    {
                        Name    = br.ReadCString(),
                        Type    = br.ReadUInt16BE(),
                        BitMask = new BoolArray(br.ReadBytes(numMaskBytes))
                    };

                    Tags.Add(tag);
                }

                EncodingMap = blte.EncodingMap.ToArray();

                endofStageIndex = new int[]                 // store last indice of each stage
                {
                    Entries.FindLastIndex(x => x.Stage == 0),
                    Entries.FindLastIndex(x => x.Stage == 1)
                };
            }

            blte?.Dispose();
        }
Пример #2
0
 public DownloadHandler()
 {
     Header      = new DownloadHeader();
     EncodingMap = new[]
     {
         new EncodingMap(EncodingType.None, 6),
         new EncodingMap(EncodingType.None, 6),
         new EncodingMap(EncodingType.ZLib, 9)
     };
 }
Пример #3
0
        public static async Task HandleDownload(string ytUrl)
        {
            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 _ex) {
                    error(_ex);
                    App.ShowToast(errorTxt);
                    return;
                }
                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, id);

                        //  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);
                    }
                }
            });
        }
Пример #4
0
        public DownloadHandler(BLTEStream blte)
        {
            if (CASContainer.BuildConfig["download-size"][0] != null && blte.Length != long.Parse(CASContainer.BuildConfig["download-size"][0]))
            {
                CASContainer.Settings?.Logger.LogAndThrow(Logging.LogType.Critical, "Download File is corrupt.");
            }

            using (var br = new BinaryReader(blte))
            {
                Header = new DownloadHeader()
                {
                    Header       = br.ReadBytes(2),
                    Version      = br.ReadByte(),
                    ChecksumSize = br.ReadByte(),
                    HasChecksum  = br.ReadByte(),
                    NumEntries   = br.ReadUInt32BE(),
                    NumTags      = br.ReadUInt16BE(),
                };

                if (Header.Version >= 2)
                {
                    Header.NumFlags = br.ReadByte();
                }

                if (Header.Version >= 3)
                {
                    // TODO do we have a version 3 file to test with?
                    //Header.BasePriority = br.ReadByte();
                    //Header.Unknown_0D = br.ReadBytes(3);
                    throw new NotImplementedException("Download file versions newer than 2 are not supported.");
                }

                // entries
                for (int i = 0; i < Header.NumEntries; i++)
                {
                    var entry = new DownloadEntry()
                    {
                        EKey     = new MD5Hash(br),
                        FileSize = br.ReadUInt40BE(),
                        Priority = br.ReadByte()
                    };

                    if (Header.HasChecksum != 0)
                    {
                        entry.Checksum = br.ReadUInt32BE();
                    }

                    if (Header.Version >= 2)
                    {
                        entry.Flags = (DownloadFlags[])(object)br.ReadBytes(Header.NumFlags);
                    }

                    Entries.Add(entry);
                }

                // tags
                int numMaskBytes = ((int)Header.NumEntries + 7) / 8;
                for (int i = 0; i < Header.NumTags; i++)
                {
                    var tag = new DownloadTag()
                    {
                        Name    = br.ReadCString(),
                        Type    = br.ReadUInt16BE(),
                        BitMask = new BoolArray(br.ReadBytes(numMaskBytes))
                    };

                    // We need to remove trailing bits from the padded byte array.
                    while (tag.BitMask.Count != Entries.Count)
                    {
                        tag.BitMask.RemoveAt(tag.BitMask.Count - 1);
                    }

                    Tags.Add(tag);
                }

                EncodingMap = blte.EncodingMap.ToArray();

                endofStageIndex = new int[]                 // store last indice of each stage
                {
                    Entries.FindLastIndex(x => x.Priority == 0),
                    Entries.FindLastIndex(x => x.Priority == 1)
                };
            }

            blte?.Dispose();
        }
Пример #5
0
        public static string DownloadVideo(MuxedStreamInfo mediaStreamInfos, string name, MuxedStreamInfo info, Video v, int id, DownloadHeader header, bool isNotification = false)
        {
            ImageService.Instance.LoadUrl(v.Thumbnails.HighResUrl, TimeSpan.FromDays(30));             // CACHE IMAGE

            string fileUrl = DownloadHandleIntent(MovieType.YouTube, -1, -1, v.Title, v.Author, id, new List <BasicMirrorInfo>()
            {
                new BasicMirrorInfo()
                {
                    name = info.VideoQualityLabel, mirror = info.Url
                }
            }, true, true, false, v.Thumbnails.HighResUrl, "{name}\n");                                                                                                                                                                                                             //isMovie ? "{name}\n" : ($"S{season}:E{episode} - " + "{name}\n"));

            return(fileUrl);
        }
Пример #6
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);
            }
        }
Пример #7
0
        public static string DownloadVideo(MuxedStreamInfo mediaStreamInfos, string name, MuxedStreamInfo info, Video v, int id, DownloadHeader header, bool isNotification = false)
        {
            string rootPath = App.GetDownloadPath("", "/YouTube");

            if (rootPath.EndsWith("\\"))
            {
                rootPath = rootPath[0..^ 1];