Rapidshare premium download using python

I used to download from rapidshare using wget as descripted here.
Since Rapidshare changed there website this method stopped working, so I decided to write a simple python script using the rapidshare api to help me out.
There might be a few bugs but it generally serves its purpose.

#!/usr/bin/env python
 
import urllib
import os
import sys
 
args = sys.argv;
 
username = 'your_username'
passw = 'your_password'
 
linkfile = ''
link = ''
download_dir = ''
 
if '-h' in args or len(args) == 1:
  print 'Usage: ' + args[0] + ' options link || linkslist'
  print '\tOptions: '
  print '\t-h help'
  print '\t-d download directory e.g. /home/user/downloads'
  print '\t-l linklist'
  exit()
 
if '-d' in args:
  if args.index('-d') >= (len(args) - 1):
    exit('missing argument for -d')
  else:
    download_dir = args[args.index('-d') + 1]
 
if '-l' in args:
  if args.index('-l') >= (len(args) - 1):
    exit('missing argument for -l')
  else:
    linkfile = args[args.index('-l') + 1]
 
if '-l' not in args and len(args) > 1:
  link = args[len(args) - 1]
 
if linkfile == '' and link == '':
  exit('No links given. You have to give either a list of links or a single link. type ' + args[0] + ' -h for more information')
 
input = list()
if linkfile != '':
  input = open(linkfile, 'r')
else:
  input = [link]
 
for line in input:
  if(line == ''):
    continue
  linkmap = line.split('/')
  fileid = linkmap[4]
  filename = linkmap[5].rstrip()
  f = urllib.urlopen('http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles_v1&files=' + fileid + '&filenames=' + filename)
  serverid = f.read().split(',')[3]
  link = 'http://rs' + serverid + 'dt.rapidshare.com/cgi-bin/rsapi.cgi?sub=download_v1\&filename=' + filename + '\&login=' + username + '\&password=' + passw + '\&fileid=' + fileid
  os.system('wget -c -O ' + download_dir + filename + ' ' + link)

The scripts requires wget to be installed.

Leave a Reply

Kontakt: mail@gamgee.de