casey / intermodal

A command-line utility for BitTorrent torrent file creation, verification, and more
https://imdl.io
Creative Commons Zero v1.0 Universal
487 stars 25 forks source link

[Question] Is there a way for bulk verification? #500

Closed DerBunteBall closed 3 years ago

DerBunteBall commented 3 years ago

Hi all,

does imdl has a possibility for bulk verification?

So e.g. this:

imdl torrent verify -i /data/torrents/*.torrent -c /data/stuff/

I think this actually doesn't work because imdl ignores "subfolders". So if a torrent is a "folder torrent" it would definitly don't work because the path must be given explicitly. So it also isn't possible to loop this in bash or zsh because you would need to inspect the torrent to get the content path.

Is there a solution for this?

Best Regards

casey commented 3 years ago

Hmm, interesting!

Could you do:

cd /data/stuff
for torrent in /data/torrents/*.torrent; do
  imdl torrent verify -i $torrent
done

--content is optional, and defaults to the name field of the torrent metadata, so if the torrent contents have those names in /data/stuff, it should find them.

DerBunteBall commented 3 years ago

Exactly this was also my idea.

But exactly this fails.

If in /data/stuff/ are torrents which are crated from a folder e.g. torrent1 is crated from folder1 in which file1 exists imdl ignores the fact of folder1. So folder1 is in /data/stuff/ as folder1 but imdl looks for file1 in /data/stuff/ instead of e.g. relativly in ./folder1/. So in my case I'm getting corrupted pieces because the files are missing.

If the files are directly in /data/stuff/ e.g. if the torrent is created from a file so /data/stuff/file exists the looping approach works.

My verify works when I'm taking torrent1 going to /data/stuff/folder1/ and running imdl normally. Edit: See below - doesn't work. Don't remembered that this only works with -c .

Best Regards

DerBunteBall commented 3 years ago

Without -c nothing works. That's really strange. If a torrent2 is created only from file2 the following appears:

Working: cd /data/stuff/; imdl torrent verify -i /data/torrents/torrent2.torrent -c file2 - verification succeeded Faling: cd /data/stuff/; imdl torrent verify -i /data/torrents/torrent2.torrent - here file2 is missing. broken peaces.

Edit: It seems that -c is needed always explicitly for torrents created from a single file. The above mentioned . method works for torrents created from a dir in the correct dir.

Best Regards

casey commented 3 years ago

Edit: It seems that -c is needed always explicitly for torrents created from a single file. The above mentioned . method works for torrents created from a dir in the correct dir.

Are you sure that this is the case? For me, verification succeeds both when a torrent is a single file, and when it's a directory, without providing the -c flag:

# create and verify torrent created from directory
imdl torrent create src
imdl torrent verify src.torrent
# create and verify torrent created from single file
imdl torrent create README.md
imdl torrent verify README.md.torrent
DerBunteBall commented 3 years ago

Yes.

This works due to the fact that the files are always in the same dir.

I tested the following (from my homedir):

user@box:~$ mkdir imdl-test
user@box:~$ cd ./imdl-test/
user@box:~/imdl-test$ dd if=/dev/urandom of=testfile bs=512 count=10
user@box:~/imdl-test$ imdl torrent create testfile - working
user@box:~/imdl-test$ imdl torrent verify -i testfile.torrent - working
user@box:~/imdl-test$ mv testfile.torrent ..
user@box:~/imdl-test$ imdl torrent verify -i ~/testfile.torrent - failing imdl looks for testfile in ~ not at ./testfile
user@box:~/imdl-test$ imdl torrent verify -i ~/testfile.torrent -c . - failing imdl seems to be confused by .
user@box:~/imdl-test$ imdl torrent verify -i ~/testfile.torrent -c ./testfile - working

In case of looping I think the following happens:

imdl looks relatively to the torrent location. So /data/torrents/torrent1.torrent leads to /data/torrents/torrent1/ as checking location but it should be /data/stuff/torrent1/ when the workingdir is /data/stuff/. The -c option forces imdl to look strictly at the location given. But it seems to be confused by . in a strange way. So it's unimportant where the working dir is imdl torrent verify -i /data/torrents/torrent1.torrent -c /data/stuff/torrent1/ works always unimportant if torrent1 is a folder or a file.

casey commented 3 years ago

Ah, okay, that makes sense, thank you for clarifying.

I think --contents is behaving correctly, since it expects to receive the path to the torrent contents, not the path to a directory that contains the torrent contents.

What do you think about adding a flag called --base-directory which will be concatenated with the name value in the torrent to find the contents. It would be mutually exclusive with --contents.

So you could do:

touch foo
imdl torrent create foo
mkdir subdir
mv foo.torrent subdir
imdl torrent verify subdir/foo.torrent --base-directory .

In the above example, the name field of foo.torrent is foo, so when --base-directory . is passed, imdl would look in ./foo for the torrent contents, instead of alongside foo.torrent in subdir.

DerBunteBall commented 3 years ago

That sounds rellay good. So you can seperate torrents and data.

The killer feature would be something like a bulk report. For example that beside of --base-directory the -i could take something like /data/torrents/*.torrent and a third option like --short-report that tells whether a torrent in the bulk is failing or all succeed.

So like this:

user@box:~$ imdl torrent verify -i /data/torrents/*.torrent --base-path /data/stuff/ --short-report

This should simply tell me: All succeeded or this and this failed. It's ok when short report don't gives the normal output so it could be quiet or refreshing the progress bar for every torrent.

I now copied my torrent files to /data/stuff/ which works fine in a loop actually. But it is a bit of confusing if you have some torrents. So you can overlook something.

casey commented 3 years ago

I added a --base-directory flag in #501.

I'm hesitant to add the ability to process multiple torrents, since often the easiest way to do that will be to write a shell loop and check the exit code of each verify command.