8thbit

LaracastsDownloader.py

Mar 28th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. #!/usr/bin/python
  2. #Script By 8ThBiT.net ~
  3. import requests
  4. import re
  5. import os
  6. import sys
  7. from bs4 import BeautifulSoup
  8.  
  9.  
  10. def getUrl(u):
  11.     r = requests.session()
  12.     return r.get(u).text
  13.  
  14.  
  15. if len(sys.argv) == 1:
  16.     print "[!] Usage {0} https://laracasts.com/series/laravel-from-scratch-2017".format(sys.argv[0])
  17.     exit(-1)
  18. url = sys.argv[1]
  19. if(url[len(url) -1 ] != '/'):
  20.     url = url + "/"
  21.  
  22. print "[+] Getting Course Episodes"
  23. CoursePage = getUrl(url)
  24. match = re.findall('<strong>(\d+)<\/strong>',CoursePage,flags=re.MULTILINE)
  25. if(len(match) != 1):
  26.     print "Invalid Response"
  27.     exit(-1)
  28. cl = int(match[0])
  29. cl = cl + 1
  30. for i in range(1,cl):
  31.     episode = "{0}episodes/{1}".format(url, i)
  32.     print "[+] Sending Request to {0}".format(episode)
  33.     episodePage = getUrl(episode)
  34.     soup = BeautifulSoup(episodePage,'html.parser')
  35.     title = soup.select('meta[property="og:title"]')[0]["content"]
  36.  
  37.     sources = soup.findAll('source')
  38.     if len(sources) > 1:
  39.         for source in sources:
  40.             if(source['data-quality'] == 'HD'):
  41.                 print "[+] Downloading {0} - {1}".format((str(i).zfill(3)),title)
  42.                 os.system('wget -O "{0} - {1}.{2}" {3}'.format((str(i).zfill(3)),title,"mp4",'https:' + source["src"]))
  43.     elif len(sources) == 1:
  44.         print "[+] Downloading {0}".format(title)
  45.         os.system('wget -O "{0} - {1}.{2}" {3}'.format((str(i).zfill(3)), title, "mp4", 'https:' + sources["src"]))
  46.     else:
  47.         print "[-] No Video Source For Episode {0}".format(i)
Add Comment
Please, Sign In to add comment