Advertisement
Guest User

Untitled

a guest
Jun 28th, 2024
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import requests
  2.  
  3. def upload_to_listreamed(api_key, file_path):
  4. response = requests.get(f"https://api.vidguard.to/v1/upload/server?key={api_key}")
  5. response_data = response.json()
  6.  
  7. if response_data['msg'] != "Done":
  8. raise Exception(f"Failed to get upload URL: {response_data['msg']}")
  9.  
  10. upload_url = response_data['result']['url']
  11.  
  12. with open(file_path, 'rb') as f:
  13. files = {'file': f}
  14. data = {'key': api_key}
  15. upload_response = requests.post(upload_url, files=files, data=data)
  16. try:
  17. upload_response_data = upload_response.json()
  18. except ValueError:
  19. print("Failed to parse response as JSON:")
  20. print(upload_response.text)
  21. raise
  22.  
  23. if upload_response_data['status'] != 200:
  24. raise Exception(f"Failed to upload file: {upload_response_data['msg']}")
  25.  
  26. return upload_response_data['result']['URL']
  27.  
  28. api_key_listreamed = "My Key, don't worry this is replaced correctly"
  29. file_path = "My file path, don't worry this is replaced correctly"
  30.  
  31. try:
  32. listeamed_url = upload_to_listreamed(api_key_listreamed, file_path)
  33. print("Listeamed URL:", listeamed_url)
  34. except Exception as e:
  35. print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement