Last active
May 23, 2019 05:33
-
-
Save Ryahn/337c2edbd53863089cba23095a41ec6f to your computer and use it in GitHub Desktop.
Make torrent file based on size with accurate piece size
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 | |
#title :mkt | |
#description :This script will create a torrent file with the correct piece size in mind | |
#author :Ryahn | |
#date :20190523 | |
#version :0.1.9 | |
#usage :bash mkt | ./mkt | put in bin folder to use globally | |
#notes :Install mktorrent to use | |
#bash_version :4.4.12(1)-release | |
#license :MIT | |
#=============================================# | |
# Change to the tracker URL you would like # | |
# use multiple -a to add multiple tracker URL # | |
# -a http://sukebei.tracker.wf:8888/announce # | |
# -a udp://open.stealth.si:80/announce # | |
#=============================================# | |
announce="-a URL" | |
#=============================================# | |
# DO NOT TOUCH BELOW THIS LINE # | |
#=============================================# | |
l15=52428800 #32KiB piece size - 50MiB | |
l16=157286400 #64KiB piece size - 150MiB | |
l17=367001600 #128KiB piece size - 350MiB | |
l18=536870912 #256KiB piece size - 512MiB | |
l19=1073741824 #512KiB piece size - 1GiB | |
l20=5368709120 #1MiB piece size - 5GiB | |
l21=10737418240 #2MiB piece size - 10GiB | |
l22=16106127360 #4MiB piece size - 15GiB | |
l23=21474836480 #8MiB piece size - 20GiB | |
l24=26843545600 #16MiB piece size - 25GiB | |
for i in "$@"; do | |
#Get file/folder size | |
SIZE=$(find $i ! -type d -printf '%s\n' | paste -sd+ - | bc) | |
#Get human readable size | |
h=$(du -sh "$i" | awk '{print $1;}') | |
#Get absolute path | |
path=$(readlink -f "$i") | |
#Check file size and set piece size | |
if (( SIZE <= l15 )); | |
then | |
p=15 | |
p1="32KiB piece size" | |
elif (( SIZE > l15 && SIZE <= l16 )); | |
then | |
p=16 | |
p1="64KiB piece size" | |
elif (( SIZE > l16 && SIZE <= l17 )); | |
then | |
p=17 | |
p1="128KiB piece size" | |
elif (( SIZE > l17 && SIZE <= l18 )); | |
then | |
p=18 | |
p1="256KiB piece size" | |
elif (( SIZE > l18 && SIZE <= l19 )); | |
then | |
p=19 | |
p1="512KiB piece size" | |
elif (( SIZE > l19 && SIZE <= l20 )); | |
then | |
p=20 | |
p1="1MiB piece size" | |
elif (( SIZE > l20 && SIZE <= l21 )); | |
then | |
p=21 | |
p1="2MiB piece size" | |
elif (( SIZE > l21 && SIZE <= l22 )); | |
then | |
p=22 | |
p1="4MiB piece size" | |
elif (( SIZE > l22 && SIZE <= l23 )); | |
then | |
p=23 | |
p1="8MiB piece size" | |
elif (( SIZE >= l23 && SIZE == l24 )); | |
then | |
p=24 | |
p1="16MiB piece size" | |
else | |
p=24 | |
p1="16MiB piece size" | |
fi | |
echo " | |
Making Torrent | |
------------------------ | |
Name: $i | |
Filesize (bytes/human): $SIZE/$h | |
Piece Size: $p1 | |
------------------------" | |
#Make torrent | |
mktorrent -l $p $announce -o "${@%/}.torrent" "$path" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment