A library of functions that can be used to manage the download of claims from the LBRY network.

Overview

lbrytools

A library of functions that can be used to manage the download of claims from the LBRY network. It includes methods to download claims by URI (canonical url), claim ID, or from specific channels.

It also includes methods to clean up older files and free space, so the functions are suitable for use in a headless computer that will download files, and seed them to the network with little user intervention.

This libary is released as free software under the MIT license.

Motivation

The LBRY Desktop application provides basic functionality to manage downloaded claims. Real control of the system is achieved with the lbrynet headless client, also called the lbry-sdk.

This library provides convenience functions that wrap around lbrynet in order to search, download, and delete many claims easier.

This library is inspired by tuxfoo's lbry-seedit script, which provides basic functions, and a configuration file to download and seed claims. Initially tuxfoo's code was extended slightly but eventually an entire library was written from scratch to provide more functionality.

Installation

You must have the LBRY Desktop application or the lbrynet client. Get them from lbry.com/get.

You must have Python installed. Most Linux distributions come with Python ready to use; for Windows you may need to get the official package, or a full featured distribution such as Anaconda.

Copy the internal lbrytools directory, and place it inside a site-packages directory that is searched by Python. This can be in the user's home directory,

/home/user/.local/lib/python3.8/site-packages/lbrytools

or in a system-wide directory:

/usr/local/lib/python3.8/dist-packages/lbrytools
/usr/lib/python3/dist-packages/lbrytools

You can also modify the PYTHONPATH environmental variable to include the parent directory where lbrytools is located:

PYTHONPATH=/opt/git/lbrytools:$PYTHONPATH

This library was developed and tested with Python 3.8 but it may also work with earlier versions with small changes. It uses standard modules such as importlib, os, random, requests, sys, and time.

Usage

Make sure the lbrynet daemon is running either by launching the full LBRY Desktop application, or by starting the console lbrynet program.

lbrynet start

Then open a Python console, import the module, and use its methods.

import lbrytools as lbryt

lbryt.download_single(...)
lbryt.ch_download_latest(...)
lbryt.ch_download_latest_multi(...)
lbryt.redownload_latest(...)
lbryt.download_claims(...)
lbryt.print_summary()
lbryt.print_channels()
lbryt.delete_single(...)
lbryt.ch_cleanup(...)
lbryt.ch_cleanup_multi(...)
lbryt.remove_claims(...)
lbryt.measure_usage(...)
lbryt.cleanup_space(...)
lbryt.remove_media()
lbryt.count_blobs(...)
lbryt.count_blobs_all(...)
lbryt.analyze_blobs(...)
lbryt.download_missing_blobs(...)
lbryt.analyze_channel(...)
lbryt.print_channel_analysis(...)
lbryt.blobs_move(...)
lbryt.blobs_move_all(...)
lbryt.claims_bids(...)
lbryt.channel_subs(...)
lbryt.list_accounts(...)
lbryt.list_playlists(...)
lbryt.list_supports(...)
lbryt.print_blobs_ratio(...)
lbryt.create_support(...)
lbryt.abandon_support(...)
lbryt.target_support(...)

Read the lbrytools.md file for a short explanation on the most useful functions in the library.

Zeedit script

This script uses the lbrytools methods to achieve the same objective as tuxfoo's original lbry-seedit. It downloads content from various channels, and then seeds the blobs to the network. This script should be run periodically to constantly download new content, and remove the older files if they take too much space. See zeedit.py.

If lbrytools is correctly installed in the Python path, the script can be executed directly, or through the Python interpreter.

python zeedit.py [config.py]

A configuration file should be passed as the first argument.

python zeedit.py funny_config.py
python zeedit.py tech_channels_config.py
python zeedit.py cooking_conf.py

The configuration file specifies the channels to download content from, the download directory, the limit in gigabytes before cleanup of older files is started, and whether to write a summary of all downloaded claims. Modify the zeedit_config_example.py to your liking, and read the comments in it to understand what each variable does. Only the channels variable is mandatory, all others have a default value if they are missing in the configuration file.

If no argument is given, or if the provided configuration file does not exist, it will default to loading a configuration under the name zeedit_config.py; if this is not available, it will simply exit.

To keep everything contained, the lbrytools package can be placed in the same directory as zeedit.py and zeedit_config.py.

zeedit/
      zeedit.py
      zeedit_config.py
      lbrytools/
               __init___.py
               blobs.py
               ...

Development

Ideally, this collection of tools can be merged into the official LBRY sources so that everybody has access to them. Where possible, the tools should also be available from a graphical interface such as the LBRY Desktop application.

If you wish to support this work you can send a donation:

LBC: bY38MHNfE59ncq3Ch3zLW5g41ckGoHMzDq
XMR: 8565RALsab2cWsSyLg4v1dbLkd3quc7sciqFJ2mpfip6PeVyBt4ZUbZesAAVpKG1M31Qi5k9mpDSGSDpb3fK5hKYSUs8Zff
Comments
  • Delete lists of claims and from a specific channel

    Delete lists of claims and from a specific channel

    If we have downloaded many claims from the same channel, we may want to delete the older ones from that channel, without considering other channels.

    At the moment the generic function clean.cleanup_space looks at all claims. The parameter never_delete considers channels to avoid. Maybe a new parameter only_delete could do the opposite, and consider only the channels to clean up, as oppose to avoid.

    channels = ["@lbry", "@odysee"]
    dd = t.cleanup_space(main_dir="/opt", size=1000, percent=90,
                         only_delete=channels, what="media")
    

    A new function could be used to remove all older videos from a specific channel, and only leave a select number of the newest ones.

    # leave only the 3 newest videos of the channel
    channels = ["@lbry", "@odysee"]
    dd = t.cleanup_channels(channels=channels, number=3, what="media")
    

    We need a function that takes a list of claims to delete, just like download.redownload_claims takes a list of claims to download or re-download.

    dd = t.remove_claims(ddir="/opt", file="remove.txt")
    dd = t.remove_claims(ddir="/opt", start=10, end=20, file="remove.txt")
    
    enhancement 
    opened by belikor 2
  • Move `zeedit` to its own repository

    Move `zeedit` to its own repository

    The program zeedit.py is contained in a single file, and uses lbrytools as backend.

    The program lbrydseed (https://github.com/belikor/lbrydseed) also uses lbrytools as backend.

    Therefore, this repository lbrytools, should contain only the code of the library, and it should be placed at the top level of the repository so that it can be used as a submodule by other programs, that is, zeedit and lbrydseed.

    In turn, a new zeedit repository should be created to contain only the code for this program, and should have lbrytools as a submodule, just like lbrydseed.

    enhancement 
    opened by belikor 1
  • Handle the returncode of the `lbrynet` process better

    Handle the returncode of the `lbrynet` process better

    Currently the lbrynet command is run through subprocess; if the returncode is 1, this indicates an error and it abruptly terminates the Python script.

        get_cmd = ["lbrynet",
                   "get",
                   "'lbry://@asaaa#5/a#b'"]
        output = subprocess.run(get_cmd,
                                capture_output=True,
                                check=True,
                                text=True)
        if output.returncode == 1:
            print(f"Error: {output.stderr}")
            sys.exit(1)
    

    Although lbrynet seems to be quite stable, and it rarely returns an error, this should be handled better, and exit should be avoided, as it terminates the complete script where the function is being used.

    This returncode may be exclusive to running subprocess. Maybe by solving issue #1, we can avoid this altogether.

    As mentioned in #1, the reason we do it like this at the moment is historical. We started by copying the code from another programmer, and we just continued that.

    enhancement 
    opened by belikor 1
  • Use requests module to send json messages to the daemon

    Use requests module to send json messages to the daemon

    Currently we communicate with the lbrynet daemon through the subprocess module.

    get_cmd = ["lbrynet",
               "get",
               "lbry://@asaaa#5/a#b"]
    output = subprocess.run(get_cmd,
                            capture_output=True,
                            check=True,
                            text=True)
    

    Instead of doing it this way, we could also use the request module, by sending json messages directly to the running daemon in localhost.

    import requests
    
    server = "http://localhost:5279"
    json = {"method": "get",
            "params": {"uri": "astream#bcd03a"}}
    
    requests.post(server, json=json).json()
    

    This is probably better and faster.

    The reason the current functions use subprocess is merely historical, as this code is based on tuxfoo's lbry-seedit, and that's how he did it.

    This is a similar implementation but using json messages. https://odysee.com/@BrendonBrewer:3/channel-download:8

    enhancement 
    opened by belikor 1
  • Simplify the way to print claims

    Simplify the way to print claims

    Most claims when resolved online have the same type of data in the output dictionary; instead of handling the printing by special functions, we could simplify this by using a single function with many options.

    For example, print_claims.print_sch_claims already can print a list of claims with a lot of information, which is controlled by the parameters given to it. We can display block height, claim_id, type, channel name, title, and others. This function could be used in all methods that require printing claims.

    print_sch_claims(claims,
                     blocks=False, claim_id=False,
                     typ=False, ch_name=False,
                     title=False, sanitize=False,
                     start=1, end=0,
                     reverse=False,
                     file=None, fdate=None, sep=";")
    
    enhancement help wanted 
    opened by belikor 0
  • Return only 'stream' claims when searching claims in a channel

    Return only 'stream' claims when searching claims in a channel

    Various operations such as download and delete can only be performed on downloadable content, that is, streams.

    At the moment many functions depend on searching multiple claims from a channel by using search_ch.ch_search_latest.

    Instead of returning all types (streams, reposts, collections, livestreams) from the search, we should add an option to only return streams:

    claims = ch_search_latest("@some-chn", number=12, only_streams=False)
    streams = ch_search_latest("@some-chn", number=12, only_streams=True)
    

    This can be implemented by specifying the claim_type and using the has_source parameter in claim_search in lbrynet:

    lbrynet claim search --channel=@some-chn --claim_type=stream --has_source=True
    

    Livestreams are of type 'stream' but they don't have a source, so they are not downloadable, and should be avoided.

    enhancement help wanted 
    opened by belikor 0
  • Use `PyBRY` as wrapper for `lbrynet`

    Use `PyBRY` as wrapper for `lbrynet`

    At the moment we call the SDK methods by using requests.

    import requests
    
    msg = {"method": "claim_search",
           "params": {"channel": "@example",
                      "page": 1}}
    
    output = requests.post(server, json=msg).json()
    if "error" in output:
        return False
    
    result = output["result"]
    

    This essentially creates a wrapper around the lbrynet methods. Instead, we can use the already existing wrapper https://github.com/osilkin98/PyBRY

    This allows us to use any method defined in lbrynet like a native Python method.

    import pybry
    
    lbry = pybry.LbrydApi()
    output = lbry.claim_search(channel="@example", page=1)
    
    result = output[0]
    

    This would make access to the SDK more uniform, and all methods of the SDK would be available to use with all their parameters; therefore, there would be no need to write more wrappers like now.

    enhancement help wanted 
    opened by belikor 0
  • Clean up claims except for select claims

    Clean up claims except for select claims

    This follows from the closed issue #6, and #7.

    At the moment the generic function space.cleanup_space looks at all claims. The parameter never_delete considers channels to avoid when deleting claims.

    Maybe a new parameter keep could be used to avoid deleting select claims, either by 'name' or by 'claim_id', regardless of the channel.

    keep = ["is-justin-bieber-a-christian-singer:d",
            "b17e56e5f3b476b7f7a82916a340028aa9292f87"]
    dd = t.cleanup_space(main_dir="/opt", size=1000, percent=90,
                         keep=keep, what="media")
    
    
    enhancement help wanted 
    opened by belikor 0
  • Cleanup claims only from selected channels

    Cleanup claims only from selected channels

    This follows from the closed issue #6.

    At the moment the generic function clean.cleanup_space looks at all claims. The parameter never_delete considers channels to avoid when deleting claims.

    Maybe a new parameter only_delete could do the opposite, and consider only these channels when cleaning up older files.

    channels = ["@lbry", "@odysee"]
    dd = t.cleanup_space(main_dir="/opt", size=1000, percent=90,
                         only_delete=channels, what="media")
    

    Internally, the function would use the methods clean.ch_cleanup and clean.ch_cleanup_multi introduced in e45bf17.

    These functions delete all videos from a particular channel leaving only the newest one, established by the number=x parameter.

    enhancement help wanted 
    opened by belikor 0
  • Clean up orphaned blobs from claims

    Clean up orphaned blobs from claims

    With LBRY when a claim is downloaded, it downloads blob files that are stored on the blobfiles directory. In Linux this is normally

    /home/user/.local/share/lbrynet/blobfiles
    

    However, if the claim is re-uploaded, for example, if the file is re-encoded, the blobs will be different. A new set of blobs will have to be downloaded, but the old blobs will remain in the system taking hard drive space.

    A function needs to be created to examine the blobfiles directory so that only the currently managed claims have blobs. All other blobs, which are not tied to a specific claim, should be deleted so that they don't take unnecessary space in the system.


    Each claim with a URI or 'claim_id' will have a "manifest" blob file. This blob file is named after the 'sd_hash' of the claim. This information is found under a specific key in the dictionary representing the claim, item["value"]["source"]["sd_hash"].

    Inside this manifest blob file there is JSON data with all blobs that make the claim. Therefore, by examining this manifest blob file, we can know if all its blobs are present in the blobfiles directory or not.

    We can get all claims with search.sort_files (lbrynet file list), and examine the 'sd_hash' of each of them, to find all blobs in blobfiles.

    All additional blobs that don't seem to belong to any claim, that is, that are not contained in any manifest blob file, should be considered orphaned, and thus can be deleted from the system.

    Reference documentation of how the content is encoded in LBRY by using blobs https://lbry.tech/spec#data

    enhancement help wanted 
    opened by belikor 1
Owner
null
This is a python based command line Network Scanner utility, which input as an argument for the exact IP address or the relative IP Address range you wish to do the Network Scan for and returns all the available IP addresses with their MAC addresses on your current Network.

This is a python based command line Network Scanner utility, which input as an argument for the exact IP address or the relative IP Address range you wish to do the Network Scan for and returns all the available IP addresses with their MAC addresses on your current Network.

Abhinandan Khurana 1 Feb 9, 2022
DataShare - Simple library for data sharing between scripts and public functions calling

DataShare - Simple library for data sharing between scripts and public functions calling. Installation. Install code, Delete LICENSE, README, readme.t

Ivan Perzhinsky. 1 Dec 17, 2021
Multipurpose Growtopia Server tools, can be used for newbie to learn things.

Multipurpose Growtopia Server tools, can be used for newbie to learn things.

FelixF 3 Dec 1, 2021
The best way to send tokens into a specific server, which can be used for discord bots, and some tools..

XTRA420 The simplified version of sending tokens into a server, the basic and fastest way.. When using this, you have the option to use proxies (http)

07v 1 Nov 30, 2021
A tool to generate valid ip addresses of 55 countries. These ip's can be used for OpenBullet.

IP-Grabber A tool to generate valid ip addresses of 55 countries. These ip's can be used for OpenBullet. ive added the feature to set the generated ip

Saad 9 Dec 17, 2022
It can be used both locally and remotely (indicating IP and port)

It can be used both locally and remotely (indicating IP and port). It automatically finds the offset to the Instruction Pointer stored in the stack.

DiegoAltF4 13 Dec 29, 2022
Multi-path load balancing is a method used by most of the real-time network to split the packets into different paths rather than transferring it through a single path

Multipath-Load-Balancing Method of managing incoming traffic by distributing and sharing load fairly among multiple routes from source to destination

Dharshan Kumar 6 Dec 10, 2022
A simple software which can use to make a server in local network

home-nas it is simple software which can use to make a server in local network, it has a web site on it which can use by multipale system, i use nginx

R ansh joseph 1 Nov 10, 2021
The can package provides controller area network support for Python developers

python-can The Controller Area Network is a bus standard designed to allow microcontrollers and devices to communicate with each other. It has priorit

Brian Thorne 904 Dec 29, 2022
Ipscanner - A simple threaded IP-Scanner written in python3 that can monitor local IP's in your network

IPScanner ?? A simple threaded IP-Scanner written in python3 that can monitor lo

null 4 Dec 12, 2022
Nautobot is a Network Source of Truth and Network Automation Platform.

Nautobot is a Network Source of Truth and Network Automation Platform. Nautobot was initially developed as a fork of NetBox (v2.10.4). Nautobot runs as a web application atop the Django Python framework with a PostgreSQL database.

Nautobot 549 Dec 31, 2022
nettrace is a powerful tool to trace network packet and diagnose network problem inside kernel.

nettrace nettrace is is a powerful tool to trace network packet and diagnose network problem inside kernel on TencentOS. It make use of eBPF and BCC.

null 84 Jan 1, 2023
PcapXray - A Network Forensics Tool - To visualize a Packet Capture offline as a Network Diagram

PcapXray - A Network Forensics Tool - To visualize a Packet Capture offline as a Network Diagram including device identification, highlight important communication and file extraction

Srinivas P G 1.4k Dec 28, 2022
NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

NetworkX 12k Jan 2, 2023
The sequel to SquidNet. It has many of the previous features that were in the original script, however a lot of the functions that do not serve much functionality have been removed.

SquidNet2 The sequel to SquidNet. It has many of the previous features that were in the original script, however a lot of the functions that do not se

DrSquidX 5 Mar 25, 2022
wireguard-config-benchmark is a python script that benchmarks the download speeds for the connections defined in one or more wireguard config files

wireguard-config-benchmark is a python script that benchmarks the download speeds for the connections defined in one or more wireguard config files. If multiple configs are benchmarked it will output a file ranking them from fastest to slowest.

Sal 12 May 7, 2022
Network Engineer's Unified Realtime Automation Library

NEURAL is the premiere CLI jockey replacement full stack web/app/database network automation application, providing a "no-code" web app for network engineers developed by a network engineer!

Brett M Spunt 3 Aug 15, 2022
A Python tool used to automate the execution of the following tools : Nmap , Nikto and Dirsearch but also to automate the report generation during a Web Penetration Testing

?? WebMap A Python tool used to automate the execution of the following tools : Nmap , Nikto and Dirsearch but also to automate the report generation

Iliass Alami Qammouri 274 Jan 1, 2023
DNSStager is an open-source project based on Python used to hide and transfer your payload using DNS.

What is DNSStager? DNSStager is an open-source project based on Python used to hide and transfer your payload using DNS. DNSStager will create a malic

Askar 547 Dec 20, 2022