123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #####################################################################
- # #
- # THIS IS A SOURCE CODE FILE FROM A PROGRAM TO INTERACT WITH THE #
- # LBRY PROTOCOL ( lbry.com ). IT WILL USE THE LBRY SDK ( lbrynet ) #
- # FROM THEIR REPOSITORY ( https://github.com/lbryio/lbry-sdk ) #
- # WHICH I GONNA PRESENT TO YOU AS A BINARY. SINCE I DID NOT DEVELOP #
- # IT AND I'M LAZY TO INTEGRATE IN A MORE SMART WAY. THE SOURCE CODE #
- # OF THE SDK IS AVAILABLE IN THE REPOSITORY MENTIONED ABOVE. #
- # #
- # ALL THE CODE IN THIS REPOSITORY INCLUDING THIS FILE IS #
- # (C) J.Y.Amihud and Other Contributors 2021. EXCEPT THE LBRY SDK. #
- # YOU CAN USE THIS FILE AND ANY OTHER FILE IN THIS REPOSITORY UNDER #
- # THE TERMS OF GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER #
- # VERSION. TO FIND THE FULL TEXT OF THE LICENSE GO TO THE GNU.ORG #
- # WEBSITE AT ( https://www.gnu.org/licenses/gpl-3.0.html ). #
- # #
- # THE LBRY SDK IS UNFORTUNATELY UNDER THE MIT LICENSE. IF YOU ARE #
- # NOT INTENDING TO USE MY CODE AND JUST THE SDK. YOU CAN FIND IT ON #
- # THEIR OFFICIAL REPOSITORY ABOVE. THEIR LICENSE CHOICE DOES NOT #
- # SPREAD ONTO THIS PROJECT. DON'T GET A FALSE ASSUMPTION THAT SINCE #
- # THEY USE A PUSH-OVER LICENSE, I GONNA DO THE SAME. I'M NOT. #
- # #
- # THE LICENSE CHOSEN FOR THIS PROJECT WILL PROTECT THE 4 ESSENTIAL #
- # FREEDOMS OF THE USER FURTHER, BY NOT ALLOWING ANY WHO TO CHANGE #
- # THE LICENSE AT WILL. SO NO PROPRIETARY SOFTWARE DEVELOPER COULD #
- # TAKE THIS CODE AND MAKE THEIR USER-SUBJUGATING SOFTWARE FROM IT. #
- # #
- #####################################################################
- # This file will perform a simple search on the LBRY network.
- from subprocess import *
- import json
- from flbry import url
- from flbry.variables import *
- def simple(args=""):
-
-
- # The user might write the search argument right in the same
- # line as the work search.
- #
- # : seach blenderdumbass
- #
- # Or they can type nothing. And be confused of what happened.
- # So I want to provide a catcher here. If they type nothing it
- # will ask them to provide a search query.
- if not args:
- args = input(" Channel url :: ")
- if not args.startswith("@") and not args.startswith("lbry://@"):
- args = "@"+args
-
- # So we want to request a query to the SDK to search what ever
- # the user wants. The problem is it can be a very large output.
- # For example the "blender dumbass" query returns 1000 claims
- # on the LBRY network. And people will wait for a very long time
- # on something that might have a million claims.
- # So instead we are going to request only the first 20 and let
- # the user load more.
- w, h = tsize()
-
- page_size = h - 5
- page = 1
-
- while True:
- # Printing the search query and page number
- center("CHANNEL: "+args+" PAGE:"+str(page))
-
- out = check_output(["flbry/lbrynet",
- "claim", "search", '--channel='+args,
- '--page='+str(page),
- '--page_size='+str(page_size),
- "--no_totals",
- '--order_by=release_time'])
- # Now we want to parse the json
-
- try:
- out = json.loads(out)
- except:
- print(" Connect to LBRY first.")
- return
-
-
- try:
- data_print = {"categories":["Type", "Title"],
- "size":[1,5],
- "data":[]}
- # List what we found
- for n, i in enumerate(out["items"]):
-
- title = "---!Failed Loading Title---"
- ftype = "claim"
-
- try:
- try:
- title = i["value"]["title"]
- except:
- title = i['name']
-
- try:
- ftype = what[i["value"]["stream_type"]]
- except:
- ftype = what[i["value_type"]]
- except:
- pass
-
-
- data_print["data"].append([ftype, title])
- table(data_print)
- # Tell the user that he might want to load more
- center("---type 'more' to load more---")
- page = page +1
-
- # Error messages
- except Exception as e:
- if "code" in out:
- print(" Error code: ", out["code"] )
- if out["code"] == -32500:
- print(" SDK is still starting. Patience!")
- else:
- print(" Error :", e)
- return
- # Making sure that we stop every time a new page is reached
- c = input(typing_dots())
- if c != "more":
- break
- try:
- c = int(c)
- except:
- return
- while True:
- url.get(out["items"][c]["canonical_url"])
- c = input(typing_dots())
- if not c:
- break
- try:
- c = int(c)
- except:
- return
- def select(message="", claim_id=False):
- # This fucntion will give users to select one of their channels.
- center(message)
- out = check_output(["flbry/lbrynet",
- "channel", "list"])
- # Now we want to parse the json
- try:
- out = json.loads(out)
- except:
- print(" Connect to LBRY first.")
- return
- d = {"categories":["lbry url", "title"],
- "size":[1,2],
- "data":[]}
-
- for n, i in enumerate(out["items"]):
- d["data"].append([i["name"], i["value"]["title"]])
- table(d)
- center("select a channel by typing it's number")
-
- select = input(typing_dots())
- try:
- select = int(select)
- if claim_id:
- return out["items"][select]["name"], out["items"][select]["claim_id"]
- return out["items"][select]["name"]
- except:
- if claim_id:
- return out["items"][0]["name"], out["items"][0]["claim_id"]
- return out["items"][0]["name"]
|