Anyone who has ever pulled a website from a script knows the pain that is Javascript. Normally you want to just get some text and work out the API actions but a lot of sites use horribly obfuscated Javascript -- either because that's what modern web development is (lolz) -- or because its part of their 'security.' That means if you want to write browser-based bots properly -- you ought to use a browser. There are spe…
Just npm install puppeteer.
YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
151–160 of 166 posts
Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
#152Earlier quoted context omitted.
That is against HN guidelines: "Please submit the original source. If a post reports on something found on another site, submit the latter." - https://news.ycombinator.com/newsguidelines.html
Citing the guidelines is against the guidelines, if not by the letter, in spirit. It's boring and it lacks curiosity. It assumes too much about the sharer. "Can we stop this trend" is a dog whistle for the "HN is getting worse" complaint. Instead we could be considering if we're meant to read the Twitter conversation as well, or sharing a laugh about the link in the tweet author's bio. Or maybe the sharer didn't feel…
Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
#153I do wonder why YouTube does not try harder to make it difficult to do this computation meant to prove you are a legit YouTube web client. Providing an easy-to-find, simple JS function interpretable with 900 lines of Python is like they don't try at all. They might as well do nothing. Or is their goal just to make youtube-dl not 100% reliable? Or to be able to say "look, you are running our code in a way we did not i…
They do make it harder from time to time. In fact yt-dlp's interpreter has been broken for a month or so now and the devs finally gave up and told users to just install PhantomJS (which itself hasn't been updated since 2016 and probably has bugs / vulns of its own, but whatever). https://github.com/yt-dlp/yt-dlp/issues/4635#issuecomment-12...
Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
#154Earlier this year I enrolled in an online class called "Building a Programming Language" taught by Roberto Ierusalimschy (creator of Lua) and Gustavo Pezzi (creator of pikuma.com). We created a toy language interpreter/VM and the final code was around of 1,800 lines of Lua code. Keeping things as simple (and sometimes naive) as possible was definitely the right choice for me to really wrap my head around the basic theory and connect the dots.
Thanks for the link.
Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
#155Earlier quoted context omitted.
Citing the guidelines is against the guidelines, if not by the letter, in spirit. It's boring and it lacks curiosity. It assumes too much about the sharer. "Can we stop this trend" is a dog whistle for the "HN is getting worse" complaint. Instead we could be considering if we're meant to read the Twitter conversation as well, or sharing a laugh about the link in the tweet author's bio. Or maybe the sharer didn't feel…
How can I read the Twitter conversation when Twitter asks me to log in? :-)
Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
#156How should a programming noob interpret this? Be impressed at what was achieved here? Be concerned about security implications using the tool? Something else entirely?
This is the compiler writer equivalent of parsing HTML with regex: It is technically wrong - it isn't a sufficiently rich and powerful approach to handle all JS (HTML) that you might throw at it. It'll work for a while until it eventually barfs when you least expect it. EXCEPT that if the inputs you are giving it come from some understood source(s) that aren't likely to change, then a simpler approach to the "all sin…
Does that apply to YouTube? Or any of the other hundreds of supported sites?
Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
#157Earlier quoted context omitted.
> How should a programming noob interpret this? The browser is client-facing and everything there is possible to reverse engineer and figure out. So if you design a web-based application, and are depending on client-side Javascript for any security or distribution enforcement, it can be helpful, but can ultimately be unwound and cracked even if obfuscated, etc. > Be impressed at what was achieved here? Yes. Try to do…
Youtube-dl is impressive. This particular hack is not.
Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
#158Earlier quoted context omitted.
This is the compiler writer equivalent of parsing HTML with regex: It is technically wrong - it isn't a sufficiently rich and powerful approach to handle all JS (HTML) that you might throw at it. It'll work for a while until it eventually barfs when you least expect it. EXCEPT that if the inputs you are giving it come from some understood source(s) that aren't likely to change, then a simpler approach to the "all sin…
> some understood source(s) that aren't likely to change Does that apply to YouTube? Or any of the other hundreds of supported sites?
Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
#159To be clear, this is an extremely tiny subset of JS. It looks like they only implemented the features needed to run a very specific function. For example, the only symbol allowed after "new" is "Date", everything else throws an exception. It's still fun that it's there, but it's not as big a deal as it sounds from the tweet.
The specific site modules in youtube-dl will take care to extract the bare minimum necessary to solve whatever challenge.
Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python
#160To be clear, this is an extremely tiny subset of JS. It looks like they only implemented the features needed to run a very specific function. For example, the only symbol allowed after "new" is "Date", everything else throws an exception. It's still fun that it's there, but it's not as big a deal as it sounds from the tweet.
if it's going to need much more than that then it probably would make more sense to port the whole application to javascript instead. but then this could be turned into a commandline browser that is able to interpret a whole web-page and save the resulting html structure instead of the source as curl/wget would do.
I bet someone's already started a YouTube downloader that uses a headless browser