Update site-list.py

This commit is contained in:
Arjix 2021-10-04 20:19:39 +03:00 committed by GitHub
parent 5c97942f92
commit 136d44dc85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

31
.github/site-list.py vendored
View file

@ -1,19 +1,22 @@
#!/usr/bin/python3 #!/usr/bin/python3
from glob import glob from glob import glob
from re import findall, search, compile, sub, DOTALL from re import findall, compile, sub, DOTALL
from typing import List, Dict
# Globals # Globals
URL_REGEX = compile("override val mainUrl(?:\:\s?String)?[^\"']+[\"'](https?://[a-zA-Z0-9\.-]+)[\"']") URL_REGEX = compile(
"override val mainUrl(?:\:\s?String)?[^\"']+[\"'](https?://[a-zA-Z0-9\.-]+)[\"']")
NAME_REGEX = compile("class (.+?) ?: MainAPI\(\)") NAME_REGEX = compile("class (.+?) ?: MainAPI\(\)")
START_MARKER = "<!--SITE LIST START-->" START_MARKER = "<!--SITE LIST START-->"
END_MARKER = "<!--SITE LIST END-->" END_MARKER = "<!--SITE LIST END-->"
GLOB = "app/src/main/java/com/lagradost/cloudstream3/*providers/*Provider.kt" GLOB = "app/src/main/java/com/lagradost/cloudstream3/*providers/*Provider.kt"
MAIN_API = "app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt" MAIN_API = "app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt"
API_REGEX = compile("val (?:restrictedA|a)pis = arrayListOf\((.+?)\)(?=\n\n)", DOTALL) API_REGEX = compile(
"val (?:restrictedA|a)pis = arrayListOf\((.+?)\)(?=\n\n)", DOTALL)
sites = [] sites: Dict[str, str] = {}
enabled_sites = [] enabled_sites: List[str] = []
with open(MAIN_API, "r", encoding="utf-8") as f: with open(MAIN_API, "r", encoding="utf-8") as f:
@ -27,16 +30,19 @@ with open(MAIN_API, "r", encoding="utf-8") as f:
for path in glob(GLOB): for path in glob(GLOB):
with open(path, "r", encoding='utf-8') as file: with open(path, "r", encoding='utf-8') as file:
try: try:
site_text = file.read() site_text: str = file.read()
name = findall(NAME_REGEX, site_text) name: List[str] = findall(NAME_REGEX, site_text)
provider_text: str = findall(URL_REGEX, site_text)
if name: if name:
if name[0] not in enabled_sites: if name[0] not in enabled_sites:
continue continue
url = search(URL_REGEX, site_text).groups()[0] sites[name[0]] = provider_text[0]
sites.append(url)
except Exception as ex: except Exception as ex:
print("{0}: {1}".format(path, ex)) print("{0}: {1}".format(path, ex))
with open("README.md", "r+", encoding='utf-8') as readme: with open("README.md", "r+", encoding='utf-8') as readme:
raw = readme.read() raw = readme.read()
if START_MARKER not in raw or END_MARKER not in raw: if START_MARKER not in raw or END_MARKER not in raw:
@ -46,9 +52,10 @@ with open("README.md", "r+", encoding='utf-8') as readme:
readme.write(raw.split(START_MARKER)[0]) readme.write(raw.split(START_MARKER)[0])
readme.write(START_MARKER+"\n") readme.write(START_MARKER+"\n")
for site in sites: for site in enabled_sites:
readme.write( if site in sites:
"- [{0}]({1}) \n".format(sub("^https?://", "", site), site)) readme.write(
"- [{0}]({1}) \n".format(sub("^https?://", "", sites[site]), sites[site]))
readme.write(END_MARKER) readme.write(END_MARKER)
readme.write(raw.split(END_MARKER)[-1]) readme.write(raw.split(END_MARKER)[-1])