|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
import sys
|
|
|
|
|
import socket
|
|
|
|
|
import secrets
|
|
|
|
@ -10,12 +11,7 @@ from threading import Thread
|
|
|
|
|
from urllib.request import urlopen
|
|
|
|
|
|
|
|
|
|
PORT = 4040
|
|
|
|
|
BEAM_SERVER = '192.168.0.3:5005'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d = tempfile.TemporaryDirectory()
|
|
|
|
|
|
|
|
|
|
print("using tempdir " + d.name)
|
|
|
|
|
BEAM_SERVER = '192.168.0.192:4005'
|
|
|
|
|
|
|
|
|
|
def handler_for_dir(dir):
|
|
|
|
|
def myhandler(*args, **kwargs):
|
|
|
|
@ -41,17 +37,16 @@ def get_ip():
|
|
|
|
|
s.close()
|
|
|
|
|
return IP
|
|
|
|
|
|
|
|
|
|
target = sys.argv[1]
|
|
|
|
|
def local_session(target):
|
|
|
|
|
d = tempfile.TemporaryDirectory()
|
|
|
|
|
print("using tempdir " + d.name)
|
|
|
|
|
|
|
|
|
|
id = secrets.token_hex(16)
|
|
|
|
|
os.symlink(os.path.abspath(target), d.name + '/stream')
|
|
|
|
|
|
|
|
|
|
# symlink target to tempdir so we only expose a single file
|
|
|
|
|
os.symlink(os.path.abspath(target), d.name + '/stream')
|
|
|
|
|
|
|
|
|
|
handler = handler_for_dir(d.name + '/')
|
|
|
|
|
token = None
|
|
|
|
|
handler = handler_for_dir(d.name + '/')
|
|
|
|
|
token = None
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
try:
|
|
|
|
|
with http.server.HTTPServer(("0.0.0.0", PORT), handler) as httpd:
|
|
|
|
|
try:
|
|
|
|
|
print("serving at port", PORT)
|
|
|
|
@ -59,7 +54,7 @@ try:
|
|
|
|
|
t.start()
|
|
|
|
|
print("calling beam target...")
|
|
|
|
|
host = get_ip()
|
|
|
|
|
resp = get_request(f'http://{BEAM_SERVER}/open?host={host}&port={PORT}')
|
|
|
|
|
resp = get_request(f'http://{BEAM_SERVER}/open/local?host={host}&port={PORT}')
|
|
|
|
|
if resp[0]:
|
|
|
|
|
token = resp[1].strip()
|
|
|
|
|
print(f"successfully started video - session {token}")
|
|
|
|
@ -70,8 +65,37 @@ try:
|
|
|
|
|
print("shutting down server")
|
|
|
|
|
httpd.shutdown()
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
finally:
|
|
|
|
|
print("cleaning up")
|
|
|
|
|
if token:
|
|
|
|
|
get_request(f'http://{BEAM_SERVER}/stop/{token}')
|
|
|
|
|
d.cleanup()
|
|
|
|
|
|
|
|
|
|
def youtube_session(video):
|
|
|
|
|
id = re.match('^(https?:\/\/)?(www\.)?youtu(\.be\/|be\.com\/watch\?(.*&)?v=)([A-Za-z0-9]{5,20})', video)
|
|
|
|
|
if not id:
|
|
|
|
|
print(f"invalid match in {video}!")
|
|
|
|
|
return
|
|
|
|
|
id = id.group(5)
|
|
|
|
|
|
|
|
|
|
print(f"watching youtube video {id}")
|
|
|
|
|
|
|
|
|
|
resp = get_request(f'http://{BEAM_SERVER}/open/youtube/{id}')
|
|
|
|
|
|
|
|
|
|
if resp[0]:
|
|
|
|
|
token = resp[1].strip()
|
|
|
|
|
print(f"successfully started video - session {token}")
|
|
|
|
|
input("Just press enter when you are done...")
|
|
|
|
|
get_request(f'http://{BEAM_SERVER}/stop/{token}')
|
|
|
|
|
else:
|
|
|
|
|
print("Error statrtig video!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
target = sys.argv[1]
|
|
|
|
|
|
|
|
|
|
if re.match('^(https?:\/\/)?(www\.)?youtu(\.be\/|be\.com\/)', target):
|
|
|
|
|
youtube_session(target)
|
|
|
|
|
else:
|
|
|
|
|
local_session(target)
|
|
|
|
|
|
|
|
|
|
# symlink target to tempdir so we only expose a single file
|
|
|
|
|