fauzie811

sfile-dl.py

Jun 20th, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. # author : alfianokt
  2. # date   : 20/06/2019
  3. # name   : sfiledw
  4. # desc   : download file di sfile.mobi lewat cli
  5. # git    : https://github.com/alfianokt/sfiledw
  6. # mod by : fauzie811
  7.  
  8. import os, sys
  9. from tqdm import tqdm
  10. from requests import *
  11.  
  12. s = Session()
  13.  
  14. # fungsi ini untuk mengambil nilai tengah
  15. def spliter(va, vb, vc):
  16.     vd = vc.split(va)[1]
  17.     vd = vd.split(vb)[0]
  18.     return vd
  19.  
  20.  
  21. def sfileGrab(url):
  22.     # setting custom headers
  23.     headers = {
  24.         'Host':'sfile.mobi',
  25.         'User-Agent':'MohGila',
  26.         'Referer': url,
  27.         'Connection':'keep-alive',
  28.         'Upgrade-Insecure-Requests':'1',
  29.         'dnt':'1',
  30.         'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  31.         'Accept-Language':'id-ID,en-US;q=0.8',
  32.         'X-Requested-With':'com.android.chrome'
  33.         }
  34.     page = s.get(url, headers=headers)
  35.     href = spliter('id="download" href="', '" onclick', page.text)+'&k=6'
  36.     title = sfileGrabTitle(href)
  37.     file = s.get(href, headers=headers,stream=True)
  38.     file_size = int(file.headers.get('content-length', 0))
  39.     with open(title, 'wb') as fd:
  40.         print('\rDownloading ' + href)
  41.         cols = os.popen('stty size', 'r').read().split()[1]
  42.         pbar = tqdm(total=file_size, unit='B', unit_scale=True, ncols=int(cols))
  43.         for chunk in file.iter_content(1024):
  44.             fd.write(chunk)
  45.             pbar.update(1024)
  46.     pbar.close()
  47.     return 'Successfully downloaded ' + title
  48.  
  49. def sfileGrabTitle(url):
  50.     title = url.split('/')[7]
  51.     title = title.split('&is=')[0]
  52.     return title
  53.  
  54. os.system('clear')
  55. print('''
  56.  _____ _____  ____  _        ___        ___    _          ____  __ __
  57. / ___/|     |l    j| T      /  _]      |   \ | T        |    \|  T  T
  58. (   \_ |   __j |  T | |     /  [_ _____ |    \ | |        |  o  )  |  |
  59. \__  T|  l_   |  | | l___ Y    _]     ||  D  Y| l___     |   _/|  ~  |
  60. /  \ ||   _]  |  | |     T|   [_l_____j|     ||     T __ |  |  l___, |
  61. \   ||  T    j  l |     ||     T      |     ||     ||  T|  |  |     !
  62.  \___jl__j   |____jl_____jl_____j      l_____jl_____jl__jl__j  l____/
  63.                         sfile.mobi downloader
  64.        Author: https://github.com/alfianokt | Mod by: fauzie811
  65. ''')
  66.  
  67. try:
  68.     url = input('sfile.mobi URL: ')
  69.     if(url != ''):
  70.         print('Parsing URL...')
  71.         print(sfileGrab(url))
  72. except KeyboardInterrupt:
  73.     sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment