SlyGuy Addons: Smart URL Actions

This is a Supporter Only feature

All SlyGuy Addons support: Smart URL Actions

This allows you to specify URL patterns that then have various actions applied to them.
They can be applied to all add-ons and or to a single addon.

All SlyGuy addon urls used internally (talking to the various APIs etc) or used for media playback are supported.

I personally use this with my Smart DNS provider (dns4me.net) to automatically apply their smart dns functionality without requiring changes to dns settings on any of my devices. As I can apply it on per add-on basis it allows for different services that use the same domains to both work. This is not possible when using router / device dns. eg. 9Now and TVNZ (both use same brightcove host). I can just add a urls.txt for 9Now only so only it routes via the smart dns IP address and TVNZ traffic is untouched.

File to use

To apply to all add-ons, the file used is kodi/userdata/addon_data/script.module.slyguy/urls.txt
To apply to specific add-on, the file used is kodi/userdata/addon_data/{addon id}/urls.txt
(if these folders don't exist - run the addon once and it'll create them)

urls.txt is simple text file with a pattern & action - one per line.
The file is read from top to bottom and stops once a single url match is found.

If both a common and add-on urls.txt are found, the addons urls patterns take priority.
If none of those patterns match, it will then check the common patterns.

The format is
action pattern
action pattern
action pattern
(same as hosts file)

Available URL Patterns

The pattern is very basic and its a search match so if the pattern is found anywhere in the requested url - its chosen.

Examples

brightcove.com
matches: http://brightcove.com
matches: https://edge.api.brighcove.com/api/121?test=123

brightcove.com/api/
matches: https://edge.api.brighcove.com/api/121?test=123

Wildcard

There is also a wildcard character which is *
This matches 0 or more of any character.
This can be used like below:

http://*brightcove.com/api/
matches: http://edge.api.brighcove.com/api/121?test=123
doesn't match: https://edge.api.brightcove.com/

Available Actions

DNS Server Resolver

This routes the matched URL via a desired DNS server (resolver)
The dns server IP must start with
r: so the script can identify it.

eg.
r:1.1.1.1 edge.api.brightcove.com
r:8.8.8.8 *
r:https://cloudflare-dns.com/dns-query *
r:https://dns.google/resolve *

Any urls matching edge.api.brightcove.com will do a DNS lookup to 1.1.1.1
Any other urls will do DNS lookup to 8.8.8.8

DNS over HTTPS is also supported for JSON friendly servers like Cloudflare and Google.

If you want to use a Smart DNS Server for an add-on, simply create a urls.txt in that add-ons folder with 
r:[smart dns ip] * and now all urls in that add-on only will route via the smart dns server. Or as per above, you can apply it to all addons by putting the urls.txt in script.module.slyguy addon data.
No more changing DNS settings on your device or router.

DNS Rewrite

This overrides the IP address resolution for the matching URL with a provided value

eg.
43.209.63.213 edge.api.brightcove.com

If the url matches, the domain name IP lookup will be overridden with the provided IP address.
The format is compatible with hosts files format.

Proxy

This routes the matched URL via the provided proxy.
The proxy url must start with p: so the script can identify it.

Modes Supported: http, https, socks4, socks4a, socks5, socks5h
(4a and 5h both use remote dns resolving)

eg.
p:socks5h://user:pass@host:port edge.api.brightcove.com
p:http://host:port edge.api.brightcove.com

Network Interface IP

This routes the matched URL via the provided network interface.
The network interface IP must start with i: so the script can identify it. 

eg.
i:192.168.20.18 edge.api.brightcove.com
i:10.10.5.4 *

Any urls matching edge.api.brightcove.com will route through the network interface with IP 192.168.1.10
Any other urls will route through the network interface with IP 10.10.5.4

Replace

This replaces the matched URL with a provided value (uses regex sub).
This is handy to force certain CDNs for various services.

eg.
vodhds-au.akamaihd.net vodhds-*.akamaihd.net

With the above, if the url was https://vodhds-us.akamaihd.net/test.m3u8, it will be changed to https://voddhs-au.akamaihd.net/test.m3u8
This is great if your Smart DNS provider doesn't have a domain name that you found is being used. 

URL

This will download the provided url and use it's patterns.
It is defined by just putting the url on it's own line.

eg.
https://dns4me.net/api/v2/get_hosts/hosts/214852da-2f80-48f9-be62-888642d6e5e3

When the urls.txt file is being loaded - it will download the above URL and add it's contents to it's list of patterns.

Discussion

Support