Hi
I am collecting / watching, making some notes from, a lot of YouTube videos from Play lists, some of those play lists have a lot of videos in them .
For various reasons it would be helpful to get a list of all the URLs from a play list, and if possible the accompanying tile. (If as a bonus I can get other info such as the date, view count then so much the better)
Current example: the play list here:
https://www.youtube.com/watch?v=rM-CtC6 ... JHdtoul_9A
Code: Select all
https://www.youtube.com/watch?v=rM-CtC6cklI&list=UULFwInqvNXb-GN0JHdtoul_9A

The links from all the videos in the play lists are a bit different, so I cant just take the first one and change index1 to index2 to index3 … etc.
Code: Select all
https://www.youtube.com/watch?v=rM-CtC6cklI&list=UULFwInqvNXb-GN0JHdtoul_9A ( <-- Play list main link )
https://www.youtube.com/watch?v=rM-CtC6cklI&list=UULFwInqvNXb-GN0JHdtoul_9A&index=1
https://www.youtube.com/watch?v=YsnmNoq6OTg&list=UULFwInqvNXb-GN0JHdtoul_9A&index=2
https://www.youtube.com/watch?v=KIx_8comGEc&list=UULFwInqvNXb-GN0JHdtoul_9A&index=3
https://www.youtube.com/watch?v=LU-nln_3q9A&list=UULFwInqvNXb-GN0JHdtoul_9A&index=4
But in this case the text file does not seem to contain any useful info for me. Maybe it does, but in my ignorance I can’t see it.
That text file is not very big. Neither are the text files from the links for each video. They are all quite small and only slightly different in content.
WieGehtsYouTubePlayList.txt https://app.box.com/s/nxt27ivwnowkt1jy4npgktxof4ix6r6g
WieGehtsYouTubeIndex1.txt https://app.box.com/s/yavaakedxs3wes1u0qyy60o80rbwoxj0
WieGehtsYouTubeIndex2.txt https://app.box.com/s/bklozkokkyztdjz6w75pjir0kq3pql4r
WieGehtsYouTubeIndex3.txt https://app.box.com/s/3y5otnjekzbtogkzq1krwnm4ftbfjxm3
Any help please? I don’t care what form I get the info in , arrays, spreadsheet, text file etc. I am happy to manipulate the data and put it in some convenient form in a spreadsheet myself. Even if the data is hidden in a massive text file, then I expect I can do some string manipulation to get out what I want.
Thanks
Alan
Code: Select all
Option Explicit
Sub WieGehtsYouTubeURL() ' https://excelfox.com/forum/showthread.php/2656-Automated-Search-Results-Returning-Nothing https://excelfox.com/forum/showthread.php/973-Lookup-First-URL-From-Google-Search-Result-Using-VBA
On Error GoTo Bed
'_1 First section get the long text string of the HTML coding of the internet Page
'_1(i) get the long single text string
With CreateObject("msxml2.xmlhttp")
.Open "GET", "https://www.youtube.com/watch?v=rM-CtC6cklI&list=UULFwInqvNXb-GN0JHdtoul_9A", False ' 'just preparing the request type, how and what type... "The True/False argument of the HTTP Request is the Asynchronous mode flag. If set False then control is immediately returns to VBA after Send is executed. If set True then control is returned to VBA after the server has sent back a response.
'.Open "GET", "https://www.youtube.com/watch?v=rM-CtC6cklI&list=UULFwInqvNXb-GN0JHdtoul_9A&index=1", False
'.Open "GET", "https://www.youtube.com/watch?v=YsnmNoq6OTg&list=UULFwInqvNXb-GN0JHdtoul_9A&index=2", False
'No extra info here for type GET
.setRequestHeader bstrheader:="Ploppy", bstrvalue:="PooH" ' YOU MAY NEED TO TAKE OUT THIS LINE
'.setRequestHeader bstrheader:="If-Modified-Since", bstrvalue:="Sat, 1 Jan 2000 00:00:00 GMT" ' https://www.autohotkey.com/boards/viewtopic.php?t=9554 --- It will caching the contents of the URL page. Which means if you request the same URL more than once, you always get the same responseText even the website changes text every time. This line is a workaround : Set cache related headers.
.send ' varBody:= ' No extra info for type GET. .send actually makes the request
While .readyState <> 4: DoEvents: Wend ' Allow other processes to run while the web page loads. Think this is part of the True option
Dim PageSrc As String: Let PageSrc = .responseText ' Save the HTML code in the (Global) variable. ': Range("P1").Value = PageSrc 'For me for a print out copy to text file etc. The responseText property returns the information requested by the Open method as a text string
End With
'_1(ii) Optional secion to put the text string into a text file , for ease of code developments
Dim FileNum2 As Long: Let FileNum2 = FreeFile(0) ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
Dim PathAndFileName2 As String
Let PathAndFileName2 = ThisWorkbook.Path & "\" & "WieGehtsYouTube" & ".txt" '
Open PathAndFileName2 For Output As #FileNum2 ' ' The text file will be made if not there, and if it is there and already contains data, then the data will be overwritten
Print #FileNum2, PageSrc '
Close #FileNum2
Exit Sub ' Normal code error in the case of no errors
Bed:
MsgBox prompt:=Err.Number & ": " & Err.Description: Debug.Print Err.Number & ": " & Err.Description
End Sub ' Code end in the case of any error
WieGehtsYouTube.txt https://app.box.com/s/rz4nfqoeeqtuqfp9zt0fsq4obncumyj9
WieGehtsYouTube.xls https://app.box.com/s/a4q4v4zfxtwh6pzqicw6ntuz8qtddbfr