Beispiel #1
0
        // for now it only downloads ifunny
        public bool TryDownloadFile(string input, out Exception ex)
        {
            ex = null;
            try
            {
                var parser = ParserFinder.FindParser(this.ctx, input, out var url);

                if (parser == null)
                {
                    Toast.MakeText(ctx, "Incompatible site.", ToastLength.Short).Show();
                    return(false);
                }

                parser.TryFetchVideoUrl(url, out string[] urls);

                foreach (var _url in urls)
                {
                    var    uri           = Android.Net.Uri.Parse(_url);
                    var    request       = new DownloadManager.Request(uri);
                    string fileExtension = MimeTypeMap.GetFileExtensionFromUrl(_url);
                    string filename      = $"download.{fileExtension}";

                    request.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads,
                                                              $"DLBuddy/{parser.GetParserName()}/{filename}");

                    request.SetVisibleInDownloadsUi(true);
                    request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
                    request.SetTitle($"DLBuddy - {parser.GetParserName()}");
                    manager.Enqueue(request);
                }


                return(true);
            }
            catch (Exception e)
            {
                ex = e;
                return(false);
            }
        }
Beispiel #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            if (this.Intent.Action == "android.intent.action.SEND")
            {
                // if sharing, hide UI immediately. it's ok bud
                Finish();
                Toast.MakeText(this, "Attempting download...", ToastLength.Short).Show();

                var dl = new Downloader(this);

                var uri = this.Intent.Extras.GetString("android.intent.extra.TEXT");
                if (dl.TryDownloadFile(uri, out var e))
                {
                    Toast.MakeText(this, $"Enqueued download.", ToastLength.Short).Show();
                }
                else
                {
                    Toast.MakeText(this, $"Failed downloading. {e?.Message}", ToastLength.Short).Show();
                }
                // use libvideo for youtube
            }

            this.FindViewById <Button>(Resource.Id.button1).Click += MainActivity_Click;

            this.FindViewById <TextView>(Resource.Id.textView3).Text = "Supported apps: " + ParserFinder.ListParsers();
        }