DT youtube save problem - pesky link spam spoiling experience

That’s pretty simple: you want the second script in this post, rather than the one in this post :wink:

AH Thank you :slight_smile: - my fault for not reading it fully. I simply copied what I thought was the latest interation

Pls let me know if it works for you - I wasn’t able to test, because I don’t have any appropriate files handy. Pls test on one or two files rather than hundreds :slight_smile: If you were going to use this on a very large number of files, I think I’d add the step counter and the possibility to cancel the rule. I can’t do that today, but do let me know if you think that would be handy.

Hi Blanc,

It does strip the consent part of the prefix, however the issue is slightly more subtle (as it still doesn’t work for me)… the wanted unique part of the url appears to be stuck in the middle between percentage marks:

  1. Here’s the original form

[Before you continue to YouTube](https://consent.youtube.com/ml?continue=https://m.youtube.com/watch?v%3D7hGqlEpvODw%26feature%3Dyoutu.be&m=1&gl=GB&hl=en-GB&pc=yt&uxe=23983172&src=1)

  1. Here’s the result of removing the prefix (as per your script)

[Before you continue to YouTube](https://m.youtube.com/watch?v%3D7hGqlEpvODw%26feature%3Dyoutu.be&m=1&gl=GB&hl=en-GB&pc=yt&uxe=23983172&src=1)

However, and I didn’t understand this before, it doesn’t give me a link to the video…

  1. However, this link does (it’s what “Bear” App provides as a saved link)

https://youtu.be/7hGqlEpvODw

So my conclusion ignoring the title header [ ] for the moment, is the active part to save for the bookmark is only “7hGqlEpvODw” which is stuck within “%” gloop

This looks like it would need more string processing than originally thought…

(a) So removal of prefix before as in “…%”
(b) And removal of the suffix after as in “%…”
(c) Then add the string that remains at the end of “https://youtu.be/

What do you think?

Assuming the format is always the same, that’s easy (and I’ve added the progress stepper and cancel button):

-- includes sections from C. Grunenberg: Set name to title of web page
-- those sections Copyright C. Grunenberg

on performSmartRule(theRecords)
	tell application id "DNtp"
		try
			show progress indicator "Converting Youtube URLs" cancel button 1 steps count of theRecords
			repeat with theRecord in theRecords
				if cancelled progress then error number -128
				step progress indicator (name of theRecord) as string
				set theURL to URL of theRecord
				set thePos to (offset of "%3D" in theURL) + 3
				set theURL to texts thePos thru -1 of theURL
				set thePos to (offset of "%" in theURL) - 1
				set theURL to texts 1 thru thePos of theURL
				set theURL to "https://youtu.be/" & theURL
				set URL of theRecord to theURL
				-- © C. Grunenberg
				set this_source to download markup from theURL
				if this_source is not missing value then
					set this_title to get title of this_source
					if this_title is not missing value and this_title is not "" then set the name of theRecord to this_title
				end if
				-- end
			end repeat
		on error error_message number error_number
			hide progress indicator
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		end try
		hide progress indicator
	end tell
end performSmartRule

With the specific link which you posted, this script works for me, converting a bookmark with that link to a bookmark called “Public Lecture—Water: The Strangest Liquid - YouTube” and linking to “https://youtu.be/7hGqlEpvODw”. If it doesn’t work reliably for you, you’d need to post some more links so we can see if there is a (different) pattern.

2 Likes

Blanc - that’s PERFECT !!!

It now works for me :slight_smile:

You are a star!

I’ll try throughout today now - in answer to your previous question, I don’t have many bookmarks in hand as it didn’t work before… But will certainly stretch more today, and checkout the stepper (thanks!)

I’m also surprised others haven’t been calling for this from earlier, but maybe my DT video bookmarking activities are rarer than I think…

1 Like

I’ve never even heard of consent.youtube.com.

Appears as Clip to DEVONThink url prefix totally reliably under these conditions

(1) UK iPad running IoS 14.5,
(2) Safari
(3) DEVONThink To Go 3 20Mar 2021,
(4) So far, on all tested occasions (including from youtube.com) when viewing video on part of page and then “Clip to DEVONThink” (ie the only circumstance I can clip)

Different results your side?