8 Commits c7775d4ec9 ... e051939746

Auteur SHA1 Bericht Datum
  jyamihud e051939746 Fixed a rendering issue with codes in markdown 2 jaren geleden
  jyamihud 4fa720d134 Fixed 'save', 'play' and 'read' which were to do with the new SDK 2 jaren geleden
  Jeison Yehuda Amihud (Blender Dumbass) 11e4d0dbfc Merge branch 'master' of vertbyqb/FastLBRY-terminal into master 2 jaren geleden
  vertbyqb 8da8cf9b4b Update flbry/lbrynet to version 0.108.0 2 jaren geleden
  vertbyqb 3eba43b9c3 Interact directly with comment servers instead of using the SDK. 2 jaren geleden
  jyamihud 8b37699337 Added an ability for the user to add his or her auth-token 2 jaren geleden
  jyamihud 25f3881f61 Added comments into markdown.py for better understanding. 2 jaren geleden
  jyamihud 6dee34c31b Added Release date in the url.py 2 jaren geleden
10 gewijzigde bestanden met toevoegingen van 185 en 100 verwijderingen
  1. 6 2
      devs.json
  2. 5 5
      flbry/analytics.py
  3. 35 3
      flbry/channel.py
  4. 125 76
      flbry/comments.py
  5. 3 3
      flbry/connect.py
  6. 4 4
      flbry/donate.py
  7. 6 6
      flbry/following.py
  8. BIN
      flbry/lbrynet
  9. 1 1
      flbry/list_files.py
  10. 0 0
      flbry/markdown.py

+ 6 - 2
devs.json

@@ -1,6 +1,6 @@
 {
     "blenderdumbass@gmail.com": {
-        "commits": 49,
+        "commits": 51,
         "lbry": "lbry://@FastLBRY:f"
     },
     "eklektisk@eklektiskiscoding.xyz": {
@@ -11,8 +11,12 @@
         "commits": 1,
         "lbry": "lbry://@MyBeansAreBaked:b"
     },
+    "vertbyqb@onionmail.org": {
+        "commits": 1,
+        "lbry": "lbry://@vertbyqb:8"
+    },
     "vertbyqb@tuta.io": {
-        "commits": 49,
+        "commits": 46,
         "lbry": "lbry://@vertbyqb:8"
     }
 }

+ 5 - 5
flbry/analytics.py

@@ -320,7 +320,7 @@ def get_data(claim_id="", total=0, mode="sales"):
     # a given claim_id
 
     if not total:
-        command = [lbrynet_binary["b"],
+        command = [flbry_globals["lbrynet"],
                         "txo", "list",
                    "--exclude_internal_transfers",
                    "--is_not_my_input",
@@ -346,7 +346,7 @@ def get_data(claim_id="", total=0, mode="sales"):
         progress_bar(total_total-total, total_total, "Getting "+mode+" data...")
 
         
-        command = [lbrynet_binary["b"],
+        command = [flbry_globals["lbrynet"],
                         "txo", "list",
                    "--page_size=50",
                    "--exclude_internal_transfers",
@@ -379,7 +379,7 @@ def sales(mode="sales"):
 
 
     # First let's get the list of our channels
-    out = check_output([lbrynet_binary["b"],
+    out = check_output([flbry_globals["lbrynet"],
                          "channel", "list"])
 
     try:
@@ -401,7 +401,7 @@ def sales(mode="sales"):
         page_size =  h - 5
 
 
-        command = [lbrynet_binary["b"],
+        command = [flbry_globals["lbrynet"],
                    "claim", "search",
                    "--remove_duplicates",
                     '--order_by=release_time',
@@ -451,7 +451,7 @@ def sales(mode="sales"):
                 progress_bar(n+1, len(list_of_publications["items"]), "Fetching: "+name)
 
                 # Now lets get the amount of entries in txo
-                command = [lbrynet_binary["b"],
+                command = [flbry_globals["lbrynet"],
                                 "txo", "list",
                                 "--claim_id="+i["claim_id"],
                            "--exclude_internal_transfers",

+ 35 - 3
flbry/channel.py

@@ -79,7 +79,7 @@ def simple(args=""):
         center("CHANNEL: "+args+" PAGE:"+str(page))
 
 
-        out = check_output([lbrynet_binary["b"],
+        out = check_output([flbry_globals["lbrynet"],
                          "claim", "search", '--channel='+args,
                          '--page='+str(page),
                          '--page_size='+str(page_size),
@@ -246,7 +246,7 @@ def select(message="", claim_id=False, anonymous=False):
     # This fucntion will give users to select one of their channels.
     center(message)
 
-    out = check_output([lbrynet_binary["b"],
+    out = check_output([flbry_globals["lbrynet"],
                          "channel", "list"])
 
     # Now we want to parse the json
@@ -565,7 +565,7 @@ def create(name=""):
                 center("There is no '"+pn+"' preset!", "bdrd")
 
         elif c == "create":
-            command = [lbrynet_binary["b"], "channel", "create", "--name="+data["name"], "--bid="+str(data["bid"])]
+            command = [flbry_globals["lbrynet"], "channel", "create", "--name="+data["name"], "--bid="+str(data["bid"])]
 
             for i in ["title", "description", "email", "website_url", "thumbnail_urL", "cover_url"]:
                 if i in data:
@@ -585,3 +585,35 @@ def create(name=""):
                 center("Successfully created "+name, "bdgr")
 
             return
+
+def sign(data: str = "", channel: str = "", message: str = "Channel to sign data with:", hexdata: str = ""):
+    """
+    Sign a string or hexdata and return the signatures
+
+    Keyword arguments:
+    data -- a string to sign
+    channel -- channel name to sign with (e.g. "@example"). Will prompt for one if not given.
+    message -- message to give when selecting a channel. Please pass this if not passing channel.
+    hexdata -- direct hexadecimal data to sign
+    """
+    if (not data and not hexdata) or (data and hexdata):
+        raise ValueError("Must give either data or hexdata")
+    elif data:
+        hexdata = data.encode().hex()
+
+    if not channel:
+        channel = select(message)
+
+    if not channel.startswith("@"):
+        channel = "@" + channel
+
+    try:
+        sigs = check_output([flbry_globals["lbrynet"],
+                             "channel", "sign",
+                             "--channel_name=" + channel,
+                             "--hexdata=" + hexdata])
+        sigs = json.loads(sigs)
+        return sigs
+    except:
+        center("Connect to LBRY first.", "bdrd")
+        return

+ 125 - 76
flbry/comments.py

@@ -31,6 +31,7 @@
 
 from subprocess import *
 import json
+import urllib.request
 
 from flbry import url
 from flbry.variables import *
@@ -38,44 +39,40 @@ from flbry import markdown
 from flbry import channel
 from flbry import settings
 
-def list(claim_id, link, comment_id=""):
-
-
-    # This function will list a list of comments of a certain claim_id
-    # It will preview a very basic form of comment. You will have
-    # to select a comment to interact with it further. Like read the
-    # whole text, if it not short ( or in a markdown format ). Or
-    # do other things like replies.
+def list(claim_id: str, link: str, comment_id: str = ""):
+    """
+    Lists comments in a short form, truncating some if needed. Comments can be selected for further actions.
 
+    Keyword arguments:
+    claim_id -- ID of the claim to get comments from
+    link -- LBRY URL of the claim, used for display
+    comment_id -- Comment ID to get sub-comments of, optional
+    """
     w, h = tsize()
 
     page_size = h - 5
     page = 1
 
     while True:
-
         # Printing the search query and page number
         center("COMMENTS OF: "+link+" PAGE : "+str(page))
 
-        if not comment_id:
-            out = check_output([lbrynet_binary["b"],
-                         "comment", "list", claim_id,
-                         '--page='+str(page),
-                            '--page_size='+str(page_size)])
-        else:
-            out = check_output([lbrynet_binary["b"],
-                                "comment", "list", '--claim_id='+claim_id,
-                            '--parent_id='+comment_id,
-                         '--page='+str(page),
-                            '--page_size='+str(page_size),
-                            '--include_replies'])
+        params = {
+            "claim_id": claim_id,
+            "page": page,
+            "page_size": page_size,
+            "sort_by": 3,
+            "top_level": True,
+        }
 
-        # Now we want to parse the JSON
-        try:
-            out = json.loads(out)
-        except:
-            center("Connect to LBRY first.", "bdrd")
+        if comment_id:
+            params["parent_id"] = comment_id
+            params["top_level"] = False
+
+        out = comment_request("comment.List", params)
+        if not out:
             return
+        out = out["result"]
 
         if not "items" in out:
             center("Publication has no comments", "bdrd")
@@ -224,15 +221,8 @@ def view(i):
             post(i["claim_id"], c[c.find(" "):], i["comment_id"])
 
         elif c == "delete":
-            out = check_output([lbrynet_binary["b"], "comment", "abandon", i["comment_id"]])
-            out = json.loads(out)
-            try:
-                if out["abandoned"] == True:
-                    center("Comment deleted!", "bdgr")
-                    break
-            except:
-                if out["message"].startswith("Couldn't find channel with channel_id"):
-                    center("You can't delete a comment you didn't post", "bdrd")
+            delete(i["comment_id"], bywho)
+
         elif c.startswith("edit"):
             c = c + ' '
             update(i, c[c.find(" "):])
@@ -252,31 +242,32 @@ def post(claim_id, args,  parent_id=""):
         else:
             text = input(typing_dots("Comment text", give_space=True))
 
-
-    post_as = channel.select("Reply as who? Select Channel.")
-
+    post_as, post_as_id = channel.select("Reply as who? Select Channel.", True)
 
     if not post_as.startswith("@"):
         post_as = "@"+post_as
 
+    sigs = channel.sign(text, post_as)
+    if not sigs:
+        return
 
-    if not parent_id:
-        out = check_output([lbrynet_binary["b"],
-                         "comment", "create",
-                        text,
-                        '--channel_name='+post_as,
-                        '--claim_id='+claim_id])
-    else:
-        out = check_output([lbrynet_binary["b"],
-                         "comment", "create",
-                        text,
-                        '--channel_name='+post_as,
-                        '--parent_id='+parent_id,
-                        '--claim_id='+claim_id])
-
-    out = json.loads(out)
-    if "message" in out:
-        center("Error: "+out["message"], "bdrd")
+    params = {
+        "channel_id": post_as_id,
+        "channel_name": post_as,
+        "claim_id": claim_id,
+        "comment": text,
+        **sigs
+    }
+
+    if parent_id:
+        params["parent_id"] = parent_id
+
+    out = comment_request("comment.Create", params)
+    if not out:
+        return
+
+    if "error" in out:
+        center("Error: "+out["error"]["message"], "bdrd")
     else:
         center("Comment is sent.", "bdgr")
 
@@ -365,22 +356,22 @@ def inbox(opt=10):
 
 
         if page != 1:
-            out = check_output([lbrynet_binary["b"],
+            out = check_output([flbry_globals["lbrynet"],
                          "stream", "list",
                          '--page='+str(page),
                          '--page_size='+str(page_size),
                             "--no_totals"])
-            out2 = check_output([lbrynet_binary["b"],
+            out2 = check_output([flbry_globals["lbrynet"],
                          "channel", "list",
                          '--page='+str(page),
                          '--page_size='+str(page_size),
                             "--no_totals"])
         else:
-            out = check_output([lbrynet_binary["b"],
+            out = check_output([flbry_globals["lbrynet"],
                          "stream", "list",
                          '--page='+str(page),
                                 '--page_size='+str(page_size)])
-            out2 = check_output([lbrynet_binary["b"],
+            out2 = check_output([flbry_globals["lbrynet"],
                          "channel", "list",
                          '--page='+str(page),
                                 '--page_size='+str(page_size)])
@@ -444,16 +435,18 @@ def inbox(opt=10):
 
                 comment_page = comment_page + 1
 
-                cout = check_output([lbrynet_binary["b"],
-                        "comment", "list", '--claim_id='+claim_id,
-                         '--page='+str(comment_page),
-                            '--page_size='+str(50),
-                            '--include_replies'])
+                params = {
+                    "claim_id": claim_id,
+                    "page": comment_page,
+                    "page_size": 50,
+                    "sort_by": 3,
+                    "top_level": False,
+                }
 
-                try:
-                    cout = json.loads(cout)
-                except:
-                    break
+                out = comment_request("comment.List", params)
+                if not out:
+                    return
+                cout = out["result"]
 
                 # TODO: For now I'm stopping on first page when ever I'm
                 #       loading channel's comments ( community disscussion ).
@@ -561,6 +554,8 @@ def inbox(opt=10):
 
 def update(i, args):
     comment = i["comment"]
+    comment_id = i["comment_id"]
+    commenter = i["channel_name"]
     editor = settings.get("default_editor")
 
     if len(args) > 1:
@@ -572,12 +567,66 @@ def update(i, args):
             print("Comment: "+comment)
             text = input(typing_dots("Edited comment", give_space=True))
 
-    out = check_output([lbrynet_binary["b"],
-                "comment", "update", "--comment_id="+i["comment_id"],
-                "--comment="+text])
-    out = json.loads(out)
-    try:
-        if out["message"].startswith("Couldn't find channel with channel_id"):
-            center("You cant' edit a comment that isn't yours", "bdrd")
-    except:
+
+    sigs = channel.sign(text, commenter)
+    if not sigs:
+        return
+
+    params = {
+        "comment": text,
+        "comment_id": comment_id,
+        **sigs
+    }
+
+    out = comment_request("comment.Edit", params)
+
+    if "error" in out:
+        center("Error updating comment: " + out["error"]["message"], "bdrd")
+        center("Make sure you are editing a comment you posted.", "bdrd")
+    elif "result" in out:
         center("Comment edited!", "bdgr")
+
+def delete(comment_id: str, commenter: str):
+    """
+    Deletes a comment you posted by its comment ID
+    """
+    sigs = channel.sign(comment_id, commenter)
+    if not sigs:
+        return
+
+    params = {
+        "comment_id": comment_id,
+        **sigs
+    }
+
+    out = comment_request("comment.Abandon", params)
+    if "result" in out:
+        center("Comment deleted!", "bdgr")
+    elif "error" in out:
+        center("Error deleting comment: " + out["error"]["message"], "bdrd")
+        center("Make sure you posted this comment.", "bdrd")
+
+def comment_request(method: str, params: dict):
+    """
+    Sends a request to the comment API
+    """
+    data = {
+        "method": method,
+        "id": 1,
+        "jsonrpc":"2.0",
+        "params": params
+    }
+    data = json.dumps(data).encode()
+
+    headers = {
+        "Content-Type": "application/json"
+    }
+
+    try:
+        req = urllib.request.Request(flbry_globals["comment_api"], data, headers)
+        res = urllib.request.urlopen(req)
+        out = res.read().decode()
+        return json.loads(out)
+    except Exception as e:
+        center("Comment Error: "+str(e))
+        return

+ 3 - 3
flbry/connect.py

@@ -39,7 +39,7 @@ def start():
     if check():
         center("SDK is already running")
     else:
-        retcode = subprocess.Popen([lbrynet_binary["b"], 'start'],
+        retcode = subprocess.Popen([flbry_globals["lbrynet"], 'start'],
                                 stdout=subprocess.DEVNULL,
                                 stderr=subprocess.STDOUT)
         progress_bar(0.2, 10, "Checking Wallet...")
@@ -55,7 +55,7 @@ def start():
 
 def stop():
     if check():
-        retcode = subprocess.Popen([lbrynet_binary["b"], 'stop'],
+        retcode = subprocess.Popen([flbry_globals["lbrynet"], 'stop'],
                                 stdout=subprocess.DEVNULL,
                                 stderr=subprocess.STDOUT)
         center("LBRY Connection Closed")
@@ -67,7 +67,7 @@ def check():
     # whether the SDK is running
 
     try:
-        out = subprocess.check_output([lbrynet_binary["b"],
+        out = subprocess.check_output([flbry_globals["lbrynet"],
                          "claim", "search", '--text="test"',
                          '--page=1',
                          '--page_size=1',

+ 4 - 4
flbry/donate.py

@@ -146,7 +146,7 @@ def donate():
     # of your wealth to the people that contribute to the project.
 
     # First we need to show the user the amount he has.
-    balance = check_output([lbrynet_binary["b"],
+    balance = check_output([flbry_globals["lbrynet"],
                          "wallet", "balance"])
     try:
         balance = json.loads(balance)
@@ -231,7 +231,7 @@ def donate():
     print()
     progress_bar(0, len(devs)+1, "Resolving Donation Urls...")
 
-    resolve = [lbrynet_binary["b"],"resolve"]
+    resolve = [flbry_globals["lbrynet"],"resolve"]
     for dev in devs:
         resolve.append(dev[0])
 
@@ -247,7 +247,7 @@ def donate():
 
         try:
             claim_id = resolve[dev[0]]["claim_id"]
-            support_command = [lbrynet_binary["b"],
+            support_command = [flbry_globals["lbrynet"],
                      "support",
                      "create",
                      "--claim_id="+claim_id,
@@ -267,7 +267,7 @@ def donate():
         for dev in devs:
             text = text + "\n - **"+str(dev[0]).replace("lbry://", "")+"** got `"+str(dev[1])+"` LBC from me."
 
-        post_comment = [lbrynet_binary["b"],
+        post_comment = [flbry_globals["lbrynet"],
                              "comment", "create",
                             text,
                             '--claim_id=fb4db67b2a79396f4ba0a52a12e503d0a736f307']

+ 6 - 6
flbry/following.py

@@ -36,7 +36,7 @@ from flbry import url
 
 def following():
     # Get the subscriptions
-    following = check_output([lbrynet_binary["b"], "preference", "get"])
+    following = check_output([flbry_globals["lbrynet"], "preference", "get"])
     try:
         following = json.loads(following)
     except:
@@ -51,7 +51,7 @@ def following():
     page = 1
 
     while True:
-        command = [lbrynet_binary["b"], "claim", "search", "--page="+str(page), "--page_size="+str(page_size), "--order_by=release_time"]
+        command = [flbry_globals["lbrynet"], "claim", "search", "--page="+str(page), "--page_size="+str(page_size), "--order_by=release_time"]
         # Gets each channel's ID and add it to the command
         for i in following:
             i = i.split("#", 1)[1]
@@ -126,7 +126,7 @@ def following():
 
 def follow_channel(channel, name):
         # Get the shared preferences so they can be modified
-        subscriptions = check_output([lbrynet_binary["b"], "preference", "get", "shared"])
+        subscriptions = check_output([flbry_globals["lbrynet"], "preference", "get", "shared"])
         subscriptions = json.loads(subscriptions)["shared"]
 
         # If the channel is not in the subscriptions we add it
@@ -135,7 +135,7 @@ def follow_channel(channel, name):
             x = {"notificationsDisabled": True, "uri": channel}
             subscriptions["value"]["following"].append(x)
 
-            x = check_output([lbrynet_binary["b"], "preference", "set", "shared", json.dumps(subscriptions)])
+            x = check_output([flbry_globals["lbrynet"], "preference", "set", "shared", json.dumps(subscriptions)])
 
             center("Followed "+name, "bdgr")
 
@@ -145,7 +145,7 @@ def follow_channel(channel, name):
 
 def unfollow_channel(channel, name):
         # Get the shared preferences so they can be modified
-        subscriptions = check_output([lbrynet_binary["b"], "preference", "get", "shared"])
+        subscriptions = check_output([flbry_globals["lbrynet"], "preference", "get", "shared"])
         subscriptions = json.loads(subscriptions)["shared"]
 
         # If the channel is not in the subscriptions we add it
@@ -154,7 +154,7 @@ def unfollow_channel(channel, name):
             x = {"notificationsDisabled": True, "uri": channel}
             subscriptions["value"]["following"].remove(x)
 
-            x = check_output([lbrynet_binary["b"], "preference", "set", "shared", json.dumps(subscriptions)])
+            x = check_output([flbry_globals["lbrynet"], "preference", "set", "shared", json.dumps(subscriptions)])
 
             center("Unfollowed "+name, "bdgr")
 

BIN
flbry/lbrynet


+ 1 - 1
flbry/list_files.py

@@ -57,7 +57,7 @@ def downloaded():
         center("DOWNLOAD HISTORY. PAGE :"+str(page))
 
 
-        out = check_output([lbrynet_binary["b"],
+        out = check_output([flbry_globals["lbrynet"],
                              "file", "list",
                              '--page='+str(page),
                              '--page_size='+str(page_size),

+ 0 - 0
flbry/markdown.py


Some files were not shown because too many files changed in this diff