Add tauon-controls script.
This commit is contained in:
		
							parent
							
								
									8696f234c8
								
							
						
					
					
						commit
						12131285de
					
				| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
import argparse
 | 
			
		||||
import requests
 | 
			
		||||
 | 
			
		||||
HIDDEN_API = "http://0.0.0.0:7813"
 | 
			
		||||
REMOTE_API = "http://0.0.0.0:7814/api1"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def main() -> None:
 | 
			
		||||
    parser = argparse.ArgumentParser(description="Small Tauon remote control CLI")
 | 
			
		||||
    group = parser.add_mutually_exclusive_group(required=True)
 | 
			
		||||
    group.add_argument("--next-song", action="store_true")
 | 
			
		||||
    group.add_argument("--play-pause", action="store_true")
 | 
			
		||||
    group.add_argument("--previous-song", action="store_true")
 | 
			
		||||
    group.add_argument("--volume", type=int)
 | 
			
		||||
    args = parser.parse_args()
 | 
			
		||||
 | 
			
		||||
    if args.next_song:
 | 
			
		||||
        call_api(f"{REMOTE_API}/next")
 | 
			
		||||
    if args.play_pause:
 | 
			
		||||
        call_api(f"{HIDDEN_API}/playpause/")
 | 
			
		||||
    if args.previous_song:
 | 
			
		||||
        call_api(f"{REMOTE_API}/back")
 | 
			
		||||
    if args.volume is not None:
 | 
			
		||||
        call_api(f"{REMOTE_API}/setvolumerel/{args.volume}")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def call_api(endpoint: str) -> None:
 | 
			
		||||
    response = requests.get(endpoint)
 | 
			
		||||
    print(f"HTTP {response.status_code} ({endpoint})")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    main()
 | 
			
		||||
		Reference in New Issue