Last active
March 2, 2024 18:51
-
-
Save smyhlin/156472023a80c92d7acabcdf82f57059 to your computer and use it in GitHub Desktop.
Locally run http Lampa server on your local PC on 8000 port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## [Lampa](https://github.com/yumata/lampa) - online cinema and torrent catalog | |
## Torent files(movies) can be streamed throught [TorrServe](https://github.com/YouROK/TorrServer) application | |
import http.server | |
import os | |
import sys | |
import socketserver | |
import time | |
import requests | |
from zipfile import ZipFile | |
# Get from Github Repo application source code and unzip it | |
def download_and_setup_lampa(user_ip): | |
URL = "https://github.com/yumata/lampa/archive/refs/heads/main.zip" | |
response = requests.get(URL) | |
open(f"{os.path.dirname(os.path.abspath(__file__))}/lampa.zip", "wb").write(response.content) | |
with ZipFile(f"{os.path.dirname(os.path.abspath(__file__))}/lampa.zip", "r") as zipObj: | |
# Extract all the contents of zip file in current directory | |
zipObj.extractall(f"{os.path.dirname(os.path.abspath(__file__))}") | |
os.remove(f"{os.path.dirname(os.path.abspath(__file__))}/lampa.zip") | |
replace_msx_host(user_ip) | |
run_lampa_server() | |
# Config server ip addres to you local machine`s | |
def replace_msx_host(user_ip): | |
JSON_FILE = ( | |
os.path.dirname(os.path.abspath(__file__)) + "/lampa-main/msx/start.json" | |
) | |
# Read in the file | |
with open(JSON_FILE, "r") as file: | |
filedata = file.read() | |
# Replace the target string | |
filedata = filedata.replace("{domain}", f"{user_ip}:43001") | |
# Write the file out again | |
with open(JSON_FILE, "w") as file: | |
file.write(filedata) | |
def run_lampa_server(): | |
PORT = 43001 | |
DIRECTORY = os.path.dirname(os.path.abspath(__file__)) + "/lampa-main" | |
if not os.path.exists(DIRECTORY): | |
print("Could not find lampa source") | |
exit(1) | |
class Handler(http.server.SimpleHTTPRequestHandler): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, directory=DIRECTORY, **kwargs) | |
with socketserver.TCPServer(("", PORT), Handler) as httpd: | |
while True: | |
try: | |
os.system("cls") | |
print("serving at port", PORT) | |
httpd.serve_forever() | |
except: | |
print("server error - rebooting") | |
time.sleep(3) | |
continue | |
def main(): | |
to_do = int( | |
input("1 - download & setup lampa:\n" "2 - start existing lampa:\n" ">>> ") | |
) | |
while True: | |
if to_do == 1: | |
user_ip = input( | |
"Local server ip from Router [NOT 127.0.0.1 or localhost]: " | |
) | |
download_and_setup_lampa(user_ip) | |
break | |
elif to_do == 2: | |
run_lampa_server() | |
if __name__ == "__main__": | |
print('If you want setup run with -s key') | |
if len(sys.argv) < 2:run_lampa_server() | |
else:main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requerments.txt :