Live data from Hacker News

YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

twitter.com

51–60 of 166 posts

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#51
post #11

How should a programming noob interpret this? Be impressed at what was achieved here? Be concerned about security implications using the tool? Something else entirely?

> How should a programming noob interpret this?

Usually in a virtual machine.

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#52
post #42

This isn't really JS, it's a purpose built evaluator that's only for evaluating a particular script on YouTube, assuming a huge list of things are true about how YouTube JS is written. Ex. Its got a hard coded list of methods for String, and it doesn't respect prototypes. It only supports creating Date instances, and won't work if you override the global Date. It parses with regexes and implements all operators with…

This really isn't fair. Just because it doesn't faithfully implement whatever standard Javascript is on doesn't mean it isn't an interpreter. All an interpreter is is something that executes a script directly rather than requiring compilation. It is a defacto interpreter for a subset of javascript. Nothing more, nothing less. The title could be more clear, however.

There's a huge difference between an interpreter for "JavaScript" and an interpreter for a "subset of JavaScript".

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#53

Earlier quoted context omitted.

This really isn't fair. Just because it doesn't faithfully implement whatever standard Javascript is on doesn't mean it isn't an interpreter. All an interpreter is is something that executes a script directly rather than requiring compilation. It is a defacto interpreter for a subset of javascript. Nothing more, nothing less. The title could be more clear, however.

There's a huge difference between an interpreter for "JavaScript" and an interpreter for a "subset of JavaScript".

Making a pedantic argument on what constitutes an interpreter is silly. The title is bad. It is an interpreter. I'll continue to eat downvotes on this because of the pedantry of HN.

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#54

Earlier quoted context omitted.

There's a huge difference between an interpreter for "JavaScript" and an interpreter for a "subset of JavaScript".

Making a pedantic argument on what constitutes an interpreter is silly. The title is bad. It is an interpreter. I'll continue to eat downvotes on this because of the pedantry of HN.

Technically, it’s only the pedantry of a subset of HN.

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#55
post #42

This isn't really JS, it's a purpose built evaluator that's only for evaluating a particular script on YouTube, assuming a huge list of things are true about how YouTube JS is written. Ex. Its got a hard coded list of methods for String, and it doesn't respect prototypes. It only supports creating Date instances, and won't work if you override the global Date. It parses with regexes and implements all operators with…

And as a user of youtube-dl, I'm quite happy about this. This probably allows a very safe, restricted "subset" of JS. Way better than using a full JS engine. 900 lines is still small and manageable.

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#56
post #16

The same in yt-dlp https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/jsinterp... Interesting to see the diffcheck between the two https://www.diffchecker.com/8EJGN27K

Is yt-dlp's implementation being better the reason why I have fewer throttling issues than with youtube-dl?

[deleted]

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#57

Earlier quoted context omitted.

Making a pedantic argument on what constitutes an interpreter is silly. The title is bad. It is an interpreter. I'll continue to eat downvotes on this because of the pedantry of HN.

Technically, it’s only the pedantry of a subset of HN.

It's an interpretation of a subset of the pedantry on HN.

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#58
post #19

Nowadays "javascript" refers to the scriptable, grotesquely and absurdely complex and massive web engines, aka google financed blink and geeko, then apple financed webkit, that with their SDK. The currently obfuscated javascript media players will try to break yt-dlp by leveraging the complexity and size of those scripted web engines. They will make them out of reach to small teamns or individuals and it is even "bet…

ah, but quickjs is an actual js engine. I have tried a couple of versions with real progress between them. This thing here is not

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#59
post #7
post #2

What purpose does it serve?

I'd have to read up on the specifics as well, but I think basically Youtube uses a lot of obfuscated, rapidly and automatically changing Javascript code to fetch the video data. A project like youtube-dl has to run this code to be able to download videos, because that's what's happening in the browser as well.

But why not just use a normal JS engine called from Python?

Re: YouTube-dl has an interpreter for a subset of JavaScript in 870 lines of Python

#60

Earlier quoted context omitted.

There's a huge difference between an interpreter for "JavaScript" and an interpreter for a "subset of JavaScript".

Making a pedantic argument on what constitutes an interpreter is silly. The title is bad. It is an interpreter. I'll continue to eat downvotes on this because of the pedantry of HN.

I didn't downvote, but I don't think esprehn is being unfair. Their comment is very informative. They didn't argue that what was implemented is not an interpreter, they did explain why it's not a JavaScript interpreter and not even an interpreter for a subset of JavaScript. It's just a special purpose interpreter suitable for YouTube's code that cannot be re-used for any code that uses the subset that it seems to implement.

It's not pedantry (or I'm pedantic). It's a reaction to the title that can lead people to believe that a complete JavaScript interpreter has been written in less than a thousand lines of Python. This reaction is perfectly understandable.

Post reply on HN