MPDPCP/mpdpcontrol.py

165 lines
5.3 KiB
Python
Raw Normal View History

2023-07-12 08:53:11 +03:00
import requests
import getpass
import time
2023-07-12 08:53:11 +03:00
print("""
\033[38;5;15m
__ ______ ___ ___ _____ __ __
/ |/ / _ \/ _ \/ _ \ / ___/__ ___ / /________ / /
/ /|_/ / ___/ // / ___/ / /__/ _ \/ _ \/ __/ __/ _ \/ /
/_/ /_/_/ /____/_/ \___/\___/_//_/\__/_/ \___/_/
Created by Phantom
Version: 2.0
2023-07-12 08:53:11 +03:00
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",
"Accept": "application/json",
"Connection": "keep-alive",
"DNT": "1",
"Origin": f"{URL}/ui",
}
login_data = {
"operationName": "login",
"variables": {"login": USER, "password": PASSWORD},
"query": "mutation login($login: String!, $password: String!) {\n login(login: $login, password: $password)\n}",
}
response = requests.post(f"{URL}/api/graphql", headers=headers, json=login_data)
if response.status_code != 200:
print("Failed to login")
return
token = response.json()["data"]["login"]
headers["Authorization"] = f"Bearer {token}"
data = {
"operationName": operationName,
"variables": variables,
"query": query,
}
response = requests.post(f"{URL}/api/graphql", headers=headers, json=data)
if response.status_code == 200:
format_data(response.json())
else:
print("Failed to fetch data")
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. Restart Channels\033[0m")
print("\033[96m5. Exit\033[0m")
2023-07-12 08:53:11 +03:00
def format_channels(data):
channels = data["data"]["channels"]["channels"]
for channel in channels:
print(f"Channel ID: {channel['id']}")
print(f"Channel Name: {channel['name']}")
print(f"Channel Language: {channel['lang']}")
print(f"Channel URL: {channel['url']}")
print("-----------------------------------")
def format_providers(data):
providers = data["data"]["providers"]
for provider in providers:
print(f"Provider ID: {provider['id']}")
print(f"Provider Name: {provider['name']}")
print(f"Engine: {provider['engine']}")
print(f"Proxy: {provider['proxy']}")
print(f"Format: {provider['format']}")
print("-----------------------------------")
def format_categories(data):
categories = data["data"]["categories"]
for category in categories:
print(f"Category ID: {category['id']}")
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)
2023-07-12 08:53:11 +03:00
server_address = input("Enter server address (including port):")
URL = f"http://{server_address}"
USER = input("Enter username: ")
PASSWORD = getpass.getpass("Enter password: ")
while True:
print_menu()
2023-07-12 08:53:11 +03:00
choice = input("Enter your choice: ")
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":
2023-07-12 08:53:11 +03:00
break
else:
print("Invalid choice")