 Hello, so I'm recording this video on April 7th. Things may change by the time you actually see this video. But all my videos are being pushed over to the library website lbry.tv. And my username is middlex1000 there. You should check out my videos over there as well. But I wanted to see if I could just play a video or download a video using YouTube DL. And you would think that a website like this, it'd be, YouTube DL works on a lot of websites. It works great. A website like this, they have a download button right here to download the MP4. So you would think that YouTube DL would work with this. So I should just be able to take that URL, paste it in here with YouTube DL and it should start downloading it. But it doesn't. It throws an error. And yes, I am running, if I sudo YouTube DL dash capital U, it will show you that I'm up to date. You know, the version I'm running is just over a week old. So great. So I started, I decided just for fun, I'm going to write a script that will download, even though I can just click on that button there. But I wanted a script that would be able to either download or play using MPV, a YouTube or a library link without having to go to the web browser and just do it from the shell. And I actually did write a script using phantomjs, which I use for scraping websites, phantomjs is very easy to use. It took me maybe five, definitely less than 10 minutes to figure it out and I was able to get the URL. And then I went back to, I was getting ready to record this video to show you that script, which maybe I should, because it'd just be a good, good lesson. But I just, just double check, I ran YouTube DL again and realized it actually is giving me this unsupported link here. And that is the link, except for it's the embedded link rather than the download link. So for example, if I was to MPV that URL, it's going to throw an error because MPV is gonna try to either play that or use YouTube DL. But if I was to change where it says embed to download, it will start playing that video. And saying what W get, I can W get that URL and now I'm downloading the video. Let's go ahead and just remove what just started to download. So obviously YouTube DL is trying to maybe at some point that link worked, but it has been updated to look for that download link. It's looking at the embed link, which isn't working. So I don't even need to write a whole script. I can just grab what YouTube DL is outputting, like this, and use awk and grep or whatever tools I need to get this information. Now this is a standard error out. So to pipe that into another program, I'm going to have to go to pipe, space pipe, and then put my next command in parentheses, which is a little weird. I've never done that. I've piped standard error out to a file, but I'm not sure if I ever piped it like this before. But let's just go ahead and use this and we'll just say awk and we'll say to print the fourth column. So it's going to go one, two, three, four. Okay, that's great. But it's also going to show other lines in this that we want. We don't want that. So I am just going to use tail dash n1 to get the last line. So here we go, we should get that URL. Now all we have to do is use something like said to substitute. This is going onto a new line. Let me make this a little bigger. There we go. So it's a little easier to read here. So we're set. And now I could say embed and replace that with download. Problem with that is what if the title of the video has the word embed in it. So we're going to say find embed that has forward slashes around it and replace it with download with forward slashes around it. And now we should get our download URL. And that's a direct link even though it doesn't have an MP4 extension. That is our MP4 URL. So I should be able to wrap this in dollar sign parentheses and quotation marks. And I can say something like MPV. And now I'm able to start streaming that video using MPV. Again, not with the link to the MP4 but to the video URL up here. And see the big thing is this right here this randomly generated string. That's what I needed to get from the page. And originally I scraped it from the page but YouTube DL actually did that for me. See it found it here and it tried to find the URL but instead of using download again it did embed. So now I can pass it. Now I could obviously clean up the script so that this URL isn't in the middle here. But let's do it on a one liner. How about that? Instead of putting the URL in here I can say dollar sign URL. And then at the beginning of this I'm going to say read dash. Well, I'm not in bash, I'm in yeah, okay. Anyway, I'm just going to say URL. And now usually if you're in bash read has a dash P option to put a prompt in there. I'm in Z shell here which wouldn't matter if I was writing this as script but it doesn't seem to have the prompt or at least the switch for it is different. So I'm just going to say echo enter URL, okay. And we'll even put a dash in there. So we're going to say enter URL with a space, no new line. Then we're going to wait for the URL to be entered, put it into a variable called URL and then run that through our script there. So now I can hit enter on this and ask for that URL. I should be able to go here, copy any video's URL, enter it there, hit enter and theoretically it should start playing that video after a few seconds. There we go. Now YouTube DL does take a moment to go through that because it's basically throwing an error. So my script actually ripping it might be better but I was just like I went through writing my own script and then realizing that YouTube DL is 99% there which means probably with the next update they're probably going to fix that because it gets all the information it needs it just needs to change that. Anyway, this is just a quick video to look over that. Again, it's going to be a while before this video gets out so it probably be fixed by the time but just something to think of, think about writing your own script is useful and again mine probably would run a little quicker than this since this is throwing errors and going kind of slow but look at the error output when a program doesn't run properly read what the error say they're there for a reason and I just saw unsupported URL and I saw that it was this I thought was just saying that it doesn't support library but then I realized it's actually grabbing the right information 99% there. Anyway, just thought I'm actually going to go to the YouTube DL page right now and see if there is you know, there's probably a error, a bug report on this already. I'm going to check it out and see what it says but while I was thinking about it while I was working on this, I thought I'd share what I came up with. So again, and you know, someone who doesn't understand the shell is going to look at this and go, oh, that's crazy. I don't want to type that every time. The thing is you don't. I can just type in, I can say something like alias LBRY equals and I can give it a command like this. I think that should work. No, because it's running stuff. I actually throw it into a function. I should be able to say function LBRY this. Let's see if that works. Normally I'd throw it into a script file. I'm just seeing if this works. So now I should say LBRY. Nope, that didn't work. Now I just kind of messed up the end of this video. Anyway, I thank you for watching and I hope that you have a great day.