mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-09 13:26:44 +03:00
Fix the docker bug #22
Make video ids hashed Get 10 videos from youtube to make sure that the right id is found Refactored the api calls
This commit is contained in:
@@ -9,13 +9,15 @@ def save_config(config, config_file):
|
||||
with open(config_file, "w") as f:
|
||||
json.dump(config, f)
|
||||
|
||||
#Taken from postlund/pyatv atvremote.py
|
||||
|
||||
# Taken from postlund/pyatv atvremote.py
|
||||
async def _read_input(loop: asyncio.AbstractEventLoop, prompt: str):
|
||||
sys.stdout.write(prompt)
|
||||
sys.stdout.flush()
|
||||
user_input = await loop.run_in_executor(None, sys.stdin.readline)
|
||||
return user_input.strip()
|
||||
|
||||
|
||||
async def find_atvs(loop):
|
||||
devices = await pyatv.scan(loop)
|
||||
if not devices:
|
||||
@@ -23,14 +25,20 @@ async def find_atvs(loop):
|
||||
return
|
||||
atvs = []
|
||||
for i in devices:
|
||||
#Only get Apple TV's
|
||||
if i.device_info.model in [DeviceModel.Gen4, DeviceModel.Gen4K, DeviceModel.AppleTV4KGen2]:
|
||||
#if i.device_info.model in [DeviceModel.AppleTV4KGen2]: #FOR TESTING
|
||||
# Only get Apple TV's
|
||||
if i.device_info.model in [
|
||||
DeviceModel.Gen4,
|
||||
DeviceModel.Gen4K,
|
||||
DeviceModel.AppleTV4KGen2,
|
||||
]:
|
||||
# if i.device_info.model in [DeviceModel.AppleTV4KGen2]: #FOR TESTING
|
||||
if input("Found {}. Do you want to add it? (y/n) ".format(i.name)) == "y":
|
||||
|
||||
identifier = i.identifier
|
||||
|
||||
pairing = await pyatv.pair(i, loop=loop, protocol=pyatv.Protocol.AirPlay)
|
||||
pairing = await pyatv.pair(
|
||||
i, loop=loop, protocol=pyatv.Protocol.AirPlay
|
||||
)
|
||||
await pairing.begin()
|
||||
if pairing.device_provides_pin:
|
||||
pin = await _read_input(loop, "Enter PIN on screen: ")
|
||||
@@ -39,18 +47,23 @@ async def find_atvs(loop):
|
||||
await pairing.finish()
|
||||
if pairing.has_paired:
|
||||
creds = pairing.service.credentials
|
||||
atvs.append({"identifier": identifier, "airplay_credentials": creds})
|
||||
atvs.append(
|
||||
{"identifier": identifier, "airplay_credentials": creds}
|
||||
)
|
||||
print("Pairing successful")
|
||||
await pairing.close()
|
||||
return atvs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def main(config, config_file, debug):
|
||||
try: num_atvs = len(config["atvs"])
|
||||
except: num_atvs = 0
|
||||
if input("Found {} Apple TV(s) in config.json. Add more? (y/n) ".format(num_atvs)) == "y":
|
||||
try:
|
||||
num_atvs = len(config["atvs"])
|
||||
except:
|
||||
num_atvs = 0
|
||||
if (
|
||||
input("Found {} Apple TV(s) in config.json. Add more? (y/n) ".format(num_atvs))
|
||||
== "y"
|
||||
):
|
||||
loop = asyncio.get_event_loop_policy().get_event_loop()
|
||||
if debug:
|
||||
loop.set_debug(True)
|
||||
@@ -62,39 +75,42 @@ def main(config, config_file, debug):
|
||||
for i in atvs:
|
||||
config["atvs"].append(i)
|
||||
print("done adding")
|
||||
except:
|
||||
except:
|
||||
print("rewriting atvs (don't worry if none were saved before)")
|
||||
config["atvs"] = atvs
|
||||
|
||||
try : apikey = config["apikey"]
|
||||
except:
|
||||
|
||||
try:
|
||||
apikey = config["apikey"]
|
||||
except:
|
||||
apikey = ""
|
||||
if apikey != "" :
|
||||
if apikey != "":
|
||||
if input("Apikey already specified. Change it? (y/n) ") == "y":
|
||||
apikey = input("Enter your API key: ")
|
||||
config["apikey"] = apikey
|
||||
else:
|
||||
print("get youtube apikey here: https://developers.google.com/youtube/registering_an_application")
|
||||
print(
|
||||
"get youtube apikey here: https://developers.google.com/youtube/registering_an_application"
|
||||
)
|
||||
apikey = input("Enter your API key: ")
|
||||
config["apikey"] = apikey
|
||||
|
||||
try: skip_categories = config["skip_categories"]
|
||||
except:
|
||||
|
||||
try:
|
||||
skip_categories = config["skip_categories"]
|
||||
except:
|
||||
skip_categories = []
|
||||
|
||||
|
||||
if skip_categories != []:
|
||||
if input("Skip categories already specified. Change them? (y/n) ") == "y":
|
||||
categories = input("Enter skip categories (space sepparated) Options: [sponsor, selfpromo, exclusive_access, interaction, poi_highlight, intro, outro, preview, filler, music_offtopic:\n")
|
||||
categories = input(
|
||||
"Enter skip categories (space sepparated) Options: [sponsor, selfpromo, exclusive_access, interaction, poi_highlight, intro, outro, preview, filler, music_offtopic:\n"
|
||||
)
|
||||
skip_categories = categories.split(" ")
|
||||
else:
|
||||
categories = input("Enter skip categories (space sepparated) Options: [sponsor, selfpromo, exclusive_access, interaction, poi_highlight, intro, outro, preview, filler, music_offtopic:\n")
|
||||
categories = input(
|
||||
"Enter skip categories (space sepparated) Options: [sponsor, selfpromo, exclusive_access, interaction, poi_highlight, intro, outro, preview, filler, music_offtopic:\n"
|
||||
)
|
||||
skip_categories = categories.split(" ")
|
||||
config["skip_categories"] = skip_categories
|
||||
|
||||
print("config finished")
|
||||
save_config(config, config_file)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("starting")
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user