test.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #GPL3 +
  2. import os
  3. import json
  4. import time
  5. from modules import youtube
  6. # "8eJEtnPUekY": {
  7. # "title": "Be Like That (From \"American Pie\" Soundtrack)",
  8. # "file": "/home/blenderdumbass/.matrix_music/8eJEtnPUekY.opus",
  9. # "duration": 237,
  10. # "timestamp": 1676962180,
  11. # "last_played": 1678008344
  12. # }
  13. with open('stuff.json') as json_file:
  14. stuff = json.load(json_file)
  15. p = 0
  16. for i in stuff["users"]:
  17. for song in stuff["users"][i]["history"]:
  18. fix = False
  19. try:
  20. info = stuff["songs"][song]
  21. if info.get("title") == song:
  22. print(song, "Title Is Link")
  23. p = p + 1
  24. fix = True
  25. elif type(info.get("title")) != str:
  26. print(song, "Title Type is Wrong")
  27. p = p + 1
  28. fix = True
  29. elif type(info.get("file")) != str:
  30. print(song, "File Type is Wrong")
  31. p = p + 1
  32. fix = True
  33. elif type(info.get("duration")) != int:
  34. print(song, "Duration Type is Wrong")
  35. p = p + 1
  36. elif type(info.get("timestamp")) != int:
  37. print(song, "Timestamp Type is Wrong")
  38. p = p + 1
  39. fix = True
  40. except:
  41. print(song, "Data Missing")
  42. p = p + 1
  43. fix = True
  44. if fix:
  45. print("Fixing:", song)
  46. videoId = song
  47. info = youtube.fetch_info(videoId)
  48. length = info.get("lengthSeconds", 9999999999999999)
  49. title = info.get("title", "")
  50. print(" Title:", title)
  51. print(" Length", length)
  52. stuff["songs"][videoId] = {"title":title,
  53. "file":None,
  54. "duration":length,
  55. "timestamp":int(time.time())}
  56. print()
  57. print()
  58. print(p, "problems in total.")
  59. print("Saving!")
  60. with open('stuff.json', 'w') as fp:
  61. json.dump(stuff, fp, indent=4)