Created
February 9, 2019 14:02
-
-
Save 3f8wohoo/2c675cd2df345f33760d571c5f084d6c to your computer and use it in GitHub Desktop.
Extract name from torrent and rename .torrent file
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
#!/bin/bash | |
# Usage: rename-torrent.sh /path/to/torrents /path/to/output | |
# | |
# read-torrent must be installed | |
# npm install -g read-torrent | |
if [[ -z $1 ]]; then | |
echo "No input path specified!" | |
exit 1 | |
else | |
inputPath="$1" | |
fi | |
if [[ -z $2 ]]; then | |
echo "No output path specified; creating directory..." | |
outputPath="done" | |
if [[ ! -d "$outputPath" ]]; then | |
mkdir "$outputPath" | |
fi | |
else | |
outputPath="$2" | |
fi | |
for filename in "$inputPath/*"; do | |
echo "Reading $filename" | |
torrentID=$(basename "$filename") | |
torrentName=$(read-torrent "$filename" | head -4 | grep name | sed 's/name: //' | sed 's/\///') | |
echo "Name: $torrentName" | |
mv "$filename" "$outputPath/$torrentName - $torrentID" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment