COMMENT
Version : 1.3.3
Github : @MediaGrabber
Telegram : @ShortcutsApps
|| Made with ❤️ by Sayem ||
COMMENT
A partial list of supported sites is available here: https://kutt.it/mgsites
Report any issue on github.
SCRIPTING
If
Shortcut Input
contains
Shortcut Input
SCRIPTING
Otherwise
SHARING
Get clipboard

Clipboard
TEXT
Match
https?://.*
in
Clipboard

Matches
COMMENT
Keep it to yes to suppress url prompts. It is helpful when your run from widget for background downloads.
TEXT
No

Text
VARIABLES
Set variable
WidgetMode
to
Text
SCRIPTING
If
WidgetMode
contains
Yes
TEXT
Clipboard

Text
SCRIPTING
Otherwise
SCRIPTING
Ask
Enter url or query
Default Answer
[{'class': 'magic', 'value': 'Text Matches', 'glyph': '', 'UUID': '94877D75-4047-4B37-94AF-356FA3F94E41'}]

Provided Input
SCRIPTING
End If

If Result
SCRIPTING
End If

If Result
TEXT
Match
^.+?(?=\&t|\&list)|^.*
in
If Result

Matches
VARIABLES
Set variable
InputURL
to
Matches
TEXT
Match
.*(twitter.com|vk.com|dailymotion.com|dai.ly|alive.in.th|weibo.cn|ubicast.tv|apple.com|funnyordie.com|tumblr.com|videofy.me|orfium.com|spreaker.com|smosh.com|mirror.co.uk|manchestereveningnews.co.uk|pbslearningmedia.org|livestreamfails.com|zeit.de|stream.me).*
in
InputURL

Matches
SCRIPTING
If
Matches
contains
Text Matches
URL
Get
Scheme
from
Matches

Component of URL
TEXT
Match
twitter.com|tumblr.com|dailymotion.com
in
Component of URL

Matches
SCRIPTING
If
Matches
contains
Text Matches
SCRIPTING
If
Matches
is
twitter.com
TEXT
Match
[0-9]{16,}
in
InputURL

Matches
URL
https://api.twitter.com/1.1/statuses/show.json?tweet_mode=extended&id=
Text Matches

URL
NETWORK
Get contents of
URL
Options Under Construction

Contents of URL
SCRIPTING
End If

If Result
SCRIPTING
If
If Result
is
tumblr.com
TEXT
Match
[0-9]{12,}
in
InputURL

Matches
URL
https://api.tumblr.com/v2/blog/
Component of URL
/posts/video?api_key=rdlmV7PoHOUVOPPGutXaQ1QkO7xDRZENPKiWAgKWTXooeqwo7M&id=
Text Matches

URL
NETWORK
Get contents of
URL
Options Under Construction

Contents of URL
SCRIPTING
End If

If Result
SCRIPTING
If
If Result
is
dailymotion.com
URL
InputURL
&locale=en&integration=inline&GK_PV5_NEON=1

URL
NETWORK
Get contents of
URL
Options Under Construction

Contents of URL
DOCUMENTS
Make HTML from
Contents of URL

HTML from Rich Text
SCRIPTING
End If

If Result
SCRIPTING
Otherwise
NETWORK
Get contents of
InputURL
Options Under Construction

Contents of URL
DOCUMENTS
Make HTML from
Contents of URL

HTML from Rich Text
SCRIPTING
End If

If Result
DOCUMENTS
Replace
\
with
World
in
If Result

Updated Text
DOCUMENTS
Replace
href="/
with
Component of URL
/
in
Replace Text

Updated Text
WEB
Get URLs from
Replace Text

URLs
TEXT
Combine
URLs
with
New Lines

Combined Text
DOCUMENTS
Replace
(?sm)(^[^\r\n]*)[\r\n](?=.*^\1)
with
World
in
Text

Updated Text
TEXT
Match
(https?).*?(\.mp4|/video_file/|\.m4v|\.mov|\.mp3|\.aac|\.m4a).*
in
Replace Text

Matches
SCRIPTING
Repeat with each item in
Matches

Repeat Results
TEXT
Match
mp4|mp3|m4a|aac|m4v|mov+$
in
Repeat Item

Matches
SCRIPTING
If
Matches
contains
Text Matches
SCRIPTING
Otherwise
TEXT
mp4

Text
SCRIPTING
End If

If Result
VARIABLES
Set variable
FileEXT
to
If Result

Text
VARIABLES
Add
Text
to
DictInfo
SCRIPTING
End Repeat

Repeat Results
SCRIPTING
End If

If Result
COMMENT
Get json results from our backend server. The json results include all the information needed to download videos.
SCRIPTING
Count
Items
in
If Result

Count
SCRIPTING
If
Count
is
0
TEXT
aHR0cDovL3l0LmdldGh0dHAub25saW5lL2luZm8=

Text
SCRIPTING
Decode
Text
with base64

Base64 Encoded
NETWORK
Get contents of
Base64 Encoded
Options Under Construction

Contents of URL
VARIABLES
Set variable
FetchedJSON
to
Contents of URL
SCRIPTING
If
FetchedJSON
contains
"error"
COMMENT
Errors have json value. This errors are usually from youtube-dl installed on backend server. Errors will be displayed with alert option.
SCRIPTING
Show alert
FetchedJSON
Title
[{'class': 'magic', 'value': 'FetchedJSON', 'glyph': 'assets/cat/Variable.svg', 'UUID': ''}]
SCRIPTING
If
FetchedJSON
contains
update_url
URL
FetchedJSON

URL
SCRIPTING
Open
URL
with x-callback
Options Under Construction

X-Callback Result
SCRIPTING
Wait
2 seconds
SCRIPTING
End If

If Result
VARIABLES
Set variable
Alert
to
If Result
SCRIPTING
Otherwise
COMMENT
Parse json for getting information on video url, title and formats.
SCRIPTING
Get dictionary from
FetchedJSON

Dictionary
VARIABLES
Set variable
DictInfo
to
Dictionary
SCRIPTING
If
DictInfo
contains
"mgalert":
SCRIPTING
Show alert
Informational Message
SCRIPTING
End If

If Result
SCRIPTING
Count
DictInfo
in
If Result

Count
SCRIPTING
If
Count
is greater than
1.0
SCRIPTING
Repeat with each item in
DictInfo

Repeat Results
TEXT
Repeat Item

Text
SCRIPTING
Set name of
Text
to
Repeat Item

Renamed Item
VARIABLES
Add
Set Name
to
ChooseDict
SCRIPTING
End Repeat

Repeat Results
SCRIPTING
Choose from
ChooseDict

Chosen Item
VARIABLES
Set variable
DictInfo
to
Selected Item
SCRIPTING
End If

If Result
COMMENT
Remove any illegal characters from title and replace with "_" for saving file.
TEXT
DictInfo

Text
DOCUMENTS
Replace
[/:|;",\\*']
with
_
in
Text

Updated Text
VARIABLES
Set variable
DictTitle
to
Replace Text
TEXT
DictInfo

Text
VARIABLES
Set variable
Headers
to
Text
SCRIPTING
Get
Value
for
formats
in
DictInfo

Dictionary Value
VARIABLES
Set variable
Formats
to
Dictionary Value
COMMENT
Check if json results only have one single video or multiple.