From bb9541c9ed0dc05231f5aae3fc1067396572db30 Mon Sep 17 00:00:00 2001 From: Phantom Date: Sun, 16 Jul 2023 12:14:21 +0300 Subject: [PATCH] update version Added function for restart streams --- mpdpcontrol.py | 83 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 19 deletions(-) diff --git a/mpdpcontrol.py b/mpdpcontrol.py index 6a65538..c7a3ddb 100644 --- a/mpdpcontrol.py +++ b/mpdpcontrol.py @@ -1,5 +1,6 @@ import requests import getpass +import time print(""" \033[38;5;15m @@ -12,14 +13,13 @@ print(""" Created by Phantom -Version: 1.0 +Version: 2.0 Telegram: https://t.me/PHMSupport Special for: DRMStuff.com \033[0m \n\n\n\n""") - def fetch_data(URL, USER, PASSWORD, operationName, variables, query, format_data): headers = { "Content-Type": "application/json", @@ -41,8 +41,6 @@ def fetch_data(URL, USER, PASSWORD, operationName, variables, query, format_data print("Failed to login") return - - token = response.json()["data"]["login"] headers["Authorization"] = f"Bearer {token}" @@ -63,7 +61,8 @@ def print_menu(): print("\033[96m1. Fetch Channels\033[0m") print("\033[96m2. Fetch Providers\033[0m") print("\033[96m3. Fetch Categories\033[0m") - print("\033[96m4. Exit\033[0m") + print("\033[96m4. Restart Channels\033[0m") + print("\033[96m5. Exit\033[0m") def format_channels(data): channels = data["data"]["channels"]["channels"] @@ -91,6 +90,52 @@ def format_categories(data): print(f"Category Label: {category['label']}") print("-----------------------------------") +def restart_channels(URL, CHANNEL_IDS, MPD_PANEL): + headers = { + "Content-Type": "application/json", + "Accept": "application/json", + "Connection": "keep-alive", + "DNT": "1", + "Origin": f"{URL}/ui", + } + + ids = CHANNEL_IDS.split(",") + + if MPD_PANEL.lower() == "v3": + for channel_id in ids: + channel_id = channel_id.strip() + restart = { + "operationName": "Restart", + "variables": { + "id": int(channel_id), + }, + "query": "query Restart($id: Int!) {\n restart(id: $id)\n}", + } + requests.post(f"{URL}/api/graphql", headers=headers, json=restart) + time.sleep(1) + + else: + for channel_id in ids: + channel_id = channel_id.strip() + stop = { + "operationName": "Stop", + "variables": { + "id": int(channel_id), + }, + "query": "query Stop($id: Int!) {\n stop(id: $id)\n}", + } + requests.post(f"{URL}/api/graphql", headers=headers, json=stop) + time.sleep(1.5) + + start = { + "operationName": "Play", + "variables": { + "id": int(channel_id), + }, + "query": "query Play($id: Int!) {\n play(id: $id)\n}", + } + requests.post(f"{URL}/api/graphql", headers=headers, json=start) + time.sleep(1.5) server_address = input("Enter server address (including port):") URL = f"http://{server_address}" @@ -100,20 +145,20 @@ PASSWORD = getpass.getpass("Enter password: ") while True: print_menu() + choice = input("Enter your choice: ") - if choice == '1': - fetch_data(URL, USER, PASSWORD, "channels", {"limit": 50, "offset": 0, "model": {"lang": "", "provider": "", "searchString": ""}}, - "query channels($limit: Int!, $offset: Long!, $model: ChannelFilterModel!) {\n channels(limit: $limit, offset: $offset, model: $model) {\n channels {\n id\n name\n lang\n url\n }\n hasMore\n }\n}", - format_channels) - elif choice == '2': - fetch_data(URL, USER, PASSWORD, "providers", {}, - "query providers {\n providers {\n id\n name\n engine\n proxy\n format\n }\n}", - format_providers) - elif choice == '3': - fetch_data(URL, USER, PASSWORD, "categories", {}, - "query categories {\n categories {\n id\n label\n }\n}", - format_categories) - elif choice == '4': + + if choice == "1": + fetch_data(URL, USER, PASSWORD, "Channels", {}, "query Channels {\n channels {\n channels {\n id\n name\n lang\n url\n }\n }\n}", format_channels) + elif choice == "2": + fetch_data(URL, USER, PASSWORD, "Providers", {}, "query Providers {\n providers {\n id\n name\n engine\n proxy\n format\n }\n}", format_providers) + elif choice == "3": + fetch_data(URL, USER, PASSWORD, "Categories", {}, "query Categories {\n categories {\n id\n label\n }\n}", format_categories) + elif choice == "4": + CHANNEL_IDS = input("Enter channel ids (comma separated): ") + MPD_PANEL = input("Enter MPD Panel version: ") + restart_channels(URL, CHANNEL_IDS, MPD_PANEL) + elif choice == "5": break else: - print("Invalid choice. Please try again.") + print("Invalid choice")