Download youtube video automation

This is the script I came up with earlier today and works for me:

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			do shell script "/usr/local/bin/youtube-dl -o '~/Library/Application Support/DEVONthink 3/Inbox/%(title)s.%(ext)s' " & URL of theRecord
		end repeat
	end tell
end performSmartRule
4 Likes

Welcome @jrickmd

Thanks for your offering. :slight_smile:

Can you post a screencap of your smart rule too? Thanks.

Sure can. That is on my work computer, so reproduced it here:

Looks at an RSS feed I have for one of the playlists I watch on YouTube. If the URL has YouTube in it, it uses that script on the files, and moves them to the trash now that I have the movie downloaded in my inbox.

Rick

3 Likes

Thanks! :slight_smile:

thanks @jrickmd this did the the trick however I am not sure what the problem was actually. I thought I tried every combination with and without “quoted form”.

@pete31 thanks for the tip on how to debug however I am not sure if I have the best workflow.
I have a smartrule in DT with the script I am developing and everytime I change something I run it to test it in DT. However it seems that DT is caching the scripts and I did not find any way to reload it so I have to close and reopen DT everytime when I update the script which is very cumbersome.
There must be a better way right?

Now I just need to find a way to save the outcome not to the global inbox but to a specific inbox of another db. It looks like the global inbox is special in terms of “easy access”

1 Like

I plan on writing a smart rule for my global inbox to move the .mp4 file to the group I want it to end up in…

Rick

hm I actually dont want the mp4 file to go to the global inbox at all since it will get synced and I dont want to get the video files synced

Try adding a Move action at the beginning of the action chain.

There is Script: Comfortably developing a Smart Rule Script

2 Likes

But this would still mean that youtube-dl is saving to the global Inbox and then I would move the file right?
Isn’t there a way that youtube-dl can directly save to one specific db inbox?

@pete31
thanks for the link this helps a lot!

No, you need to either

  • create the file in an indexed group and move it to the incoming group afterwards

or

  • create the file in any Finder folder and import it to the incoming group afterwards

or

  • create the file the way you’re doing it now and then move it as suggested by @BLUEFROG.
1 Like

How can I do this since groups in DT don’t have a file/folder representation on the filesystem right?

Yes, groups that were created in DEVONthink don’t have a representation.

But they have if you’ve indexed a file or folder. That’s the whole point of indexing.

Search indexed in DEVONthink’s help.

@pete31 thanks again now it works almost 90% the way I wanted it :wink:

1 Like

So the script was working as expected and is still working on desktop. However it now does not work when I add a youtube link via iPhone.

The reason is that instead of sharing the actual link to the video, the devonthink app changes the link to the youtube consent screen…

Is there any way to tell the devonthink app not to do that? Or is it a bug?

you might want to read this thread all about that :wink:

thanks!

Thank you for sharing this code. Installing youtube-dl is a bit of a journey, but now the smart rule is working flawlessly

There is some controversy online about YouTube-dl and the support given to it. I only read about this when my YouTube-dl downloads got to be VERY slow. Some thought that YouTube was blocking it. This is now the shell script line I use after installing a fork of YouTube-dl called yt-dlp…

do shell script "/usr/local/bin/yt-dlp -o '~/Library/Application Support/DEVONthink 3/Inbox/%(title)s.%(ext)s' " & theURL

Rick

2 Likes

If you guys want something faster than youtube-dl, try yt-dlp.
It has date formatting that makes things really nice…

For example, here’s my script:
yt-dlp -U 'https://channel or playlist or video' -o '%(uploader)s (%(uploader_id)s)/%(upload_date>%Y-%m-%d %a %b)s YT %(title).150s - (%(duration>%Hh%Mm%Ss)s) [%(resolution)s] [%(id)s]' --write-auto-sub --convert-subs=srt --write-description --write-info-json -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'

2022-07-30 Sat Jul YT VideoTitle - (00h36m51s) [1920x1030] [ASxSbOj6nJP]

The date is sortable by YYYY-MM-DD
I like to know the date and month (for searching): Sat Jul
I trim the title to 150 characters and this allows me to be able to do those crazy long titles of videos on Twitter, for example (you can use a twitter url or other video service instead of youtube)
I add the YT prefix in this case, but you can remove that if you wish or make a macro that uses YT, TW, etc if you want the original source site…

The script above also downloads the video description and transcript and json details for each video all with the same nice formatting. Furthermore it puts the videos into the proper channel directory so that you don’t have to figure that out later.

Super fast. Enjoy.