Skip to content
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

Help with transmission script to unrar torrents #75

Closed
mightymads opened this issue May 11, 2016 · 18 comments
Closed

Help with transmission script to unrar torrents #75

mightymads opened this issue May 11, 2016 · 18 comments

Comments

@mightymads
Copy link

mightymads commented May 11, 2016

Hi,

First of all thanks for making this available to the public! It works like a charm on my Synology DSM 6 and it was fairly easy to setup and configure to my liking.

I'm however having some problems trying to get transmission to automatically unpack downloaded files. I have configured transmission to execute a simple script after downloading completes using TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED and TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME, and it can navigate to the torrent using TR_TORRENT_DIR and TR_TORRENT_NAME.

The problem is that it doesn't seem like calling unrar or 7z works - or at least nothing seems to happen when calling them. If I do a 'which unrar' inside the script it correctly logs '/bin/unrar'. But when I try to unrar files nothing happens - and I have tried all sorts of different variations using relative path and absolute path to unrar, and even copying unrar to the torrent directory and calling it with "./unrar", but all to no avail.

Anything special I need to be aware of here? Is something in the nature of this setup preventing a script from executing binaries? Any help would be highly appreciated.

Thanks.

haugene added a commit that referenced this issue May 11, 2016
@haugene
Copy link
Owner

haugene commented May 11, 2016

Hey, and thanks :)

When I exec'ed into the container it doesn't seem unrar is installed.

root@3d1f6f2b91c2:/# unrar
bash: unrar: command not found

When you checked 'which unrar' and it said '/bin/unrar', was that on the commandline to your Synology, or inside the container? The script will be executed by transmission inside the container where unrar does not exist.

I added rar and unrar to the container, they are nice to have tools for simple scripts like this. Pull the image again using the dev tag and let me know how it goes ;)

@mightymads
Copy link
Author

Man you rule! Now my script is able to unrar files - sweet.

Would it be possible to add unzip, 7z or similar to the container as well?

For you question about 'which unrar' I must admit that I was doing a lot of hacking while trying to make unrar work so not really sure how correct my answer would be actually. Can we just leave it at that ;)

Thanks again for a fast fix!

@haugene
Copy link
Owner

haugene commented May 12, 2016

Haha, no worries. Let's leave it at that :)

I added zip and unzip as well, I guess that covers the basics of packing and unpacking stuff. You can check it out, it's on the dev tag for now. I'm gonna merge it to master sometime soon, just got to clean up a little first.

@haugene
Copy link
Owner

haugene commented May 13, 2016

Fix is merged to master and available on the main tag. That should close this...

@haugene haugene closed this as completed May 13, 2016
@mightymads
Copy link
Author

Mange tak :-)

@haugene
Copy link
Owner

haugene commented May 14, 2016

Bare hyggelig

@ethanopp
Copy link

ethanopp commented Mar 1, 2017

mightymads / haugene,

I realize this issue is closed but was hoping you could help shed a little light on exactly how you pointed your container to the script...

I have the following simple script saved as a "unrar.sh"

#!/bin/bash find /data/completed/Sonarr -name '*.rar' -execdir unrar e -o- {} \;

In my docker run I have the following volume mounted
-v "/share/CACHEDEV1_DATA/Library/Application Support/Transmission-AirVPN":/unrar \

and then in my DockerEnv, I have
TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED=true TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME= "/unrar/unrar.sh"

The unrar.sh file is placed in /share/CACHEDEV1_DATA/Library/Application Support/Transmission-AirVPN

When I run the container I get the following error:
/etc/transmission/start.sh: 58: export: /unrar/unrar.sh: bad variable name

What am I doing wrong?

@mightymads
Copy link
Author

Hi ethanopp,

Not sure I can be of much help, but I can tell you how I have configured it.

In my docker run script I have added:
-v /volume1/downloads/:/data \
-e "TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED=true" \
-e "TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME=/data/extract_torrent.sh" \

And I have placed extract_torrent.sh in:
/volume1/downloads

extract_torrent.sh looks like this:
#!/bin/bash
CUR_DIR=`pwd`
cd $TR_TORRENT_DIR
test -d "$TR_TORRENT_NAME" && cd "$TR_TORRENT_NAME"
unrar e -inul *.rar
7z e *.zip > /dev/null 2>&1
cd $CUR_DIR

Hope it helps.

@ethanopp
Copy link

ethanopp commented Mar 1, 2017

Thanks for the quick response!

Looking at your code actually made me realize an error in mine...

I had a space between
TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME= "/unrar/unrar.sh"

Updating to this seems to avoid the error I was previously getting TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME="/unrar/unrar.sh"

Now I'm just downloading something to see if my bash script works, may have to steal yours if it doesn't.

Thanks again!

@ethanopp
Copy link

ethanopp commented Mar 2, 2017

Script doesn't seem to work when a download completes...

What is odd though is if I SSH into the container and manually run the script, it works as expected.

Any other ideas?

I've set the scripts permissions to 0777

@ethanopp
Copy link

ethanopp commented Mar 2, 2017

Restarted everything... seems to be working now.

Thanks again for the help!

@jamesmanning
Copy link

@haugene I didn't want to open a new issue about this since it's likely intentional / by-design, but is there a chance that the image could change in such a way that automatically extracting rar/zip/etc either Just Worked(tm) or could be turned on with a single boolean setting? It's completely fine if not, of course, and this thread is perfect for how to get a script going that'll handle it, but I just wanted to see if it was possible to have something more "in the box". 😄 Maybe something like the script from @mightymads being included in the transmission dir (looks like the image already includes the things the script depends on AFAICT) so it would end up in /etc/transmission in the image, then the default TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME could point to it and a user would only need to turn on TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED for this (I would imagine common?) case? Thanks!!

@haugene
Copy link
Owner

haugene commented Nov 29, 2017

Hi!

I'm not opposed to a boolean switch saying "unzip/untar stuff automatically and bundling a script for it. I'd suggest you create a new issue for it, describe the need and link it to this issue and the script you're mentioning and then see if someone can help bundle it. I'm not sure I'll be able to look at it in a while, kind of moving and changing jobs, so a lot happening :)

@zaphod007
Copy link

Hello all,

after a long journey as a total noob I got everything working thanks to countless hours of reading through this and other material, however I still lack some basic skill obviously as I cant figure out what/how to change the script to move the unpacked items in a specific directory on my data mount instead of the same directory where the rar files are. Can somebody help me? This is what I use and it works for me, thanks to @mightymads post above:
In my docker run script I have added:
-v /volume1/downloads/:/data
-e "TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED=true"
-e "TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME=/data/extract_torrent.sh" \

And I have placed extract_torrent.sh in:
/volume1/downloads

extract_torrent.sh looks like this:
#!/bin/bash
CUR_DIR=pwd
cd $TR_TORRENT_DIR
test -d "$TR_TORRENT_NAME" && cd "$TR_TORRENT_NAME"
unrar e -inul *.rar
7z e *.zip > /dev/null 2>&1
cd $CUR_DIR

@mightymads
Copy link
Author

mightymads commented Apr 17, 2018

@zaphod007 great work :-)

Without having tried this I assume you can simply change the lines:
unrar e -inul *.rar
7z e *.zip > /dev/null 2>&1

To something like:
unrar e -inul *.rar PATH_TO_DIR
7z e *-zip -oPATH_TO_DIR > /dev/null 2>&1

Where PATH_TO_DIR could be something like:
/volume1/my-extracted-files

@zaphod007
Copy link

works like a charm (just needed to add a blank space between -o and PATH in the last line and path to dir= /data/unrar/, thank you so much @mightymads !

@ensignvorik
Copy link

Just wanted to thank the poster for their script and haugene for implementing unrar and that 3 years after posting, this post is still useful.

@waleedayoub
Copy link

Hello all,

after a long journey as a total noob I got everything working thanks to countless hours of reading through this and other material, however I still lack some basic skill obviously as I cant figure out what/how to change the script to move the unpacked items in a specific directory on my data mount instead of the same directory where the rar files are. Can somebody help me? This is what I use and it works for me, thanks to @mightymads post above: In my docker run script I have added: -v /volume1/downloads/:/data -e "TRANSMISSION_SCRIPT_TORRENT_DONE_ENABLED=true" -e "TRANSMISSION_SCRIPT_TORRENT_DONE_FILENAME=/data/extract_torrent.sh" \

And I have placed extract_torrent.sh in: /volume1/downloads

extract_torrent.sh looks like this: #!/bin/bash CUR_DIR=pwd cd $TR_TORRENT_DIR test -d "$TR_TORRENT_NAME" && cd "$TR_TORRENT_NAME" unrar e -inul *.rar 7z e *.zip > /dev/null 2>&1 cd $CUR_DIR

Hi there, found this thread while trying to implement my own unrar when a torrent is completed, so thanks all!
One question I can't figure out: Where does the $TR_TORRENT_NAME environment variable get set? Is that something that is only available once a torrent is downloaded temporarily? When I docker exec into my transmission container, I don't see this as a variable. Thanks in advance! And hope people are still reading this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants