-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathonedrive-hook.lua
61 lines (49 loc) · 1.9 KB
/
onedrive-hook.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
--[[
Detects when a onedrive link is loaded and converts it to an absolute path to play the file.
Uses powershell, so it only works on windows. Though if someone is using the cross-platform
version of powershell, they may just need to change the first arguement from 'powershell' to 'pwsh'.
available at: https://github.com/CogentRedTester/mpv-scripts
Also includes script messages to add video/audio/sub tracks from onedrive:
script-message onedrive/video-add [url] {flag}
script-message onedrive/audio-add [url] {flag}
script-message onedrive/sub-add [url] {flag}
]]--
local mp = require 'mp'
local msg = require 'mp.msg'
function get_link(url)
msg.debug('expanding url ' .. url)
local command = mp.command_native({
name = "subprocess",
playback_only = false,
capture_stdout = true,
args = {
'powershell',
'-command',
'([System.Net.HttpWebRequest]::Create("' .. url .. '")).GetResponse().ResponseUri.AbsoluteUri'
}
})
url = command.stdout
url = url:gsub('redir%?', 'download%?')
msg.debug('returning url ' .. url)
return url
end
function fix_onedrive_link()
local path = mp.get_property('stream-open-filename', '')
if path:find("https://1drv.ms") ~= 1 then
return
end
msg.info('onedrive link detected')
path = get_link(path)
msg.verbose('expanded onedrive url: ' .. path)
mp.set_property('stream-open-filename', path)
end
mp.add_hook('on_load_fail', 50, fix_onedrive_link)
mp.register_script_message('onedrive/video-add', function(url, flag)
mp.command_native({'video-add', get_link(url), flag})
end)
mp.register_script_message('onedrive/audio-add', function(url, flag)
mp.command_native({'audio-add', get_link(url), flag})
end)
mp.register_script_message('onedrive/sub-add', function(url, flag)
mp.command_native({'sub-add', get_link(url), flag})
end)