invidious.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. # Imports
  3. import requests
  4. import json
  5. import os
  6. # Coloring
  7. bold="\033[01m"
  8. norm="\033[00m"
  9. bright_cyan="\033[46m"
  10. colora="\033[45m"
  11. colorb="\033[44m"
  12. invidious_instance = "https://invidio.xamh.de/"
  13. query = input("Searching for: ")
  14. query = str(query)
  15. size = str(19)
  16. invidious_search = invidious_instance + "api/v1/search?q=" + query
  17. wol_api = "https://scrap.madiator.com/api/get-lbry-video?url="
  18. command = "mpv "
  19. launcher = "fzf "
  20. data = requests.get(invidious_search)
  21. json_stuff = json.loads(data.text)
  22. for i, vid in enumerate(json_stuff):
  23. print(i, colora+vid["title"]+norm+"\n"+colorb+vid["author"]+norm+"\n"+bright_cyan+vid["videoId"]+norm)
  24. c = 100000
  25. while not c >= 0 or not c <= 19:
  26. c = input('Number from 1-' + size + " of the URL you want to open: ")
  27. try:
  28. c = int(c)
  29. except:
  30. c = 100000
  31. # wol-api check
  32. lbry_check = requests.get(wol_api + json_stuff[c]["videoId"])
  33. lbry_check = json.loads(lbry_check.text)
  34. # For now using odysee because yt-dlp doesn't support librarian
  35. librarian_instance = "https://odysee.com/"
  36. if lbry_check["lbryurl"] == None:
  37. # Using youtube.com since yt-dlp on any given invidious url redirects to youtube.com anyways.
  38. selected_url = "https://youtube.com/watch?v=" + json_stuff[c]["videoId"]
  39. else:
  40. selected_url = librarian_instance + lbry_check["lbryurl"]
  41. selected_url = selected_url.replace("#", ":")
  42. comments = invidious_instance + "/api/v1/comments/" + json_stuff[c]["videoId"]
  43. data_comment = requests.get(comments)
  44. json_comment = json.loads(data_comment.text)
  45. for i, comment in enumerate(json_comment["comments"]):
  46. print(i, colora+comment["author"]+norm+"\n"+colorb+comment["content"]+norm)
  47. # Do stuff with it.
  48. os.system(command + selected_url)
  49. quit()