Group Abstract Group Abstract

Message Boards Message Boards

Playing with YouTube from Mathematica

Posted 7 years ago
POSTED BY: b3m2a1 ​ 
19 Replies
Posted 3 years ago

The Wolfram cloud links in this post give 403 (forbidden).

POSTED BY: julian

After playing with this paclet for a while I got a failure from YouTube indicating that the API had exceeded its allowed "quota".

Read more about it here: https://developers.google.com/youtube/v3/getting-started

It sounds like any YouTube app / API comes with a default amount of "quota" -- it indicates "10,000 units per day".

  • Each video upload is 1,600 units of quota.
  • Each write is 50 units.
  • Each simple read is 1 unit.

Presumably anyone that uses your paclet chews through the quota for your "app", "MathematicaLink", until the max daily quota is hit.

I suppose ideally the paclet would allow a user to substitute their own Google "app" / API in place of your "MathematicaLink", so that they could manage their own quota, etc.

As for me, I think I'll be OK -- I'll just wait until tomorrow to keep playing with the API, but figured I'd let you know about this incase it was of interest.

POSTED BY: Daniel Bigham
Posted 6 years ago

I'm well aware of that, but mostly I don't care. This was a fun side project for me, but I didn't sink enough time into it to make it worth figuring out some easy way for others to supply their own credentials inside the link. I've done that for my GoogleAPI extension stack in BTools, but the ServiceConnect framework is clunky.

In any case, if you want to use your own API credentials it's actually pretty easy. They're cooked directly into the paclet. Go to YouTube.m in Kernel and swap them out in youtubeclientid and youtubeclientsecret. I'm violating the TOS by directly exposing them in the first place so you'd be doing me a favor.

POSTED BY: b3m2a1 ​ 

Thanks for that info

Thanks, that solved the error.

Now I'm getting a response that contains an error:

{<|"domain" -> "global", "reason" -> "authError", "message" -> "Invalid Credentials", "locationType" -> "header", "location" -> "Authorization"|>}

When I ran:

$so = ServiceConnect["YouTube"]

... a couple of days ago, I followed your above instructions and checked the box for it to remember. When I evaluate $so = ServiceConnect["YouTube"] now, it doesn't launch the web browser but instead immediately returns a ServiceObject[...], that when used, results in the above error.

POSTED BY: Daniel Bigham
Posted 6 years ago

That looks like a ServiceConnect issue, not one on my end. Try using ServiceDisconnect on the object.

POSTED BY: b3m2a1 ​ 
POSTED BY: Daniel Bigham
Posted 6 years ago
POSTED BY: b3m2a1 ​ 

That did the trick. Thanks, and well done!

POSTED BY: Daniel Bigham

Thank for your reply. Wrapping it in File[...] led to the same result. Is there a particular source file and line that I should go to to inspect how you tried to work around this?

POSTED BY: Daniel Bigham
Posted 6 years ago

Turns out the issue is here: https://github.com/b3m2a1/mathematica-BTools/blob/eef23617d0fc565745cabf79cfb7b38000a5cb8f/Resources/Templates/Frameworks/%24ServiceConnection/Kernel/%24ServiceConnectionFunctions.m#L882

Mathematica doesn't know how to handle MP4 as a "MIMEType", but it looks like I set it up so you can specify your own as an argument, try adding "MIMEType"->the/right/mimetype" as an argument to the function. Alternately overload ImportExport`GetMIMEType to understand MP4

POSTED BY: b3m2a1 ​ 

I was delighted to see that code already exists to upload videos to YouTube from WL, so I gave it a try with an MP4 file, and got this: enter image description here

POSTED BY: Daniel Bigham
Posted 6 years ago
POSTED BY: b3m2a1 ​ 

"but you can get a link to the actual URL on YouTube where the video will display or use some YouTube downloader with that URL to get the video." Exactly that is what I want. How to do it?

Posted 7 years ago

With a response dataset you can get the ID for the video or list IDs for a list of videos by inspecting the response dataset structure and using the appropriate extractors.

Then you use the request $so["VideoURL", "id"->id] to get the display URL. You can map this over the IDs if you want to get a bunch of URLs.

POSTED BY: b3m2a1 ​ 

Thanks for the instruction. I verified that it works on V11.3 win 10.

enter image description here

POSTED BY: Shenghui Yang
Posted 7 years ago
POSTED BY: b3m2a1 ​ 
POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard