peertube.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # Variables
  13. query = input("Searching for: ")
  14. query = str(query)
  15. size = str(19)
  16. search = "https://sepiasearch.org/api/v1/search/videos?search=" + query
  17. command = "mpv "
  18. data = requests.get(search)
  19. json_stuff = json.loads(data.text)
  20. for i, vid in enumerate(json_stuff["data"]):
  21. print(i, colora+vid["name"]+norm+"\n"+colorb+vid["channel"]["displayName"]+norm+"\n"+bright_cyan+vid["url"]+norm)
  22. # Choose a result
  23. c = 100000
  24. while not c >= 0 or not c <= 19:
  25. c = input('Number from 1-' + size + " of the URL you want to open: ")
  26. try:
  27. c = int(c)
  28. except:
  29. c = 100000
  30. selected_url = json_stuff["data"][c]["url"]
  31. comments = "https://" + json_stuff["data"][c]["account"]["host"] + "/api/v1/videos/" + json_stuff["data"][c]["uuid"] + "/comment-threads/"
  32. data_comment = requests.get(comments)
  33. json_comment = json.loads(data_comment.text)
  34. # PRINT COMMENTS!
  35. for i, comment in enumerate(json_comment["data"]):
  36. # Sometimes peertube likes to give nonsese json
  37. if comment["account"] == None:
  38. print(i, "No Account Data")
  39. # This detects if a comment has replies.
  40. elif comment["totalReplies"] > 0:
  41. replies = comments + str(comment["id"])
  42. data_replies = requests.get(replies)
  43. json_replies = json.loads(data_replies.text)
  44. total_replies = str(json_replies["comment"]["totalReplies"])
  45. # Print out that this comment has replies and also say how many
  46. print(i, colora+comment["account"]["displayName"]+norm+"\n"+colorb+comment["text"]+norm+bright_cyan+"\nREPLIES: "+total_replies+norm)
  47. # Here in this for loop inside of a for loop for replys
  48. for i, reply in enumerate(json_replies["children"]):
  49. # Same thing can happen where it gives nonsense json.
  50. if reply["comment"]["account"] == None:
  51. print(i, "No Account Data")
  52. # This prints out the first reply.
  53. else:
  54. print(" " + str(i) + " " + colora+reply["comment"]["account"]["displayName"]+norm+"\n "+colorb+reply["comment"]["text"]+norm)
  55. # This is the final thing, the comment has no replys so it just
  56. # prints it as a comment.
  57. else:
  58. print(i, colora+comment["account"]["displayName"]+norm+"\n"+colorb+comment["text"]+norm)
  59. os.system(command + selected_url)