iTunes Match + SABnzbd (iOS)

Got a program that plays well with SABnzbd? Share it here!
Post Reply
throwaway
Newbie
Newbie
Posts: 9
Joined: December 12th, 2011, 5:24 am

iTunes Match + SABnzbd (iOS)

Post by throwaway »

Hey guys,
I spent the last few hours working on a cool idea I have had since iTunes Match came out.

My idea: Set up SABnzbd on a machine that is always on (Server/Old PC) and install iTunes and activate iTunes Match, then use myNZB (iOS) or some other iOS app that talks to SABnzbd to start a download for some music album (Obviously one that is not represented by a label/Copy-written) and set up SABnzbd to move the completed download into the iTunes Mp3 watch folder which forces iTunes to add it to the library and then upload it to iCloud.

To make this easier here is the work flow I had in mind:
* Start download via iOS device (Not needed but this is the cool part)
* Download finishes and gets added to iTunes
* iTunes adds music to iCloud (Via "Uploaded" or "Matched", which should not happen because you are not downloading songs that you should pay for, right?)
* Song is available for download on iOS device

Originally I was going to use an old desktop computer of mine but I was having problems with it so decided to look elsewhere. Then I decided to use a VPS on cloud hosting so that I didn't have to maintain any hardware and I would be able to scale my work for more people (ie. my Friends/Family). The first VPS hosting I paid for I had a lot of problems (Windows hosting is ALWAYS a pain but I needed it for iTunes) but I was able to get my initial proof-of-concept working and then I turned to Amazon EC2. I was excited to use EC2 because I had never used it and wanted a project to learn more.

I had MANY roadblocks along the way including:
* iTunes refusing to start without an error because their was no sound card (Duh, it's a headless server)
* Problems getting SABnzbd to run as a system service
* Problems getting the DynDNS update to work
but after about 17 hours (Yea, it's been a long day) I am writing this post.

My bigest reason for wanting to go with EC2 is the ability to turn off/on the server to save costs and AWS has a free tier that I am taking advantage of. Here is my final workflow:

* Run a small webapp (Bookmarked to the homescreen, in the picture it's called "Launch Server", don't judge me for my complete lack of designing skills)
Image
* Webapp is hosted on a shared host I have and makes API calls over to EC2 to start up the server and then API calls to DynDNS to update the DNS records (This is needed because every time you start/stop a EC2 instance you lose the dynamic IP address you were assigned so I used DynDNS so that I could point myNZB to Hostname-here.dyndns.org and let DynDNS tell myNZB where SABnzbd is running)
Image
Image
Image
(Again don't judge me by my lack of design skills)
* Once the server is started up and the DNS is updated (Approx. 2mins on a micro windows 2008 instance) the webapp is done and now it's time to move on to myNZB
**** At this point I would love to use URL Schemes (http://developer.apple.com/library/ios/ ... ction.html) to open myNZB immediately after the DNS resolves yet myNZB does not have a URL Scheme :-\
* Now I just open myNZB
* Download something and it's pushed to itunes which is opened up by SABnzbd on completion of download
* Song shows up in iTunes (iOS or desktop) available for download
* 30 mins after the VPS is powered on it shuts it's self down to save $$$$

This whole process takes ~6mins, the download is insanely fast due to it sitting on Amazon's network (Average of 7-12MB/s, yes MegaBytes not bits <- That is how fast SABnzbd reports, here is a speed test Image). Yes it's not instantaneous download-to-iOS solution but it works for me and I would guess the majority of people.

Now the important question, how much does it cost?
iTunes Match: $25/yr
Amazon EC2: (Not as straight forward)
For this I had to make some guesstimates, I way over estimated so that it was worst-case

For each hour the VPS is on it cost money, and from what I can tell even if you turn on your VPS for a few minutes it will count as 1 hour so I will assume for every album you want to download it will "cost" you one hour. Here are the assumptions I am going to make, and yes I know they are high:
# of Albums/month: 20 albums (Way high I know but I threw extra in there just in case)
Average size of album: 100mb
So about 2GB of data will be downloaded/month and 2GB will be uploaded (to iTunes Servers assuming none are "matched")

When you plug this all into the EC2 calculator you get the SUPER HIGH price of $0.72/month (This is BEFORE the free tier discount which brings mine down to $0.57/month)

Total: $33.69/Year

Step 2 is to expand to Friends/Family and write more code that talks to the EC2 API to better manage and track everything. This is very simple to do as I can simply clone my instance over and over and just RDP in to each one to enter the iTunes login details of Friends/Family. My small webapp will also be worked on to provide more than dumb-startup and actually be able to manage the VM. A possibility is using Titanium Mobile to write a mobile app (Which I have done before) so that it is a little more stable and has more access to the device.

I am more than happy to answer any/all of your questions on how I did it and I can also provide you with access to the most of the code I wrote to make this possible. I just spent/wasted 17hrs when I should have been studying for my exams so I hope at least someone takes something away from this. I look forward to continuing to work on this and find new and interesting ways to bend awesome technologies to do awesome (at least in my mind) things. Thanks for your time!

pducharme
Newbie
Newbie
Posts: 12
Joined: December 17th, 2011, 11:37 am

Re: iTunes Match + SABnzbd (iOS)

Post by pducharme »

How you make the extracted files to be imported automatically in itunes? I plan to do the same, but from my always on imac.

throwaway
Newbie
Newbie
Posts: 9
Joined: December 12th, 2011, 5:24 am

Re: iTunes Match + SABnzbd (iOS)

Post by throwaway »

Well to be honest I do 2 things.
1) Move completed music folder into the "Automatically add to iTunes" folder
2) Run iTunes.exe [Completed Folder] on completion

But this is because I am on windows and have no other options, I use a mac and if I were doing this on OS X I would make heavy use of AppleScript to add them to iTunes. I am not sure if AppleScript has support for iTunes match but in my case the two steps above (I'm not sure which exactly but together they work) successfully adds the music and iTunes adds it to iTunes match almost instantly

pducharme
Newbie
Newbie
Posts: 12
Joined: December 17th, 2011, 11:37 am

Re: iTunes Match + SABnzbd (iOS)

Post by pducharme »

i'm on OS X. I created a Bash script with the following :

Code: Select all

#!/bin/bash
#1 = Full path to the downloaded file
#3 = Folder name of the download
#delete any files which you don’t want to copy
echo "Deleting the bumfluff…"
rm -f "$1"/*.nfo

rm -f "$1"/*.srr

rm -f "$1"/*.sfv

rm -f "$1"/*.nzb

rm -f "$1"/*.m3u

rm -f "$1"/*.jpg
echo "[done]"
#copy the file to your remote location

cp -fv "$1"/*.mp3 "/Users/pducharme/Music/iTunes/iTunes Music/Automatically Add to iTunes/"
echo "[done]"
echo "Adding to iTunes"
osascript <<APPLESCRIPT
tell application "iTunes" to add "volumes:Macintosh HD:Users:pducharme:Music:iTunes:iTunes Music:Automatically Add to iTunes" to playlist "Library"'
end tell
APPLESCRIPT

exit
Unfortunately, only the parts that move *.mp3 to that folder is working, the APPLESCRIPT to add to iTunes does noting. If I run it manually, it gives errors.

Anyone know a good itunes Import script ?

Also, if I quit iTunes and reopen it, it doesn't automatically import the files i putted in this folder...

Pat

throwaway
Newbie
Newbie
Posts: 9
Joined: December 12th, 2011, 5:24 am

Re: iTunes Match + SABnzbd (iOS)

Post by throwaway »

Code: Select all

tell application "iTunes"
		launch
		add "/Users/pducharme/Music/iTunes/iTunes Music/Automatically Add to iTunes/" to playlist "Library" of source "Library"
	end tell
I think this is code you need to use

pducharme
Newbie
Newbie
Posts: 12
Joined: December 17th, 2011, 11:37 am

Re: iTunes Match + SABnzbd (iOS)

Post by pducharme »

Adding to iTunes
45:164: execution error: iTunes got an error: "/Users/pducharme/Music/iTunes/iTunes Music/Automatically Add to iTunes/" doesn’t understand the add message. (-1708

This is the output I get when running the script. My folder (/Users/pducharme/Music/iTunes/iTunes Music/Automatically Add to iTunes/) contains 10 mp3 files in no subfolders, they are all tracks from an album...

throwaway
Newbie
Newbie
Posts: 9
Joined: December 12th, 2011, 5:24 am

Re: iTunes Match + SABnzbd (iOS)

Post by throwaway »

Try this link and attach the action on your "Automatically Add to iTunes" folder

pducharme
Newbie
Newbie
Posts: 12
Joined: December 17th, 2011, 11:37 am

Re: iTunes Match + SABnzbd (iOS)

Post by pducharme »

It works, but it doesn't take them all, strangely, it's random, it will see the 4-5-6-7-8 first tunes and let the other one in the folder... Also, if the tags are wrong, i'll loose them in the library.

throwaway
Newbie
Newbie
Posts: 9
Joined: December 12th, 2011, 5:24 am

Re: iTunes Match + SABnzbd (iOS)

Post by throwaway »

I don't know off the top of my head how to do it in AppleSciprt but I would suggest creating a "Added via AppleScript" or some other playlist that you clear out and add the most recently added songs to so that if the tags are wrong you have all the songs you imported in one easy to find place

pducharme
Newbie
Newbie
Posts: 12
Joined: December 17th, 2011, 11:37 am

Re: iTunes Match + SABnzbd (iOS)

Post by pducharme »

The problem is that I don't want the song to be NOT matched because of the Tags and get uploaded instead of matched...

pducharme
Newbie
Newbie
Posts: 12
Joined: December 17th, 2011, 11:37 am

Re: iTunes Match + SABnzbd (iOS)

Post by pducharme »

i'm currently trying "Headphones", works great, except 1st scan is veryyyyy slow, I guess that when it will be complete, it will be perfect to download albums. Just need to manually add them to itunes for now.

ayashi38
Newbie
Newbie
Posts: 7
Joined: March 27th, 2010, 5:41 am

Re: iTunes Match + SABnzbd (iOS)

Post by ayashi38 »

Headphone + post processing in Automatically Add ... directory. Itunes always started.

Done

Post Reply