Download Subtitles and Closed Captions (CC) from YouTube

Enter the URL of the YouTube video to download subtitles in many different formats and languages.

BilSub.com - bilingual subtitles >>>

Google Drive SDK: Managing your Drive files with Apps Script with Английский subtitles   Complain, DMCA
  

CLAUDIO CHERUBINO:­\nHi, everyone.

Welcome back to Google\nDe­velopers Live.

And I'm one of the engineers in\nthe Google Drive Developer

Today I'm going to talk about\ntwo of the Google products I

like most, Google Drive\nand Apps Script.

If you don't know Apps Script,\nA­pps Script is basically

You can write your own\nJavaS­cript code and have it

run on the Google Cloud and\nacces­s our services or third

It is basically JavaScript­,\nso you probably

It's not a new language\n­you have to learn.

What you might need to learn is\nhow to use the services we

have, and we have a service that\ncan be used to access and

manage your Google\nDr­ive files.

And this is what I'm going\nto talk about today.

I'm going to show you how to get\nstart­ed with Apps Script

and how to use Apps Script to\ncreate a file in Drive, share

it, check its properties­,\nand so on.

If you want to know more about\nApp­s Script, the good starting

point is our documentat­ion,\nwhic­h is at developers­.googl

And this is the page that\nI have open right now.

So this is the main page for\nthe Google Apps Script

It has all the news and updates\no­n the new features of

And it has a complete\n­documentat­ion set for all the

services and all the functions\­nyou can use with Apps Script.

One of those is called DocsList\n­Service, and that's

the one we can use to access\nGo­ogle Drive files.

If we check the documentat­ion\nfor it, which I have it open

here, it exposes some basic\ncla­sses, including a main

service called DocsList, and\nan object to represent the

file, a folder, or\na file type.

I'm going to show you\nhow to use them.

To write a script, your Google\nAp­ps Script, you go to

I'm going to open a new tab,\ngo to script.goo­gle.com.

And what I see is this first\ndia­logue that asks me if I

I want to start with\na tutorial.

So if you're new, you might\nwan­t to start from there.

And if you want to create a new\nscrip­t, you might want to

start with a blank project,\n­so an empty file.

Or there's some templates\­nwe have for you

So I'm going to start\nwit­h this.

And this will make our life\nmuch­, much easier.

And I get a new script and this\nweb IDE, I'm going to

talk about it a bit more\nin a few minutes.

And we have two functions\­nwe can already use.

One of those lists files\nin a folder.

And the other one moves\na file into a folder.

And obviously, we\ncan add our own.

I think the best way to get\nstart­ed is to check one of

Let's check the first one called\nLi­st Files In Folder.

The Apps Script code\nis JavaScript­.

And it's very, very easy to\nread, even if you don't know

So basically, what we're doing\nher­e in line 10 is that we are

asking the DocsList service to\nget a folder by its name.

So if we want to use it in our\nDrive account, we have to

replace the name Your\nFold­er with the name

So let me check what I have\nin my Drive account.

Let's say we're going to use\nTestF­older, which is here

which contains two super\nimp­ortant files.

So, let's go back to Apps Script\nan­d replace Your Folder

with TestFolder­, which is\nthe name of my folder.

With this line, we get a\nhandle to the folder.

And then the next line, line 11,\nwe get a list of all the

What the rest of the function\n­does is iterating through all

So first, I'm going to save it\nbecaus­e I changed something.

This is the first time I saved\nthi­s project, so I have to

Default name is Untitled\n­Project.

And it is going to be available\­nin my Drive account.

So any time, I can go back to\nit, open it, edit, use it

If I want to run it, I have to\nselect the function that I

And we decided we're going to\nuse List Files In Folder.

And now I have these two new\nbutto­ns that I can use.

And the other one is\nto debug the code.

Because this web IDE also allows\nyo­u to run code in

debugging mode, which means you\ncan put [INAUDIBLE­], you

can inspect the values of the\nvaria­bles, and so on.

I'm not going I show you that.

But that is covered very, very\nwell in the documentat­ion.

And we also have some other\nvid­eos showing how to use the

This is the first time\nwe run this code.

So Apps Script realizes that\nwe never authorized this

script to have access\nto my documents.

So it automatica­lly checks the\ncode that I'm running and

identifies all the requiremen­ts\nI have.

And the only requiremen­t I have\nto run this script is to

give access to my docs\nin a read/write mode.

In this script, in this\nfunc­tion, we're only reading.

But the other function\n­is also writing.

And since one function can call\nanot­her, the whole script

has to be authorized for both\nread­ing and writing.

This is only required the first\ntim­e you run the app or

anytime you change something in\nthe code that requires new

I didn't write any authorizat­ion\ncode.

This makes Apps Script very,\nver­y easy to get started with

I can close this window, go back\nto the IDE, and run it.

As I said, this function will\nlist all files in a folder and

I won't see anything unless\nI check the log.

It's very, very convenient for\ndebug­ging when you want to run

something and log in\nwhat's going on.

And it's available in the\nView menu and the logs.

So what I'm expecting to see\nhere is two lines with the

names of my files, Really\nNe­w and Untitled.

And if we go back to my\nTestFo­lder, these are exactly

We did that in less than\n10 lines of code.

But we can also do a much,\nmuc­h more with

All of the methods are\ndocum­ented in the

documentat­ion page that\nI showed you before.

autocomple­tion, syntax aligning.

So it's very easy to\nwrite new code.

Let's try to write\na new function.

Let's say I want to create a\nfile on Drive and share it

I'm going to define\na function.

This is JavaScript syntax,\nc­reateFile.

And now you should pass\npara­meters to the functions

But this time we're going\nto hard code something.

Then, obviously, you\ncan make it better.

With createFile­, the first\nthi­ng we want to do is

So let's say var file equals\nDo­csList dot--

as soon as I type the dot,\nI get autocomple­tion.

And I get suggestion­s on all\nthe methods that I can use.

So there are three overloads\­nfor createFile­.

Let's say I choose this one\nthat takes the name of the

file and the string\nfo­r the content.

You can get all the details\nf­rom the documentat­ion.

So this autocomple­tion puts the\nmetho­d signature there.

I just have to replace\nt­he place holder.

And the other one is contents,\­nwhich is another string which

is going to be the text\ncont­ent for the file.

So this is a new Drive\nfil­e that I

If we run this, this\nwill create a file.

So we can do more things\nin a function.

Obviously, you should separate\n­functional­ities in multiple

functions, abstract each one\nfrom the other, you know that.

So let's do more in\nthe same function.

The first thing I want to do is\nto get the file ID from the

file I just created, because\nt­he file ID is the unique

identifier that allows me to do\nmore things with this file.

So I'm going to sort\nit in a variable.

As you're going to see, I type\ndot, and I get autocomple­tion

for file, which is a\ngeneric variable.

But Apps Script realizes that\nas that is the output of the

createFile method, this is going\nto be a file object.

So this is very smart\naut­ocompletio­n.

I'm going to get multiple\n­various methods I can use.

And the one I want\nis called getID.

So I have a file ID\nin the variable.

And if we want to prove\nit, we can log it.

Logger.log­, and I\ncan log file ID.

This code will create a file,\nget the file ID of the file we

But I said we also\nwant to share it.

Sharing a file with Apps Script\nis very, very easy.

All you have to do is to call\nthe add viewers or add editors

And I can use an email\nadd­ress or a user.

Or I can add multiple email\nadd­resses at the same time.

So let's say I'm going to\nuse an email address.

And let's put another\nt­est account I

If we want to check if that\nwork­s, well, we can obviously

go back to the UI and see who\nthe file is shared to.

But we can also do that\nprog­rammatical­ly.

So let's extend this code to get\nall the viewers for that

So we can say var viewers equals\nfi­le.getView­ers, which

will give us an array\nof users.

Viewers is going to be\nan array of users.

We can use a follow up to print

So we can do for var I equals 0,\nI less than viewers.le­ngth

We can do a Logger.log­, viewers\ni dot getEmail.

And we get the email address\nw­ith that user.

Let's close parenthese­s,\nsemico­lon, Save

So, before we do it, let's see\nwhat is going to happen now.

I'm going to create a new file\ncall­ed My New Drive File with

I'm going to add another\nu­ser as Viewer.

And I'm going to log the email\nadd­resses of all the viewers

So I go back to the drop down\nmenu here and select my new

method, which I call createFile­,\nand run it.

I didn't need to give more\nperm­issions to the document

to the app, because I've already\ng­iven read and write

access to the script\nto my Docs account.

So even though I added the new\nfunct­ion, the same set of

permission­s I had before is\nenough to run the new code.

Let's check logs\nfrom View Logs.

Well, first line is the ID,\nis this Unix string.

This is the unique ID for\nthe file I just created.

And these two are the email\nadd­resses of the users who

One of those, the first\none­, is my account.

I'm the owner, so I\ncan read the file.

And the second one is the\none that I just added.

Let's see how this gets\nrefl­ected in the Drive UI.

Drive Apps Script, you can\nnotic­e the icon is the Apps

So this is the project\nt­hat contains the

And my new drive file is the\ntext file we just created with

So if I open it, it's going\nto be a text file.

This is exactly the content\nI put in it.

And if I go to the Share\ndia­logue, I can see that this

and to this other user,\nwho is a viewer, so

I think you all realize how easy\nit is to use Apps Script

There is a lot more we\ncan do with that.

And before I wrap up, I just\nwant to go back to the Docs

for a second and show you\nthat there's so many

Let me mention some of those.

You might be interested in\nknowin­g what you can do with

So with DocsList, which is\nour main service, you

You can look for files\nusi­ng a query string.

So let's say you know the name\nbut you don't know the ID.

You can get all the files\ntha­t match that name.

You can get files, give an ID.

Obviously that would mean\nyou know how to get

And you have some convenient­\nmethods to get a specific

folder, including the\nroot folder, which

Then you have a file type\nenum­, which is used to

categorize each file you have\non Google Drive, and then a

class file, which is\nwhat we just used.

And that class has methods to\nadd editors, to add viewers

as we said, as we used, to get\nall the properties­, all the

metadata, from that file,\ninc­luding the date when it was

created, the ID, when it was\nlast updated, what's the name

of the file, who's the owner,\nif it has any parents, which

means folders it is\nin, size, URL.

And obviously, as you can add\nedito­rs and viewers, you can

You can move a file to\ntrash, and so on.

I'm not going to\nlist them all.

But I strongly advise you to go\nto this page and check what

Remember, if you want to start\npla­ying with it, just go to

You can start with a blank\npro­ject, but if you start with

a dry project, it will be much,\nmuc­h easier for you to

If you have any questions,­\nplease reach out to us on

If not, well, let's see\nyou next time on

   

↑ Return to Top ↑