Rapidshare to Megaupload script
aiwarrior
zubeido at yahoo.com.br
Sat Feb 14 15:46:25 EST 2009
I've made this script and would like to have some input and share it
with the community.
I also have a page with some code i produce on my spare time. http://pneves.net
Thanks
# -*- coding: utf-8 -*-
## I Paulo Neves am the owner of this script and i do not allow the
copy or distribution
## of this script without my permission to commercial purposes
## If you have any suggestions please mail me and i will reply and
post the on the site
from __future__ import with_statement
from urlparse import urljoin
import urllib2, urllib
import os, sys
import re
import ConfigParser
urls = []
acc_details = 0
firs_run = 0
def from_rapidshare(url):
'''Check if this is a rapidshare link'''
return (url.startswith("rapidshare.com") or
url.startswith("www.rapidshare.com") or
url.startswith("http://rapidshare.com") or
url.startswith("http://www.rapidshare.com"))
def account_details():
if os.environ.has_key("APPDATA") and os.path.exists(os.environ
["APPDATA"]):
path = os.environ["APPDATA"] + "\\murs.cfg"
else:
path = os.path.expanduser("~") + "\.murs.cfg"
if not os.path.exists(path):
print path
m_user = raw_input("Enter your user name for megaupload: ")
m_password = raw_input("Enter your password for megaupload: ")
r_user = raw_input("Enter your user name for rapidshare: ")
r_password = raw_input("Enter your password for rapidshare: ")
cfg = ConfigParser.SafeConfigParser()
cfg.add_section('Acc_Details')
cfg.set('Acc_Details', 'm_user ', m_user)
cfg.set('Acc_Details', 'm_password', m_password)
cfg.set('Acc_Details', 'r_user', r_user)
cfg.set('Acc_Details', 'r_password', r_password)
with open(path, 'wb') as configfile:
cfg.write(configfile)
cfg = ConfigParser.SafeConfigParser()
cfg.read(path)
try:
m_user = cfg.get("Acc_Details", "m_user")
m_password = cfg.get("Acc_Details", "m_password")
r_user = cfg.get("Acc_Details", "r_user")
r_password = cfg.get("Acc_Details", "r_password")
except ConfigParser.NoSectionError or ConfigParser.NoOptionError:
print "no section or No Option"
print
os.remove(path)
return (m_user, m_password, r_user, r_password)
def cookie_processor(cookie):
cookie = cookie.split("; ")
## cookie = dict( [cookie[x].split("=") for x in xrange ( len
(cookie) ) ] )
## if cookie['user'] != None:
return cookie
## else:
## print "Scheme has changed or authentication failes. Last
option most likely"
## sys.exit()
##
def rs_auth(login):
r_user = login[0]
r_password = login[1]
opener = urllib2.build_opener(urllib2.HTTPSHandler())
urllib2.install_opener( opener )
cred = urllib.urlencode({"login": r_user, "password": r_password})
try:
req = urllib2.urlopen("https://ssl.rapidshare.com/cgi-bin/
premiumzone.cgi", cred)
cookie_rs = cookie_processor( req.headers.get("set-cookie",
"") )
except urllib2.URLError:
print"Some error with the connection ocurred. Try again now or
later"
sys.exit()
#Returns the page if flag is set
return req.read(), cookie_rs
def mu_auth(login):
r_user = login[0]
r_password = login[1]
cred = urllib.urlencode({"login": r_user, "password": r_password})
try:
req = urllib2.urlopen("http://www.megaupload.com", cred)
cookie_mu = cookie_processor( req.headers.get("set-cookie",
"") )
except:
print "Connection failed"
sys.exit()
#returns the authenticated header, in case future changes
specificaly ask the cookie it would be easy
#to change code or even extract it from the header itself as a
dictionary key
return cookie_mu
def set_rscookie_in_musite(cookie_mu, cookie_rs) :
#it doesnt need to check for the cookie because it automaticaly
resets for the new value
cookie_rs = cookie_rs.split("=",1)
header = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain", "cookie":cookie_mu}
params = urllib.urlencode({'domain': "http://rapidshare.com",
'cookiename1': cookie_rs[0], 'cookievalue1': cookie[1] })
req = urllib2.Request("http://www.megaupload.com/multifetch/?
c=cookies", params, header )
print header
print params
#r = urllib2.urlopen(req)
return True
acc_details = account_details()
if len(sys.argv)==1:
print "Try -help for more information"
sys.exit("No arguments")
if sys.argv[1] == "-h" or sys.argv[1] == "–help":
print " > murs http://megaupload.com/?d=FILE1 … http://megaupload.com/?d=FILEN"
print " Download one or several rapidshare links passed as
argument separated by whitespace\n"
print " >murs links.txt"
print " Download a list of links from a file\n"
print " >murs account"
print " Automaticaly downloads the entire contents of your
account"
sys.exit()
## Process the arguments
## AFTER THIS ITS ALL ROLLING
if sys.argv[1] == "account" or sys.argv[1] == "-a":
#Getting the rapidshare user and password respectivelyfrom the
account details already called
print acc_details[2:]
page = rs_auth( acc_details[2:] )
rex = re.findall('''Adliste\["(........|.)"\]\["filename"\] =
"(.*)"''', page[0])
for retrieved_data in rex:
#as there are two matches the retrieved_data is still a
list
urls.append("http://rapidshare.com/files/" + retrieved_data
[0] + "/" + retrieved_data[1])
elif os.path.exists(sys.argv[1]): # If this is a file
from_file = True
l_file = sys.argv[1]
print "Reading list of links from the file " , l_file
print "\n"
list_f = file(l_file, "r")
urls = list_f.readlines()
list_f.close()
if not from_rapidshare(urls):
sys.exit("Urls in text file were not valid")
elif from_rapidshare(sys.argv[1]): #if argument is one or more urls
for i in range(1, len(sys.argv)):
if from_rapidshare(sys.argv[i]):
urls.append(sys.argv[i])
else:
print "This is not valid argument" , sys.argv[1]
sys.exit()
urls = []
cookie_mu = mu_auth(acc_details[:2])
print cookie_mu
headers = {"User Agent": "Mozilla/5.0", "Accept": "text/plain",
"cookie":cookie_mu[0]}
for url in urls:
try:
params = urllib.urlencode({'srcurl': url, 'description':
"something"})
req = urllib2.Request("http://megaupload.com/multifetch/",
params, headers )
r = urllib2.urlopen(req)
except:
print "An error ocurred while trying to talk to megaupload.
Make sure you enter the correct password"
More information about the Python-list
mailing list