parse.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #####################################################################
  2. # #
  3. # THIS IS A SOURCE CODE FILE FROM A PROGRAM TO INTERACT WITH THE #
  4. # LBRY PROTOCOL ( lbry.com ). IT WILL USE THE LBRY SDK ( lbrynet ) #
  5. # FROM THEIR REPOSITORY ( https://github.com/lbryio/lbry-sdk ) #
  6. # WHICH I GONNA PRESENT TO YOU AS A BINARY. SINCE I DID NOT DEVELOP #
  7. # IT AND I'M LAZY TO INTEGRATE IN A MORE SMART WAY. THE SOURCE CODE #
  8. # OF THE SDK IS AVAILABLE IN THE REPOSITORY MENTIONED ABOVE. #
  9. # #
  10. # ALL THE CODE IN THIS REPOSITORY INCLUDING THIS FILE IS #
  11. # (C) J.Y.Amihud and Other Contributors 2021. EXCEPT THE LBRY SDK. #
  12. # YOU CAN USE THIS FILE AND ANY OTHER FILE IN THIS REPOSITORY UNDER #
  13. # THE TERMS OF GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER #
  14. # VERSION. TO FIND THE FULL TEXT OF THE LICENSE GO TO THE GNU.ORG #
  15. # WEBSITE AT ( https://www.gnu.org/licenses/gpl-3.0.html ). #
  16. # #
  17. # THE LBRY SDK IS UNFORTUNATELY UNDER THE MIT LICENSE. IF YOU ARE #
  18. # NOT INTENDING TO USE MY CODE AND JUST THE SDK. YOU CAN FIND IT ON #
  19. # THEIR OFFICIAL REPOSITORY ABOVE. THEIR LICENSE CHOICE DOES NOT #
  20. # SPREAD ONTO THIS PROJECT. DON'T GET A FALSE ASSUMPTION THAT SINCE #
  21. # THEY USE A PUSH-OVER LICENSE, I GONNA DO THE SAME. I'M NOT. #
  22. # #
  23. # THE LICENSE CHOSEN FOR THIS PROJECT WILL PROTECT THE 4 ESSENTIAL #
  24. # FREEDOMS OF THE USER FURTHER, BY NOT ALLOWING ANY WHO TO CHANGE #
  25. # THE LICENSE AT WILL. SO NO PROPRIETARY SOFTWARE DEVELOPER COULD #
  26. # TAKE THIS CODE AND MAKE THEIR USER-SUBJUGATING SOFTWARE FROM IT. #
  27. # #
  28. #####################################################################
  29. def bar(text):
  30. # This function is intended to parse the bar in the
  31. # top of the FastLBRY GTK application.
  32. ##### Converting an HTTPS domain ( of any website ) into lbry url ###
  33. # Any variation of this:
  34. # https://odysee.com/@blenderdumbass:f/hacking-fastlbry-live-with-you:6
  35. # customlbry.com/@blenderdumbass:f/hacking-fastlbry-live-with-you:6
  36. # Should become this:
  37. # lbry://@blenderdumbass:f/hacking-fastlbry-live-with-you:6
  38. if "?" in text:
  39. # This means some kinds of variables given to the server through HTTP
  40. # we should ignore them
  41. text = text[:text.rfind("?")]
  42. if "api/" in text and "free/" in text:
  43. # The link might resemble something like:
  44. # https://cdn.lbryplayer.xyz/api/v4/streams/free/cc-by-sa-credit-01/38688684ce7164cbb21fcef7c49414854375b6fd/84f493
  45. name = text[text.find("free/")+5 :]
  46. name = name[:name.rfind("/")]
  47. name = name.replace("/", ":")
  48. return name
  49. if "/" in text and not text.startswith("@") and not text.startswith("lbry://"):
  50. if "@" in text:
  51. text = text[text.find("@"):]
  52. else:
  53. text = text[text.rfind("/")+1:]
  54. #text = "lbry://"+text
  55. return text