From 01c3d23b4298adcee9550fa68071136b64ef2f5c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 4 Oct 2018 16:24:56 -0700 Subject: [PATCH] Changing delimiter to ; Adding a find.sh script --- README.md | 43 +++++++++++++++++++------------------------ add_torrents.sh | 6 ++---- find.sh | 22 ++++++++++++++++++++++ torrent.csv | 2 +- 4 files changed, 44 insertions(+), 29 deletions(-) create mode 100755 find.sh diff --git a/README.md b/README.md index 45452bd..b701e06 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,28 @@ # Torrent.csv -Torrent.csv is a vetted database of torrents, consisting of a -single, searchable `torrent.csv` file. +`Torrent.csv` is a vetted database of torrents, consisting of a single, searchable `torrent.csv` file. -An "upload", consists of making a pull request adding your torrents -to the last line of the file. +An *upload*, consists of making a pull request after running the `add_torrents.sh` script that adds your new unique torrents to the file, after checking that they aren't already there, and that they have seeders. +To find torrents run `./find.sh "SEARCH"` -Run `./torrents_to_csv.sh ~/TORRENTS_DIR` to generate your add lines. +To contribute: +- [Click here](https://gitlab.com/dessalines/torrent.csv/forks/new) to fork this repo. +```sh +git clone https://gitlab.com/[MY_USER]/torrent.csv +cd torrent.csv +./add_torrents.sh MY_TORRENTS_DIR # `MY_TORRENTS_DIR` is `~/.local/share/data/qBittorrent/BT_backup/` for qBittorrent on linux, but you can search for where your torrents are stored for your client. +git commit -am "Adding my torrents" +git push +``` +Then [click here](https://gitlab.com/dessalines/torrent.csv/merge_requests/new) to do a pull/merge request to my branch. -The file will periodically be sorted -by `name`, and `seeders` descending. +## How the file looks +```sh +infohash;name;size_bytes;created_unix;seeders;leechers;completed;scraped_date +# torrents here... +``` -## Columns - -name,size_bytes,infohash,created_unix,seeders,leechers,completed,scraped_date - -To get the correct format run this script: `todo.txt` - -Seeder and leecher counts are necessary, I suggest using the [ -torrent-tracker-scraper](https://github.com/ZigmundVonZaun/torrent-tracker-scraper) -to get seeders, leechers, and completed. - -The columns are... - -Start with that one huge backup. - -TODO -- Create add line script. Inputs a torrent or a torrent directory, and spits out the add lines. -- Add a Dup checker +`Torrent.csv` will be periodically purged of non-seeded torrents, and potentially sorted. diff --git a/add_torrents.sh b/add_torrents.sh index b19cd25..e6560f7 100755 --- a/add_torrents.sh +++ b/add_torrents.sh @@ -1,5 +1,3 @@ -export LC_ALL=C - # Checking arguments # Help line torrent_csv_file="`pwd`/torrent.csv" @@ -46,7 +44,7 @@ for torrent_file in *.torrent; do # echo "show text = $show_text" name=$(grep -Po -m 1 'Name: \K.*' <<< $show_text) - name=$(sed 's/,/\\,/g' <<< $name) # Escape the commas for .csv + name=$(sed 's/;/\\;/g' <<< $name) # Escape the commas for .csv # Size: Unfortunately this will chop off some sigfigs size=$(grep -Po 'Total Size: \K.*' <<< $show_text) @@ -70,7 +68,7 @@ for torrent_file in *.torrent; do scraped_date=$(date +%s) # Construct add line - add_line="$infohash,$name,$size_bytes,$created_date,$seeders,$leechers,$completed,$scraped_date" + add_line="$infohash;$name;$size_bytes;$created_date;$seeders;$leechers;$completed;$scraped_date" # Only add the line if there are seeds, and the infohash doesn't already exist if (( $seeders > 0 )) && ! grep -q $infohash $torrent_csv_file; then diff --git a/find.sh b/find.sh new file mode 100755 index 0000000..81a53fd --- /dev/null +++ b/find.sh @@ -0,0 +1,22 @@ +torrent_csv_file="`pwd`/torrent.csv" + +search=$(grep -i "$1" $torrent_csv_file) + +# Sort results by seeders +search=$(echo -e "$search" | sort --field-separator=';' --key=5 -g) + +if [ -z "$search" ]; then + echo "No results found" +else + + # Read the lines of the results + while read -r line; do + infohash=$(echo -e "$line" | cut -d ';' -f1) + magnet_link="magnet:?xt=urn:btih:$infohash" + name=$(echo -e "$line" | cut -d ';' -f2) + + # Construct the search result + result="$name\n\t$magnet_link" + echo -e "$result" + done <<< "$search" +fi diff --git a/torrent.csv b/torrent.csv index 39bd916..7610edc 100644 --- a/torrent.csv +++ b/torrent.csv @@ -1 +1 @@ -infohash,name,size_bytes,created_unix,seeders,leechers,completed,scraped_date \ No newline at end of file +infohash;name;size_bytes;created_unix;seeders;leechers;completed;scraped_date \ No newline at end of file