Youtube Keywords/Tags etc. abfragen und in Textbox ausgeben

  • VB.NET

Es gibt 9 Antworten in diesem Thema. Der letzte Beitrag () ist von Radinator.

    Youtube Keywords/Tags etc. abfragen und in Textbox ausgeben

    Hallo!

    Ich würde gerne ein Programm erstellen in VB.net.

    Anforderungen:
    • ein Youtube-Link soll in eine Textbox (txtLink) eingefügt werden
    • durch einen Button (btnSubmit) soll folgendes ausgeführt werden:
      • in Textbox 2 (txtTitle) soll der Name des Videos stehen
      • in Textbox 3 (txtDescr) soll die Beschreibung des Videos stehe
      • in Textbox 4 (txtTags) sollen die Tags/Keywords des Videos stehen

    Beispielvideo:

    XML-Quellcode

    1. [i]https://www.youtube.com/watch?v=YE7VzlLtp-4[/i]


    Seitenquelltext:

    XML-Quellcode

    1. [i]view-source:https://www.youtube.com/watch?v=YE7VzlLtp-4[/i]


    Aus dem Quelltext:
    Name des Videos

    HTML-Quellcode

    1. <meta property="og:title" content="Big Buck Bunny">


    Beschreibung

    HTML-Quellcode

    1. <p id="eow-description" class="" >Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.<br /><br />Licensed under the Creative Commons Attribution license<br /><br /><a href="http://www.bigbuckbunny.org/" class=" yt-uix-servicelink " data-url="http://www.bigbuckbunny.org/" data-servicelink="CDEQ6TgiEwjTkruaga7PAhUJxBYKHTggDmIo-B0" target="_blank" rel="nofollow">http://www.bigbuckbunny.org/</a>


    Keywords/Tags

    HTML-Quellcode

    1. "keywords":"Animation,CGI,Big,Buck,Bunny,Blender,3D,Creative,Commons,blender,open,movie,content,cartoon,animated,animation art"



    Leider haben nicht alle 3 das gleiche Format, also wie beim Titel zum Beispiel: <meta property="og:title"="">
    Ich weiß daher leider nicht wie ich das ganze realisieren soll. Bin für jede Hilfe dankbar. :)

    EDIT: Benutze jetzt die Youtube Data Api. Bekomme als Rückgabewert eine JSON Datei.

    So sieht das ganze aus:

    XML-Quellcode

    1. ​{
    2. "items": [
    3. {
    4. "id": "YE7VzlLtp-4",
    5. "snippet": {
    6. "channelId": "UCSMOQeBJ2RAnuFungnQOxLg",
    7. "title": "Big Buck Bunny",
    8. "description": "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\r\n\r\nLicensed under the Creative Commons Attribution license\r\n\r\nhttp://www.bigbuckbunny.org/",
    9. "tags": [
    10. "Animation",
    11. "CGI",
    12. "Big",
    13. "Buck",
    14. "Bunny",
    15. "Blender",
    16. "3D",
    17. "Creative",
    18. "Commons",
    19. "blender",
    20. "open",
    21. "movie",
    22. "content",
    23. "cartoon",
    24. "animated",
    25. "animation art"
    26. ]
    27. }
    28. }
    29. ]
    }

    Wie lese ich das ganze aus dieser Datei aus?

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „nikexo“ ()

    Du könntest dir mal die Klasse HtmlDocument aus dem Namespace System.Windows.Forms ansehen.
    Mit der kannst du eine Webseite laden und per DOM auslesen (wenn du etwa ein Element wie die Description des Videos brauchst, dann kannst du über document.GetElementByID("eow-description") eine Instanz des entsprechenden HtmlElements erhalten. Dies kannst du dann auslesen.

    Lg Radinator
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell

    nikexo schrieb:

    wie mache ich das mit den Keywords?

    VB.NET-Quellcode

    1. Public Class Form1
    2. Dim WithEvents webBrowser As WebBrowser
    3. Dim elements As List(Of String)
    4. Public Sub New()
    5. InitializeComponent()
    6. Me.webBrowser = New WebBrowser()
    7. AddHandler Me.webBrowser.DocumentCompleted, AddressOf webBrowser_DocumentComplete
    8. Me.elements = New List(Of String)()
    9. End Sub
    10. Private Sub webBrowser_DocumentComplete(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
    11. Dim doc = Me.webBrowser.Document
    12. Dim metaElements = doc.GetElementsByTagName("meta")
    13. Dim keywordElement = metaElements.GetElementsByName("keywords")(0)
    14. Dim keywords = keywordElement.OuterHtml 'leider liest das die komplette Zeile aus, d.h.: hier musst du noch ein bisshcen tricksen
    15. Me.elements = keywords.Split(","c).ToList()
    16. Me.lbKeywords.DataSource = Me.elements 'lbKeywords ist eine Listbox
    17. End Sub
    18. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    19. Me.webBrowser.Navigate("https://www.youtube.com/watch?v=YE7VzlLtp-4")
    20. End Sub
    21. End Class


    nikexo schrieb:

    Wie lese ich das ganze aus dieser Datei aus?
    Verwende das NuGet Paket oder genauer gesagt die Libary Json.NET von Newtonsoft. Bilde dir den Inhalt des Json Strings mit Klassen nach und mach ein Newtonsoft.Json.JsonConvert.DeserializeObject<DeineKlasse>(jsonString). Dann kannst du auch typensicher auf die Daten zugreifen
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Ich hab nur einen lokale Instanz verwendet, die nicht auf dem UI erscheint.
    Warum verwendest du die nicht (gerne)?
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Schau in dem andern Post nach, da hab ich dir des mal beschrieben. Was du noch machen musst, ist aus dem IEnumerable(Of String) die einzelen Elemente zu extrahieren und in die Boxen zu bringen.

    Wobei: Ich mein ich kenn dein Programm ned, aber ich könnte mir vorstellen, dass du besser beraten wärst, wenn du nicht versuchtst, die Tags in verschiedene Textboxen zu packen, sondern in eine Listendarstellung (ListView oder ListBox) packst.
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    Ja dann ist das ganz einfach. Entweder du machst das mit LINQ und dem Select Befehl oder du verwendest String.Join. Der gibst du das Trennzeichen - in deinem Fall den Bindestrich - und das Array der Tags mit. Hinten kommt dann dein Ergebnis raus.
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell