-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Daemon.jsonrpc_file_summary: new method to print a summary of claims
This allows printing a list of all claim streams that were downloaded to the system. The list is printed to the terminal or to a specific file. It accepts some parameters to control the information that is printed. ``` lbrynet file summary --blobs --show_channel --title --stream_type --path lbrynet file summary --show=incomplete --start=10 --end=40 lbrynet file summary --sort=claim_name --reverse --sep=' ;.;' ``` The `--file` option writes the list of claims to a file which then can be shared with other users of LBRY in order to download the same claims and contribute to seeding that content. ``` lbrynet file summary --channel=@somechannel --file=summary.txt --fdate ``` By default it will print the date of the claim which is based on the `'claim_height'`, when the claim was registered in the blockchain, the `'claim_id'`, the `'claim_name'`, and whether the media is present or not in the download directory. ``` 1/42; 20200610_10:23:37-0500; b231714456ee832daeba4b8356803e7591126dff; "07-S"; no-media 2/42; 20200610_10:27:06-0500; 31700ff11f900429d742f2f137ba25393bdb3b0a; "09-S"; media 3/42; 20200609_23:14:47-0500; 70dfefa510ca6eee7023a2a927e34d385b5a18bd; "04-S"; no-media ```
- Loading branch information
Showing
2 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Print various types of information regarding the claims. | ||
""" | ||
import os | ||
import time | ||
|
||
|
||
def print_items(items=None, release_times=None, show="all", | ||
title=False, typ=False, path=False, | ||
cid=True, blobs=True, ch=False, | ||
name=True, start=1, end=0, | ||
file=None, fdate=None, sep=";"): | ||
"""Print items provided by file_list.""" | ||
if not items: | ||
error = "No claims" | ||
if file: | ||
error += f'; no file written "{file}"' | ||
print(error) | ||
return False, False | ||
|
||
n_items = len(items) | ||
|
||
fd = 0 | ||
|
||
if file: | ||
dirn = os.path.dirname(file) | ||
base = os.path.basename(file) | ||
|
||
if fdate: | ||
fdate = time.strftime("%Y%m%d_%H%M", time.localtime()) + "_" | ||
else: | ||
fdate = "" | ||
|
||
file = os.path.join(dirn, fdate + base) | ||
|
||
try: | ||
fd = open(file, "w") | ||
except (FileNotFoundError, PermissionError) as err: | ||
print(f"Cannot open file for writing; {err}") | ||
|
||
out_list = [] | ||
|
||
for it, pair in enumerate(zip(items, release_times), start=1): | ||
if it < start: | ||
continue | ||
if end != 0 and it > end: | ||
break | ||
|
||
item = pair[0] | ||
release_time = pair[1] | ||
|
||
_path = item.download_path | ||
_blobs = item.blobs_completed | ||
_blobs_in_stream = item.blobs_in_stream | ||
|
||
if show in "media" and not _path: | ||
continue | ||
elif show in "missing" and _path: | ||
continue | ||
elif show in "incomplete" and _blobs == _blobs_in_stream: | ||
continue | ||
elif show in "full" and _blobs < _blobs_in_stream: | ||
continue | ||
|
||
if "release_time" not in item.metadata: | ||
_time = release_time | ||
else: | ||
_time = int(item.metadata["release_time"]) | ||
_time = time.localtime(_time) | ||
_time = time.strftime("%Y%m%d_%H:%M:%S%z", _time) | ||
|
||
_claim_id = item.claim_id | ||
_claim_ch = item.channel_name | ||
_claim_name = item.claim_name | ||
_title = item.metadata["title"] | ||
_type = item.metadata["stream_type"] | ||
|
||
out = "{:4d}/{:4d}".format(it, n_items) + sep + f" {_time}" + f"{sep} " | ||
|
||
if cid: | ||
out += f"{_claim_id}" + f"{sep} " | ||
if blobs: | ||
out += "{:3d}/{:3d}".format(_blobs, _blobs_in_stream) + f"{sep} " | ||
if ch: | ||
if _claim_ch: | ||
out += f"{_claim_ch}" + f"{sep} " | ||
else: | ||
out += f"_Unknown_" + f"{sep} " | ||
if name: | ||
out += f'"{_claim_name}"' + f"{sep} " | ||
|
||
if title: | ||
out += f'"{_title}"' + f"{sep} " | ||
if typ: | ||
out += f"{_type}" + f"{sep} " | ||
if path: | ||
out += f'"{_path}"' + f"{sep} " | ||
|
||
if _path: | ||
out += "media" | ||
else: | ||
out += "no-media" | ||
|
||
out_list.append(out) | ||
|
||
print(f"Number of shown items: {len(out_list)}") | ||
|
||
if file and fd: | ||
for line in out_list: | ||
print(line, file=fd) | ||
|
||
fd.close() | ||
print(f'Summary written: "{file}"') | ||
else: | ||
print("\n".join(out_list)) | ||
|
||
return len(out_list), file |