lbry-md-to-html.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python
  2. import requests
  3. import sys
  4. import os
  5. url = "lbry://@Nasikla:5/HSMMPS:a"
  6. def resolve(url):
  7. json = {
  8. "jsonrpc": "2.0",
  9. "method": "resolve",
  10. "params": {
  11. "urls": [
  12. url
  13. ],
  14. "include_purchase_receipt": True,
  15. "include_is_my_output": True
  16. },
  17. "id": 1625272172800
  18. }
  19. data = requests.post("https://api.na-backend.odysee.com/api/v1/proxy?m=resolve", json=json)
  20. return data
  21. def get(url):
  22. #OLD WAY
  23. #claim = resolve["claim_id"]
  24. #name = resolve["name"]
  25. ## I do not know what is the name of this..
  26. #hashcut = resolve["value"]["source"]["sd_hash"][:6]
  27. ##https://player.odycdn.com/api/v4/streams/free/HSMMPS/ac721fb7b4628e43e5f6b824334b77aba4f3fa4b/9e9c17
  28. #text = requests.get(f"https://player.odycdn.com/api/v4/streams/free/{name}/{claim}/{hashcut}").text
  29. json = {
  30. "jsonrpc":"2.0",
  31. "method":"get",
  32. "params": {
  33. "uri": url,
  34. "save_file": False
  35. },
  36. "id":1625272174700
  37. }
  38. data = requests.post("https://api.na-backend.odysee.com/api/v1/proxy?m=resolve", json=json).json()
  39. return data["result"]["streaming_url"]
  40. def main():
  41. resolve = resolve(url).json()["result"][url]
  42. if resolve["value"]["source"]["media_type"] == "text/markdown":
  43. file = resolve["value"]["source"]["name"]
  44. # This is not perfect
  45. export = file.split(".")[0]+".html"
  46. with open(file, "w", encoding="utf-8") as f:
  47. f.write(requests.get(get(url)).text)
  48. os.system(f'pandoc {file} -o {export}')
  49. else:
  50. sys.exit("This is not a markdown publication.")
  51. if __name__ == "__main__":
  52. main()