A Couple Scripts to Share, and a Question

Information and Tutorials on features in Mylar and how to use it
wyth
Posts: 42
Joined: Tue Jan 20, 2015 5:09 pm

A Couple Scripts to Share, and a Question

Post by wyth »

Hey all, I just started using Mylar over the last couple days and it's awesome! Thanks evilhero for all your hard work and sharing this with us!

I've written a couple scripts that helped my setup work better, so I thought it'd be good to share them back to the community. I run mylar on a headless ubuntu server, and download with transmission, so the first script is used to remove the torrent from transmission and move it to the folder you have mylar set to watch.

Code: Select all

#!/bin/sh

# port, username, password
SERVER="9091 --auth <Username>:<Password>"

# use transmission-remote to get torrent list from transmission-remote list
# use sed to delete first / last line of output, and remove leading spaces
# use cut to get first field from each line
TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d;$d;s/^ *//' | cut --only-delimited --delimiter=" "  -$

transmission-remote $SERVER --list

# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
    echo Processing : $TORRENTID

    # check if torrent download is completed
    DL_COMPLETED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep "Percent Done: 100%"`

    # check torrents current state is
    STATE_STOPPED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep "State: Seeding\|Stopped\|Finish$
    echo $STATE_STOPPED

    # check torrent is a comic
    IS_COMIC=`transmission-remote $SERVER --torrent $TORRENTID --info | grep -i ".cb"`

        # where the torrent goes
    DEST='/path/to/mylar/watch/folder'

    # if the torrent is "Stopped", "Finished", or "Idle after downloading 100%"
    if [ "$DL_COMPLETED" ] && [ "$STATE_STOPPED" ] && [ "$IS_COMIC" ]; then
        # move the files and remove the torrent from Transmission
        echo "Torrent #$TORRENTID is completed"
        echo "Removing torrent from list"
        transmission-remote $SERVER --torrent $TORRENTID --move "$DEST"
        transmission-remote $SERVER --torrent $TORRENTID --remove
    else
        echo "Torrent #$TORRENTID is not completed. Ignoring."
    fi
done
The next script is what I'm using to send a pushbullet notification to my phone (and subsequently my watch) when a comic is finished being post-processed. I don't particularly care to get notified if it's just being snatched, so that's why I made this script, and set it to be run as an extra script post post-processing.

Code: Select all

#!/bin/bash

# The API Keys
API_KEY="<Your pushbullet api key>"
DEVICE_KEY="<Your pushbullet device id>"

# Strings coming from Mylar
FILE_NAME="$3"

# Body of the Message
BODY="Finished post process for ${FILE_NAME}"

curl -k -u "$API_KEY": https://api.pushbullet.com/v2/pushes -d device_iden="$DEVICE_KEY" -d type=note -d title="$FILE_NAME" -d body="$BODY"
Hopefully this is helpful to someone else too, so I figured I'd post it up here. Lastly, I had a question that is possibly bordering on a feature request, because I'm not sure if it's something that already possible within Mylar.

I'd like to have the option to be able to set how issues get named on a per-series basis. What I mean is sometimes an issue on ComicVine, is simply not the full name of the comic, and it can drive me crazy. An example of this is Injustice: Gods Among Us. The current run is simply called Injustice: Year Three, http://www.comicvine.com/injustice-year ... 050-77226/, and that makes it impossible to find new issues without setting an alternate search name, and also drives my OCD off the wall. I can change the alternate search name so it finds the new issues, and I can also change the directory name and it'll put the issues in the right place, but it still names the issues "Injustice Year Three 0##" whereas I'd like them to be named "Injustice - Gods Among Us - Year Three 0##".

Another Example of this is Federal Bureau of Physics http://www.comicvine.com/fbp-federal-bu ... 050-66760/. I'd much prefer the issues to be renamed to "Federal Bureau of Physics 0##" rather than "FBP Federal Bureau of Physics 0##". I don't have any problems with any of my other comics though, they all get named exactly as I want based on the settings in my configuration.

Thanks again in advance for any insight/help you may be able to offer, and thanks again for such an awesome product at our disposal!
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: A Couple Scripts to Share, and a Question

Post by evilhero »

So awesome, I love it when people start making scripts to use with mylar and help them automate even further. I've used transmission years ago, but I can see this being very handy for users using it. And if I knew more about transmission I could attempt to mock something up in python so that this kind of stuff could be automated even further.

As to the latter part of your post, and the request/enhancement it's about 80% done now on my local repo. I liked the idea so much that I started working on it last night and just have to make the necessary modifications to some other code to allow for it to work across everything (file checking/renaming/post-processing).. Hopefully will go up at some point today depending on the time I have today to finish the work - which isn't much at this point.

The pushbullet notification script is nice - I'm guessing you run it after a successful move to the watch folder?
I'm not sure if you know of it, but there's an option in the Advanced options in the configuration that you can enable that will notify on successful post-processing if the item was a torrent download (and it's manually post-processed obviously but you're already doing the manual part by using the watch folder).

Thanks again for the scripts and the neat feature request (expect that one soon)
wyth
Posts: 42
Joined: Tue Jan 20, 2015 5:09 pm

Re: A Couple Scripts to Share, and a Question

Post by wyth »

That's so awesome to hear! The pushbullet script I have set to run in the option "Use Extra Script AFTER Post-Processing". I did see the option for pushbullet notifications in the advanced tab, which is what gave me the idea for it, but it appeared to only be for on snatch, whereas I wanted it to be after the post-processing of the comic was done.

Can't wait to see that feature go up when you get around to it. I love seeing the message for new commits going up when I log in. You're the best kind of dev, and I'm so glad I found this project.
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: A Couple Scripts to Share, and a Question

Post by evilhero »

Image

Code: Select all

CP Server Thread-5 : Series: Daredevil
CP Server Thread-5 : Alternate File Naming has been enabled for this series. Will rename series title to : The Daredevil man
...
CP Server Thread-5 : New Filename: The Daredevil man 01.5 (2014).cbz
CP Server Thread-5 : Source: The Daredevil 01.5 (2014).cbz
CP Server Thread-5 : Destination: /Comics/Daredevil-(2014)/The Daredevil man 01.5 (2014).cbz
CP Server Thread-5 : Renaming The Daredevil 01.5 (2014).cbz ... to ... The Daredevil man 01.5 (2014).cbz
Keep in mind that if you want the new filenames to get picked up by the file scanner - currently you'll have to add in the name to the Alternate Search Names as well. I'll throw up a fix later on so that's not necessary, but when it gets committed initially, you're gonna have to do that.

Have it currently working with the Rename function - going to test it against the post-processing and then will release it for you to fool around with ;)
wyth
Posts: 42
Joined: Tue Jan 20, 2015 5:09 pm

Re: A Couple Scripts to Share, and a Question

Post by wyth »

I love you.
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: A Couple Scripts to Share, and a Question

Post by evilhero »

And on post-processing;

Code: Select all

Starting postprocessing for : Daredevil 010 (2014) (Digital) (Zone-Empire)
....
[POST-PROCESSING] Series: Daredevil
[POST-PROCESSING] Alternate File Naming has been enabled for this series. Will rename series to : The Daredevil man
...
[POST-PROCESSING] ofilename:Daredevil 010 (2014) (Digital) (Zone-Empire).cbz
[POST-PROCESSING] nfilename:The Daredevil man 010 (2015).cbz
[POST-PROCESSING] Renaming /Comics/Daredevil 010 (2014) (Digital) (Zone-Empire)/Daredevil 010 (2014) (Digital) (Zone-Empire).cbz  ..to.. 
                             /Comics/Daredevil 010 (2014) (Digital) (Zone-Empire)/The Daredevil man 010 (2015).cbz
[POST-PROCESSING] Removed temporary directory : /mnt/mediavg/Incoming/Comics/Daredevil 010 (2014) (Digital) (Zone-Empire)
Expect it up today (at some point) !
wyth
Posts: 42
Joined: Tue Jan 20, 2015 5:09 pm

Re: A Couple Scripts to Share, and a Question

Post by wyth »

So awesome. I'm going to have all my comics be named to The _____ man from now on. :P
wyth
Posts: 42
Joined: Tue Jan 20, 2015 5:09 pm

Re: A Couple Scripts to Share, and a Question

Post by wyth »

This is working perfectly! Thank you!
Tucker28
Posts: 10
Joined: Thu Jan 29, 2015 5:07 am

Re: A Couple Scripts to Share, and a Question

Post by Tucker28 »

Will this first script automatically take the completed file and move it into the specific comic's folder?
wyth
Posts: 42
Joined: Tue Jan 20, 2015 5:09 pm

Re: A Couple Scripts to Share, and a Question

Post by wyth »

Tucker28 wrote:Will this first script automatically take the completed file and move it into the specific comic's folder?
No, it moves it into your mylar watch folder where it waits to get post processed, assuming you have that set up. If you do mylar takes care of putting it into the specific conics folder.
Post Reply