-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not possible use input-file option #70
Comments
Hmm yeah I didn't plan this kind of use. Maybe you could simply open the file, read its lines, and feed them to |
I understand ... But if the options in file, like this:
it requires an additional parser) is not difficult, |
OK so there's no way to tell the JSON-RPC daemon to add downloads using an input file with options? We could consider adding the functionality in |
@pawamoy Whats would be the approach on this issue. I was thinking that one could provide an input file, which is parsed to create objects |
I think it's the right approach. I would see it like this:
Something like this: def add(self, uri: str) -> List[Download]:
...
if path_exists:
if path.suffix == ".torrent":
new_downloads.append(self.add_torrent(path))
elif path.suffix == ".metalink":
new_downloads.extend(self.add_metalink(path))
else:
try:
new_downloads.extend(self.add_input_file(path))
except ValueError:
for line in read_lines(path):
if line:
new_downloads.extend(self.add(line))
... |
Reference: issue pawamoy#70
I tried to implement this but had the following issues.
1. If a value error is raised should the parsing stop or should it
continue to parse other uri with valid options and inform invalid options
to the user.
2. According to your suggestion, if an error is raised it should
fallback on current behaviour (ie to read as normal file with uris).
if the file was an input file then options will be added as uris.
I have a beta version that reads all files and adds download options
incase of an aria2 input file. If it is a normal file it adds the downloads
but without options. It parses tab delimited options and new line
indented options. What is your take on this?
jonnieey@f84bcd6
|
Hello! Thank you for your patience 😅 You make a good point. Then I think we should only read a file as an input file since it will also support normal files (one URI on each line). If there's an error during parsing, it should be recorded so we can warn the user. Now I looked at your code, and it seems you're not doing exactly what you describe here: uri, download_options = line.rstrip().split("\t")[0], line.split("\t")[1:] It seems here that you are trying to read an URI and its options on the same line, which is not correct. The format accepted by aria2 is tab-delimited URIs on the same line (multiple URIs for one download), and options indented with one space, on new lines. I would write the def input_downloads(lines):
"""Helper to split downloads in an input file."""
block = []
for line in lines:
if not line.startswith(" "):
if block:
yield block
block = []
block.append(line.rstrip("\n"))
if block:
yield block
def add_input_file(input_file):
downloads = []
with Path(input_file).open() as fd:
for download_lines in input_downloads(fd):
uris = download_lines[0].split("\t")
options = {}
for opt_line in download_lines[1:]:
opt_name, opt_value = opt_line.split("=")
options[opt_name.lstrip() = opt_value
downloads.append((uris, options))
return downloads # or do something else with downloads This function can read both input file as described by aria2, as well as normal files with just regular URIs on each line. |
Yeah. No problem
I'll check it out and try to add some error handling functionality.
:thumbsup:
|
I'd like Aria2p having a very simple and basic mode like in https://github.com/prebuilder/downloaders.py/blob/master/downloaders/backends/aria2c.py And to have it in a separate package, so the most of deps are unneed. But I don't want to maintain such a package ... And maybe a compatibility layer, implementing the same, but through libaria. |
Hi @KOLANICH, not sure to understand. Such a "simple and basic mode" can be achieved by running
Me neither 😅 |
Yes, programmatically. If I wanted to run aria2c from bash, I wouldn't have used python.
Not quite. My impl is very simple: one just enumerates URIs and files to which download, the code generates an aria2c input file and feeds it to aria2c via a pipe, that is accessed by aria2c via its file path. No http-RPC, all the files are added before start. Its main advantage is that it is very small and simple and has very little deps. But having multiple packages for the same thing just fragments the ecosystem, it is not good. |
I see. Unfortunately it won't happen in aria2p, as it is really a JSON-RPC client. It wouldn't make sense to have methods using JSON-RPC and others spawning aria2c processes. |
Hey @jonnieey, very promising code! If you send a PR I can review it today 🙂 |
Describe the bug
Not possible make this:
aria2c -i for_aria.txt
To Reproduce
System (please complete the following information):
aria2p
version: 0.9.1The text was updated successfully, but these errors were encountered: