Advertisement
Guest User

Untitled

a guest
Mar 29th, 2016
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. import requests
  2. import json
  3.  
  4. requests.packages.urllib3.disable_warnings()
  5.  
  6. ####################################################################
  7. #CHANGE THIS STUFFS:
  8. username = "EMAIL"
  9. password = "PASSWORD"
  10. ####################################################################
  11.  
  12. __author__ = "calvin"
  13. __license__ = "WTFPL (Do What The Fuck You Want To Public License)"
  14. __version__ = "1.1"
  15.  
  16. #Python 2 compatability
  17. try:
  18. input = raw_input
  19. except NameError:
  20. pass
  21.  
  22. class Mofibo(object):
  23. session = requests.session()
  24. session.headers.update({"User-agent": "Dalvik/1.5.1 (Linux; U; Android 5.0; Nexus 6)",
  25. "X-Mofibo-ApiLicenseKey": "rrhSFUajl6R1GWXfRUAVn5b9",
  26. "X-Mofibo-AppType": "Mobile",
  27. "X-Mofibo-DeviceInfo": '{ "Identifier": "1", "Name": "Nexus 4", "OperatingSystem": "Android","SystemVersion": "4.2", "Model": "Nexus+S","Appversion": "1.0.2"}',
  28. 'Content-type': 'application/json',
  29. "X-Mofibo-Capabilities": "audio"
  30. })
  31.  
  32. def login(self, username, password):
  33. url = "https://api.mofibo.com/api/account/login"
  34. data = {"Username": username, "Password": password}
  35. req = self.session.post(url, data=json.dumps(data), verify=False)
  36. self.session.cookies["FedAuth"] = self.session.cookies["FedAuth"] #Stupid cookielib, why you so hard.
  37.  
  38. def get_book_url(self, id):
  39. url = "https://api.mofibo.com/api/books/contentlink?id={}&fullBook=true".format(id)
  40. req = self.session.get(url, verify=False)
  41. return req.json()["ExternalUrl"]
  42.  
  43. def get_book(self, id, secondary=False):
  44. title = None
  45.  
  46. if secondary:
  47. req = self.session.get("https://api.mofibo.com/api/books/id/{0}".format(id)).json()
  48. id = req['buddyId']
  49. title = req['Title']
  50.  
  51. url = self.get_book_url(id)
  52. req = self.session.get(url, verify=False, stream=True)
  53.  
  54. if secondary:
  55. filename = "".join(x for x in title if x.isalnum()) + ".mp3"
  56. else:
  57. filename = req.headers["Content-Disposition"].split("filename=")[1]
  58. chunk_size = 1024
  59.  
  60. with open(filename, 'wb') as fd:
  61. for chunk in req.iter_content(chunk_size):
  62. fd.write(chunk)
  63.  
  64. m = Mofibo()
  65. print("Logging in...")
  66. m.login(username, password)
  67. print("Logged in.")
  68. book = input("Enter book id: ")
  69. secondary = input("Secondary (If the book has both ebook and audio, and you want audio. (True/False): ")
  70. secondary = secondary == "True"
  71. print("Downloading book")
  72. m.get_book(book, secondary)
  73. print("Done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement