fix: license + login5
This commit is contained in:
73
tests/test_login5.py
Normal file
73
tests/test_login5.py
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify Login5 authentication using stored credentials
|
||||
"""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import os
|
||||
from librespot.core import Session
|
||||
|
||||
# Enable debug logging to see what's happening
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
def test_with_stored_credentials():
|
||||
"""Test using stored credentials (if available)"""
|
||||
print("=== Testing with stored credentials ===")
|
||||
|
||||
try:
|
||||
if os.path.exists("credentials.json"):
|
||||
session = Session.Builder().stored_file("credentials.json").create()
|
||||
print(f"✓ Successfully authenticated as: {session.username()}")
|
||||
|
||||
# Test token retrieval
|
||||
token_provider = session.tokens()
|
||||
try:
|
||||
token = token_provider.get("playlist-read")
|
||||
print(f"✓ Successfully got playlist-read token: {token[:20]}...")
|
||||
|
||||
# Check if Login5 token is available
|
||||
login5_token = session.get_login5_token()
|
||||
if login5_token:
|
||||
print(f"✓ Login5 token available: {login5_token[:20]}...")
|
||||
else:
|
||||
print("⚠ Login5 token not available")
|
||||
|
||||
session.close()
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"✗ Token retrieval failed: {e}")
|
||||
session.close()
|
||||
return False
|
||||
else:
|
||||
print("⚠ No credentials.json file found")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ Authentication failed: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
print("Testing Login5 Authentication Implementation")
|
||||
print("=" * 50)
|
||||
|
||||
# Test with stored credentials
|
||||
stored_success = test_with_stored_credentials()
|
||||
|
||||
# Note: Username/password authentication has been deprecated by Spotify
|
||||
# and is no longer supported. Use stored credentials or OAuth flow instead.
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("Test Results:")
|
||||
print(f"Stored credentials: {'✓ PASS' if stored_success else '✗ FAIL or NO CREDENTIALS'}")
|
||||
|
||||
if stored_success:
|
||||
print("\n🎉 Login5 authentication is working!")
|
||||
return 0
|
||||
else:
|
||||
print("\n⚠ Could not test authentication - no valid credentials.json file found")
|
||||
print(" Please authenticate using OAuth or other supported methods first.")
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
86
tests/test_zeroconf_login5.py
Normal file
86
tests/test_zeroconf_login5.py
Normal file
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script using Zeroconf/Spotify Connect to verify Login5 authentication
|
||||
"""
|
||||
|
||||
import logging
|
||||
import time
|
||||
import pathlib
|
||||
from librespot.zeroconf import ZeroconfServer
|
||||
|
||||
# Enable debug logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
def test_zeroconf_login5():
|
||||
"""Test Login5 using Zeroconf authentication"""
|
||||
print("=== Testing Login5 with Zeroconf ===")
|
||||
print("1. Open Spotify on your phone/computer")
|
||||
print("2. Look for 'librespot-spotizerr' in Spotify Connect devices")
|
||||
print("3. Transfer playback to it")
|
||||
print("4. Wait for credentials to be stored...")
|
||||
print("\nWaiting for Spotify Connect transfer...")
|
||||
|
||||
zs = ZeroconfServer.Builder().create()
|
||||
|
||||
start_time = time.time()
|
||||
timeout = 60 # 60 seconds timeout
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
elapsed = time.time() - start_time
|
||||
|
||||
if elapsed > timeout:
|
||||
print(f"\n⚠ Timeout after {timeout} seconds")
|
||||
print("Make sure you:")
|
||||
print("- Have Spotify open on another device")
|
||||
print("- Can see 'librespot-spotizerr' in Spotify Connect")
|
||||
print("- Transfer playback to it")
|
||||
return False
|
||||
|
||||
if zs._ZeroconfServer__session:
|
||||
session = zs._ZeroconfServer__session
|
||||
print(f"\n✓ Got session for user: {session.username()}")
|
||||
|
||||
# Test token retrieval
|
||||
try:
|
||||
token_provider = session.tokens()
|
||||
token = token_provider.get("playlist-read")
|
||||
print(f"✓ Got playlist-read token: {token[:20]}...")
|
||||
|
||||
# Test Login5 token
|
||||
login5_token = session.get_login5_token()
|
||||
if login5_token:
|
||||
print(f"✓ Login5 token available: {login5_token[:20]}...")
|
||||
else:
|
||||
print("⚠ Login5 token not available")
|
||||
|
||||
# Check if credentials were saved
|
||||
if pathlib.Path("credentials.json").exists():
|
||||
print("✓ Credentials saved to credentials.json")
|
||||
print("\nYou can now use the stored credentials for future tests!")
|
||||
return True
|
||||
else:
|
||||
print("⚠ Credentials not saved")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ Token test failed: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
print("Zeroconf Login5 Test")
|
||||
print("=" * 30)
|
||||
|
||||
success = test_zeroconf_login5()
|
||||
|
||||
print("\n" + "=" * 30)
|
||||
if success:
|
||||
print("🎉 Zeroconf Login5 test completed successfully!")
|
||||
return 0
|
||||
else:
|
||||
print("⚠ Zeroconf test failed or timed out")
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user