renter
Posts: 3
Joined: Thu Dec 13, 2012 8:55 am

Automatically download movies from ftp

Thu Dec 13, 2012 8:58 am

So I wanted software that could automatically download my movies to the pi without any hassle from my ftp server so I wrote a python script to do just that. If you set it up with cron it is completly automated and will check for any new movies on your ftp server every day at 11pm. Here are the install instructions. http://renter.no-ip.org/autoUpdater.py
1) SSH into your raspberry
----------------------------------------
2) Install curlftpfs
apt-get install curlftpfs
----------------------------------------
3) Download the python script to your server
wget http://renter.no-ip.org/autoUpdater.py
----------------------------------------
4) Make a directory to for the ftp to be mounted to
mkdir /mnt/seedbox
----------------------------------------
5) Edit the script with your login details and where you want the movies to be saved
nano autoUpdater.py
saveTo is where the movies will be saved
readFrom is /mnt/seedbox
ftpUser is your ftp username
ftpPass is your ftp password
ftpServer is the url of your ftp server. It can be an ip
fileType is the type of file you want to download. avi mkv etc
----------------------------------------
6) Now we setup a cron job to automatically run the script once a day.
crontab -e
Select an editor
At the botton add the following text
0 23 * * * python /path_to_script
The /patch_to_script is where you saved the file. This will run once a day at 11pm.

If you guys want I can make a video on how to install it but its really quite simple

ski522
Posts: 394
Joined: Sun Sep 30, 2012 2:22 pm

Re: Automatically download movies from ftp

Thu Dec 13, 2012 11:50 am

Curious...but wouldn't it be easier to just leave the movies on your FTP server and access them through the pi via a NFS/Samba mount? That's how I do it...just wondering.

User avatar
Dweeber
Posts: 606
Joined: Fri Aug 17, 2012 3:35 am
Location: Mesa, AZ
Contact: Website

Re: Automatically download movies from ftp

Thu Dec 13, 2012 11:56 am

I would concur... I mount my ISO directory from the NAS (FreeNAS) and just play them off of that. Gives me 3TB of file access. Even using a Wireless WiFi connection (don' t have wired access near the TV), the speed is more than enough.
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com

renter
Posts: 3
Joined: Thu Dec 13, 2012 8:55 am

Re: Automatically download movies from ftp

Thu Dec 13, 2012 12:17 pm

It would but I am going to be using this at my fathers where the internet is very bad. So for me it is easier to have it download in the background at night and then when he wants to see it its there.

toinoze
Posts: 4
Joined: Wed Jan 02, 2013 6:13 pm

Re: Automatically download movies from ftp

Wed Jan 02, 2013 6:24 pm

I´ve tryed your script, but have changed the file type, and nothing happens, I want to use it with mp3 files, I'm very newby with linux, could you please give me a hand

jamiesk
Posts: 95
Joined: Mon Nov 26, 2012 8:48 pm
Location: Ipswich, Suffolk, England, UK.

Re: Automatically download movies from ftp

Thu Jan 03, 2013 8:06 am

toinoze wrote:I´ve tryed your script, but have changed the file type, and nothing happens, I want to use it with mp3 files, I'm very newby with linux, could you please give me a hand
Stoopid Q 1) Did you setup the username, password, etc ?
Pi1 (Nov 2012 loft)= 1KW immersion controller for Solar panel
Pi2 (Jan 2013 living room)=Play thing
Pi3 (Feb 2013 mobile)= Play thing with Tandy Ladder board,breakout board,Nokia display
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=28193

toinoze
Posts: 4
Joined: Wed Jan 02, 2013 6:13 pm

Re: Automatically download movies from ftp

Thu Jan 03, 2013 9:44 am

of course, the only change that I made was the "avi" to "mp3", I put my ftpserver pass, my username, create the folder readfrom and saveto, I used the script in raspberry pi with xbmc and in another with wheezy with ni luck

jamiesk
Posts: 95
Joined: Mon Nov 26, 2012 8:48 pm
Location: Ipswich, Suffolk, England, UK.

Re: Automatically download movies from ftp

Thu Jan 03, 2013 11:57 am

toinoze wrote:of course, the only change that I made was the "avi" to "mp3", I put my ftpserver pass, my username, create the folder readfrom and saveto, I used the script in raspberry pi with xbmc and in another with wheezy with ni luck
are there any error messages reported on either machine?

sudo more /var/log/messages

If you change back to "avi" does it work? Put a small file onto the server if you want to debug quicker...

echo "This is a test" > test.avi

HTH, Keith
Pi1 (Nov 2012 loft)= 1KW immersion controller for Solar panel
Pi2 (Jan 2013 living room)=Play thing
Pi3 (Feb 2013 mobile)= Play thing with Tandy Ladder board,breakout board,Nokia display
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=28193

toinoze
Posts: 4
Joined: Wed Jan 02, 2013 6:13 pm

Re: Automatically download movies from ftp

Thu Jan 03, 2013 12:16 pm

when I run it on wheezy it gives me a syntax error
This the script:

saveTo = "/home/Música"
readFrom = "/mnt/seedbox"

ftpUser = "XXXXX"
ftpPass = "XXXXXXX"
ftpServer = "ftp://XXXXXXXXXXX.com/files"

fileType = "mp3"

import os
import shutil
import shlex, subprocess

a = []
newFiles = False

print "Mounting ftp server to " + readFrom

return_code = subprocess.call("curlftpfs -o allow_other " + ftpUser + ":" + ftpPass + "@" + ftpServer + " " + readFrom, shell=True)

print "Checking for new files..."

for dirname, dirnames, filenames in os.walk(saveTo):
for filename in filenames:
if filename.rsplit('.', 1)[1] == fileType:
a.append(os.path.join(dirname, filename).replace(saveTo, ""));

for dirname1, dirnames1, filenames1 in os.walk(readFrom):
for filename1 in filenames1:
if filename1.rsplit('.', 1)[1] == fileType:
if os.path.join(dirname1, filename1).rsplit('/', 1)[1] not in a:
shutil.copyfile(os.path.join(dirname1, filename1), saveTo + filename1)
print "Added -- " + filename1
newFiles = True

print "Unmounting ftp server from " + readFrom

return_code = subprocess.call("umount " + readFrom, shell=True)

if newFiles:
print "Done! Saved to - " + saveTo
else:
print "Done! No new files"

jamiesk
Posts: 95
Joined: Mon Nov 26, 2012 8:48 pm
Location: Ipswich, Suffolk, England, UK.

Re: Automatically download movies from ftp

Thu Jan 03, 2013 2:22 pm

toinoze wrote: fireturn_code = subprocess.call("curlftpfs -o allow_other " + ftpUser + ":" + ftpPass + "@" + ftpServer + " " + readFrom, shell=True)
This should be one line. Is it ?
Pi1 (Nov 2012 loft)= 1KW immersion controller for Solar panel
Pi2 (Jan 2013 living room)=Play thing
Pi3 (Feb 2013 mobile)= Play thing with Tandy Ladder board,breakout board,Nokia display
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=28193

toinoze
Posts: 4
Joined: Wed Jan 02, 2013 6:13 pm

Re: Automatically download movies from ftp

Thu Jan 03, 2013 2:29 pm

yes it is

jamiesk
Posts: 95
Joined: Mon Nov 26, 2012 8:48 pm
Location: Ipswich, Suffolk, England, UK.

Re: Automatically download movies from ftp

Thu Jan 03, 2013 6:41 pm

the line ...

Code: Select all

return_code = subprocess.call("curlftpfs -o allow_other " + ftpUser + ":" + ftpPass + "@" + ftpServer + " " + readFrom, shell=True)
adds the value ftpServer and I think is "just" needs the server XXXXXXXXXXX.com, not ftp://XXXXXXXXXXX.com/files

If not them I'm out of here as I'm on the end of my knowledge. Sorry.
Pi1 (Nov 2012 loft)= 1KW immersion controller for Solar panel
Pi2 (Jan 2013 living room)=Play thing
Pi3 (Feb 2013 mobile)= Play thing with Tandy Ladder board,breakout board,Nokia display
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=28193

1983
Posts: 16
Joined: Wed Mar 26, 2014 3:29 am

Re: Automatically download movies from ftp

Wed Mar 26, 2014 11:16 am

I need this script for a project. Any chance someone has access to the script as the link is now longer working :(

Thanks.. ;)

1983
Posts: 16
Joined: Wed Mar 26, 2014 3:29 am

Re: Automatically download movies from ftp

Wed Mar 26, 2014 2:19 pm

Just to say I have tried copying and pasting the above example code someone else put on in a reply.

Get formatting issues (expected an indented block) etc, so formatting was obviously stripped out when they pasted it on here.

Maybe some cover person knows where all the indents go in that above example code?

Sorry I'm a bit of a noob but getting there.

Thanks..

Return to “General discussion”