-
Oct 24th, 2020, 07:41 PM
#1
Thread Starter
Lively Member
How to get YouTube PlayList video links.
Hi, I am trying to create a simple tool that will save the link and title from my playlist as many times a video is being deleted and there is no way to retrieve the name of it. Such a pity..
So, I've been googling a lot and there is a way using YouTube Api.
I'd like to make it easier and my main idea was to get playlist list html, but since videos links are not formatted as links, I have to skip this idea.
Endeed the html for every video in the videos list in playlist is:
Code:
{"videoId":"j6QkVTx2d88","thumbnail":{"thumbnails":[{"url":"https://i.ytimg.com/vi/j6QkVTx2d88/hqdefault.jpg?sqp=-oaymwEYCKgBEF5IVfKriqkDCwgBFQAAiEIYAXAB\u0026rs=AOn4CLCIkWbekWo0sw5Ck8jcB5KpW6u_dA","width":168,"height":94},{"url":"https://i.ytimg.com/vi/j6QkVTx2d88/hqdefault.jpg?sqp=-oaymwEYCMQBEG5IVfKriqkDCwgBFQAAiEIYAXAB\u0026rs=AOn4CLB9LSSNe63WE--MINkBx1O400nCvA","width":196,"height":110},{"url":"https://i.ytimg.com/vi/j6QkVTx2d88/hqdefault.jpg?sqp=-oaymwEZCPYBEIoBSFXyq4qpAwsIARUAAIhCGAFwAQ==\u0026rs=AOn4CLA6fL6ji2ouMF9lYjOQEXTkbn7XIw","width":246,"height":138},{"url":"https://i.ytimg.com/vi/j6QkVTx2d88/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==\u0026rs=AOn4CLA0TpWD5sBE_Os4RjHmhlqIlfjpjA","width":336,"height":188}]},"title":{"runs":[{"text":"Peter Tosh - Legalize It"}],"accessibility":{"accessibilityData":{"label":"Peter Tosh - Legalize It di Bondade é Nosso Hábito 8 anni fa 4 minuti e 46 secondi"}}},"index":{"simpleText":"1"},"shortBylineText":{"runs":[{"text":"Bondade é Nosso Hábito","navigationEndpoint":{"clickTrackingParams":"CEcQxjQYACITCKu_rqefzuwCFTPASQcdz2IKWg==","commandMetadata":{"webCommandMetadata":{"url":"/user/Bruno12170","webPageType":"WEB_PAGE_TYPE_CHANNEL","rootVe":3611}},"browseEndpoint":{"browseId":"UCY1IJY2IYNVfD7R-JbgQGbQ","canonicalBaseUrl":"/user/Bruno12170"}}}]},"lengthText":{"accessibility":{"accessibilityData":{"label":"4 minuti e 46 secondi"}},"simpleText":"4:46"},"navigationEndpoint":{"clickTrackingParams":"CEcQxjQYACITCKu_rqefzuwCFTPASQcdz2IKWjIKcGxwcF92aWRlb1okVkxQTDRfRHg4OGRwdTdlcGZINnlid3FKcGY5dUwydEFsMzY4mgEDEPos","commandMetadata":{"webCommandMetadata":{"url":"/watch?v=j6QkVTx2d88\u0026list=PL4_Dx88dpu7epfH6ybwqJpf9uL2tAl368\u0026index=1","webPageType":"WEB_PAGE_TYPE_WATCH","rootVe":3832}},"watchEndpoint":
The 3 string in red are what I would like to extract.
So, I tried with the last one using:
Code:
Dim textafter As String = """,""webPageType"
Dim textbefore As String = """url"":""/watch?v="
Dim startPosition As Integer = RichTextBox1.Text.IndexOf(textbefore)
startPosition += textbefore.Length
Dim endPosition As Integer = RichTextBox1.Text.IndexOf(textafter, startPosition)
Dim textFound As String = RichTextBox1.Text.Substring(startPosition, endPosition - startPosition)
RichTextBox1.AppendText(textFound)
This code output is : "j6QkVTx2d88\u0026list=PL4_Dx88dpu7epfH6ybwqJpf9uL2tAl368\u0026index=1" as it is supposed to do. But in the playlist page, there are obviously more than one video. How can I use For each Loop in this case and Is it possible to extract videoId, text(title) and url all together using my code? Thanks
-
Oct 24th, 2020, 10:07 PM
#2
Re: How to get YouTube PlayList video links.
Are you aware that that data is in JSON format? That is probably THE most common format for exchanging data with web APIs these days. I suggest that you do a bit of research on JSON and working with it in .NET. There are tools to work with it as objects so you don't have to resort to nasty string manipulation.
-
Oct 25th, 2020, 12:45 PM
#3
Thread Starter
Lively Member
Re: How to get YouTube PlayList video links.
You are right and this is new to me.
Is there a way to see it formatted while I'm looking to the source code?
Anyway I tried with 3 different things:
Code:
Dim json As String = RichTextBox1.Text
Dim ser As JObject = JObject.Parse(json)
Dim data As List(Of JToken) = ser.Children().ToList
For Each item As JProperty In data
item.CreateReader()
For Each msg As JObject In item.Values
Dim first_name As String = msg("Text")
Dim last_name As String = msg("url")
Next
Next
Code:
Dim json As JObject = JObject.Parse(Me.RichTextBox1.Text)
MsgBox(json.SelectToken("title").SelectToken("text"))
Code:
Dim o As JObject = JObject.Parse("{""title"": {
""runs"": [
{
""text"": ""Peter Tosh - Legalize It""
}
],
""accessibility"": {
""accessibilityData"": {
""label"": ""Peter Tosh - Legalize It by Bondade é Nosso Hábito 8 years ago 4 minutes, 46 seconds""
}
}
},
""index"": {
""simpleText"": ""1""
},
""shortBylineText"": {
""runs"": [
{
""text"": ""Bondade é Nosso Hábito"",
""navigationEndpoint"": {
""clickTrackingParams"": ""CD0QxjQYACITCMn2heSTz-wCFUmw1Qod1hMDdw=="",
""commandMetadata"": {
""webCommandMetadata"": {
""url"": ""/user/Bruno12170"",
""webPageType"": ""WEB_PAGE_TYPE_CHANNEL"",
""rootVe"": 3611
}
},
""browseEndpoint"": {
""browseId"": ""UCY1IJY2IYNVfD7R-JbgQGbQ"",
""canonicalBaseUrl"": ""/user/Bruno12170""
}
}
}
]
},
""lengthText"": {
""accessibility"": {
""accessibilityData"": {
""label"": ""4 minutes, 46 seconds""
}
},
""simpleText"": ""4:46""
},
""navigationEndpoint"": {
""clickTrackingParams"": ""CD0QxjQYACITCMn2heSTz-wCFUmw1Qod1hMDdzIKcGxwcF92aWRlb1okVkxQTDRfRHg4OGRwdTdlcGZINnlid3FKcGY5dUwydEFsMzY4mgEDEPos"",
""commandMetadata"": {
""webCommandMetadata"": {
""url"": ""/watch?v=j6QkVTx2d88&list=PL4_Dx88dpu7epfH6ybwqJpf9uL2tAl368&index=1"",
""webPageType"": ""WEB_PAGE_TYPE_WATCH"",
""rootVe"": 3832
} } }")
Dim fc As String = o("text")("url").ToString()
End Sub
but none of them is working.. What can I do to fix it? Thanks
Last edited by si_the_geek; Oct 25th, 2020 at 01:22 PM.
Reason: fixed formatting issue
-
Oct 25th, 2020, 07:06 PM
#4
Re: How to get YouTube PlayList video links.
Originally Posted by matty95srk
none of them is working
That's never an adequate explanation. A proper explanation includes what you expect to happen and what actually happens. If there are compilation errors, what they are and where they occur is required. I'm no expert when it comes to JSON but I may be able to help if I know what I'm looking for, so don't keep information that you have a secret when it might help indicate what to look for.
-
Oct 26th, 2020, 06:10 AM
#5
Thread Starter
Lively Member
Re: How to get YouTube PlayList video links.
Originally Posted by jmcilhinney
That's never an adequate explanation. A proper explanation includes what you expect to happen and what actually happens. If there are compilation errors, what they are and where they occur is required. I'm no expert when it comes to JSON but I may be able to help if I know what I'm looking for, so don't keep information that you have a secret when it might help indicate what to look for.
I thought I was clear.. My bad. So I just want to grab title and url. Anyway, I tried Youtube Api and this is returning max 50 songs for page. Then I am supposed to use nextpage Token, which is totally non sense to me. The only good thing about youtube api is that is giving straight the Json Code.
In this case, I'll come back using :
Code:
Dim textafter As String = """,""webPageType"
Dim textbefore As String = """url"":""/watch?v="
Dim startPosition As Integer = RichTextBox1.Text.IndexOf(textbefore)
startPosition += textbefore.Length
Dim endPosition As Integer = RichTextBox1.Text.IndexOf(textafter, startPosition)
Dim textFound As String = RichTextBox1.Text.Substring(startPosition, endPosition - startPosition)
RichTextBox1.Text=(textFound)
The only problem with this is that is giving back the first url. I don't know how to loop it, but it should work in a for each.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|