コード例 #1
0
        async void BtnScrape_Clicked(object sender, System.EventArgs e)
        {
            try
            {
                if (!String.IsNullOrEmpty(etyURL.Text))
                {
                    lblText.Text = etyURL.Text;

                    foreach (string word in etyURL.Text.Split(' '))
                    {
                        if (word.StartsWith("http".ToLower()))
                        {
                        }
                        else if (word.StartsWith("www".ToLower()))
                        {
                            var result = await MetaScraper.GetMetaDataFromUrl(string.Format("{0}" + word, "https://"));

                            imgUrl.Source       = result.ImageUrl;
                            lblTitle.Text       = result.Title;
                            lblDescription.Text = result.Description;
                        }
                    }
                }
            }catch (Exception ex)
            {
                DisplayAlert("Error", "Not a valid URI", "OK");
            }
        }
コード例 #2
0
        // TODO: Fix. Not happy with actually calling out to (and having a dependency on) an external website,
        // but loading from file is a different call for Html Agility Pack. Might need a wrapper to enable DI.
        public void GetMetaDataFromUrl_WithUrlValid_ReturResult()
        {
            var result = MetaScraper.GetMetaDataFromUrl(VALID_URL);

            Assert.NotNull(result);
            Assert.Equal(VALID_URL_TITLE, result.Title);
        }
コード例 #3
0
        public void GetMetaDataFromUrl_WithUrlInvalid_ReturnsError()
        {
            var result = MetaScraper.GetMetaDataFromUrl(INVALID_URL);

            Assert.NotNull(result);
            Assert.True(result.HasError);
            Assert.False(result.ExternalPageError);
        }
コード例 #4
0
        async void EtyURL_TextChanged(object sender, Xamarin.Forms.TextChangedEventArgs e)
        {
            if (etyURL.Text.EndsWith(" ", StringComparison.Ordinal) && !hasFirstUrl)
            {
                var url = (DetectURLInString(etyURL.Text));
                if (!String.IsNullOrEmpty(url))
                {
                    var result = await MetaScraper.GetMetaDataFromUrl(url);

                    imgUrl.Source       = result.ImageUrl;
                    lblTitle.Text       = result.Title;
                    lblDescription.Text = result.Description;
                }
            }
        }
コード例 #5
0
        public IActionResult GetMetadata(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(NotFound());
            }

            var validatedUrl = url.ToLower();

            if (!validatedUrl.StartsWith("http://", StringComparison.Ordinal) &&
                !validatedUrl.StartsWith("https://", StringComparison.Ordinal))
            {
                validatedUrl = $"http://{validatedUrl}";
            }

            var metadata = MetaScraper.GetMetaDataFromUrl(validatedUrl);

            // Double check image URL
            metadata.ImageUrl = ValidateImageUri(metadata.ImageUrl);

            return(Json(metadata));
        }
コード例 #6
0
        public IActionResult GetMetadata(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(NotFound());
            }

            var validatedUrl = url.ToLower();

            if (!validatedUrl.StartsWith("http://", StringComparison.Ordinal) &&
                !validatedUrl.StartsWith("https://", StringComparison.Ordinal))
            {
                validatedUrl = $"http://{validatedUrl}";
            }

            // Inject api key here to prevent resolve of a service for this one value in the underlying class
            //var metadata = MetaScraper.GetUrlPreview(validatedUrl, _configuration["UrlPreviewApiKey"]);
            var metadata = MetaScraper.GetMetaDataFromUrl(validatedUrl);

            // Double check image URL
            metadata.ImageUrl = ValidateImageUri(metadata.ImageUrl);

            return(Json(metadata));
        }
コード例 #7
0
        public void GetMetaDataFromUrl_WithUrlNull_ThrowsArgumentNullException()
        {
            var exception = Assert.Throws <ArgumentNullException>(() => MetaScraper.GetMetaDataFromUrl(null));

            Assert.Equal("url", exception.ParamName);
        }
コード例 #8
0
        public override void ViewDidLoad()
        {
            nfloat h = 31.0f;
            nfloat w = View.Bounds.Width;

            base.ViewDidLoad();


            imageViewEx = new UIImageView(new CGRect(10, 100, 150, 200));
            Add(imageViewEx);

            titleLabel           = new UITextView();
            titleLabel.Frame     = new CGRect(110, 40, w - 180, 50);
            titleLabel.Font      = UIFont.SystemFontOfSize(22);
            titleLabel.Text      = "ADD NEW MOVIE";
            titleLabel.Editable  = false;
            titleLabel.TextColor = UIColor.Brown;

            View.AddSubview(titleLabel);

            tenphimLabel               = new UITextView();
            tenphimLabel.Frame         = new CGRect(170, 90, w - 180, 30);
            tenphimLabel.Font          = UIFont.SystemFontOfSize(18);
            tenphimLabel.Text          = "Movie's name:";
            tenphimLabel.Editable      = false;
            tenphimLabel.ScrollEnabled = false;
            tenphimLabel.ClipsToBounds = true;
            tenphimLabel.TextColor     = UIColor.Brown;
            //tenphimLabel.TextAlignment = UITextAlignment.Center;
            View.AddSubview(tenphimLabel);

            tenphimTextViewEx                  = new UITextView();
            tenphimTextViewEx.Frame            = new CGRect(170, 140, w - 180, 100);
            tenphimTextViewEx.TextAlignment    = UITextAlignment.Center;
            tenphimTextViewEx.Font             = UIFont.SystemFontOfSize(18);
            tenphimTextViewEx.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            // limit of up to 50 characters

            /*tenphimTextViewEx.ShouldChangeCharacters = (textField, range, replacementString) =>
             * {
             *  var newLength = textField.Text.Length + replacementString.Length - range.Length;
             *  return newLength <= 40;
             * };*/
            View.AddSubview(tenphimTextViewEx);

            sotapLabel               = new UITextView();
            sotapLabel.Frame         = new CGRect(170, 250, w - 180, 30);
            sotapLabel.Font          = UIFont.SystemFontOfSize(18);
            sotapLabel.Text          = "Episodes:";
            sotapLabel.Editable      = false;
            sotapLabel.ScrollEnabled = false;
            sotapLabel.ClipsToBounds = true;
            sotapLabel.TextColor     = UIColor.Brown;
            //tenphimLabel.TextAlignment = UITextAlignment.Center;
            View.AddSubview(sotapLabel);

            sotapTextViewEx                  = new UITextView();
            sotapTextViewEx.Frame            = new CGRect(170, 290, w - 180, 30);
            sotapTextViewEx.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            sotapTextViewEx.Font             = UIFont.SystemFontOfSize(18);
            sotapTextViewEx.TextAlignment    = UITextAlignment.Center;
            sotapTextViewEx.KeyboardType     = UIKeyboardType.NumberPad;

            /*sotapTextViewEx.ShouldChangeCharacters = (textField, range, replacementString) =>
             * {
             *  var newLength = textField.Text.Length + replacementString.Length - range.Length;
             *  return newLength <= 3;
             * };*/
            View.AddSubview(sotapTextViewEx);

            sophutLabel               = new UITextView();
            sophutLabel.Frame         = new CGRect(10, 330, w - 20, 30);
            sophutLabel.Font          = UIFont.SystemFontOfSize(18);
            sophutLabel.Text          = "Minutes watching:";
            sophutLabel.ScrollEnabled = false;
            sophutLabel.ClipsToBounds = true;
            sophutLabel.Editable      = false;
            sophutLabel.TextColor     = UIColor.Brown;
            //tenphimLabel.TextAlignment = UITextAlignment.Center;
            View.AddSubview(sophutLabel);

            sophutTextViewEx                  = new UITextView();
            sophutTextViewEx.Frame            = new CGRect(10, 370, w - 20, h);
            sophutTextViewEx.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            sophutTextViewEx.TextAlignment    = UITextAlignment.Center;
            sophutTextViewEx.Font             = UIFont.SystemFontOfSize(18);
            sophutTextViewEx.KeyboardType     = UIKeyboardType.NumberPad;

            /*sophutTextViewEx.ShouldChangeCharacters = (textField, range, replacementString) =>
             * {
             *  var newLength = textField.Text.Length + replacementString.Length - range.Length;
             *  return newLength <= 4;
             * };*/
            View.AddSubview(sophutTextViewEx);



            addbutton       = new UIButton();
            addbutton.Frame = new CGRect(10, 450, w - 20, 50);
            addbutton.SetTitle("ADD NEW MOVIE", UIControlState.Normal);
            addbutton.BackgroundColor    = UIColor.Blue;
            addbutton.Layer.CornerRadius = 5f;
            View.AddSubview(addbutton);
            addbutton.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            cancelbutton       = new UIButton();
            cancelbutton.Frame = new CGRect(10, 515, w - 20, 50);
            cancelbutton.SetTitle("CANCEL", UIControlState.Normal);
            cancelbutton.BackgroundColor    = UIColor.Red;
            cancelbutton.Layer.CornerRadius = 5f;
            View.AddSubview(cancelbutton);
            cancelbutton.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            var            urlstr = string.Empty;
            var            item   = ExtensionContext.InputItems[0];
            NSItemProvider prov   = null;

            if (item != null)
            {
                prov = item.Attachments[0];
            }
            if (prov != null)
            {
                prov.LoadItem(UTType.URL, null, (NSObject url, NSError error) =>
                {
                    if (url == null)
                    {
                        return;
                    }
                    NSUrl newUrl    = (NSUrl)url;
                    var newUrl2     = newUrl.ToString();
                    var resultSotap = Regex.Match(MetaScraper.GetMetaDataFromUrl(newUrl2).Title, @"\d+").Value;



                    //string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "ormdemo.db3");
                    db            = new SQLiteConnection(ShareLibs.GetDatabasePath());
                    var PhimmoiEx = new movDatabase();
                    InvokeOnMainThread(() =>
                    {
                        tenphimTextViewEx.Text   = MetaScraper.GetMetaDataFromUrl(newUrl2).Title;
                        sotapTextViewEx.Text     = resultSotap;
                        imageViewEx.Image        = FromUrl(MetaScraper.GetMetaDataFromUrl(newUrl2).ImageUrl);
                        addbutton.TouchUpInside += (sender, e) =>
                        {
                            PhimmoiEx.Tenphim = tenphimTextViewEx.Text;
                            try
                            {
                                PhimmoiEx.img = StoreImageEx(tenphimTextViewEx.Text);
                            }
                            catch
                            {
                            }
                            try
                            {
                                PhimmoiEx.Sotap = Convert.ToInt32(sotapTextViewEx.Text);
                            }
                            catch
                            {
                            }
                            try
                            {
                                PhimmoiEx.min = Convert.ToInt32(sophutTextViewEx.Text);
                            }
                            catch
                            {
                            }
                            PhimmoiEx.link = newUrl2;
                            db.Insert(PhimmoiEx);

                            var alert = UIAlertController.Create("Movie Mark", "Added", UIAlertControllerStyle.Alert);
                            PresentViewController(alert, true, () =>
                            {
                                DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 500000000), () =>
                                {
                                    // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
                                    ExtensionContext.CompleteRequest(new NSExtensionItem[0], null);
                                });
                            });
                        };
                        cancelbutton.TouchUpInside += (sender, e) =>
                        {
                            var alert = UIAlertController.Create("Movie Mark", "Canceled", UIAlertControllerStyle.Alert);
                            PresentViewController(alert, true, () =>
                            {
                                DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 500000000), () =>
                                {
                                    // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
                                    ExtensionContext.CompleteRequest(new NSExtensionItem[0], null);
                                });
                            });
                        };
                    });
                });
            }
        }