-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplex-ngrok-tunnel.py
25 lines (21 loc) · 976 Bytes
/
plex-ngrok-tunnel.py
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
import time
import socket
from pyngrok import ngrok
from plexapi.server import PlexServer
TOKEN = '<your-token-here>' # Make sure token is in quotes
PUBLIC_PORT = 32400 # 32400 is the default port for Plex, do not change unless you know what you're doing.
# Open ngrok tunnel
tunnel = ngrok.connect(PUBLIC_PORT, "tcp") # tunnel = tcp://abc:xyz
url = tunnel.public_url[6:].split(":")[0] # url = abc
ip = socket.gethostbyname(url) # ip = gethostbyname(abc) = 123
port = tunnel.public_url[6:].split(":")[1] # port = xyz
public_url = "https://" + ip + ":" + port # public_url = https://123:xyz
print('ngrok tunnel opened')
# Set Plex Custom URL
private_url = 'http://localhost:' + str(PUBLIC_PORT)
plex = PlexServer(private_url, TOKEN)
plex.settings.get('customConnections').set(public_url)
plex.settings.save()
print('Plex custom URL set')
while True:
time.sleep(3600)