fork download
  1. import re
  2. import os
  3. import time
  4. import requests
  5. from random import *
  6. from tkinter import *
  7. import tkinter.filedialog as fd
  8. class Download():
  9. def __init__ (self, link):
  10. self.mainlink = link + '?p='
  11. self.allinks = []
  12. self.n = 0
  13.  
  14. def randname(n):
  15. return ''.join(sample(''.join([chr(i)*randint(1,3) for i in range(97,123)])+ str(randint(11111,99999))*10, n))
  16.  
  17. def rawlinks(self):
  18. allinks = []
  19. p = 0
  20. mainpage = requests.get(self.mainlink+str(p)).content.decode()
  21. number_of_pages = int(re.search(r'(?<=Images:<\/td><td\s{1}class=\"gdt2\">)(\d+)(?=\s{1}@)',mainpage).group())//40
  22. raw_links = re.findall(r'(?<=href=\")(http:\/\/g\.e-hentai.org\/s\/[a-z0-9\/-]+\d+\b)(?=\")',mainpage)
  23. while p <= number_of_pages+1:
  24. raw_links = re.findall(r'(?<=href=\")(http:\/\/g\.e-hentai.org\/s\/[a-z0-9\/-]+\d+\b)(?=\")',mainpage)
  25. for elem in raw_links:
  26. allinks+=elem.split(' ')
  27. raw_links = []
  28. mainpage = requests.get(self.mainlink+str(p)).content.decode()
  29. p+=1
  30. self.allinks = list(set(allinks))
  31. self.n = len(self.allinks)
  32.  
  33. def load(self):
  34. j = 0
  35. try:
  36. while j <= self.n:
  37. page = requests.get(self.allinks[j]).content.decode()
  38. true_link = re.search(r'(?<=src=\")(http:\/\/\d{1,3}\.\d{1,3}\S+)(?=\"\s{1}st)', page).group()
  39. ext = re.search(r'(?<=\w{1}\.{1})([jpgnife]{3,4})(?=\b)',true_link).group()
  40. pic = requests.get(true_link).content
  41. time.sleep(1)
  42. f = open(Download.randname(16)+'.'+ ext,'wb')
  43. f.write(pic)
  44. f.close()
  45. j+=1
  46. except IndexError:
  47. pass
  48.  
  49. def copypast(e):
  50. lk=mainw.selection_get(selection='CLIPBOARD')
  51. mylink.insert(1, lk)
  52.  
  53. def opendir():
  54. f = fd.askdirectory()
  55. try:
  56. os.chdir(f)
  57. except: pass
  58.  
  59. def go():
  60. s = mylink.get()
  61. b2.configure(state='disabled')
  62. mylink.configure(state='disabled')
  63. d = Download(s)
  64. d.rawlinks()
  65. d.load()
  66. b2.configure(state='normal')
  67. mylink.configure(state='normal')
  68. mylink.delete(0,END)
  69.  
  70. mainw = Tk()
  71. mainw.title('g.e-hentai.org downloader')
  72. mainw.resizable(0,0)
  73. mainw.geometry('300x240')
  74.  
  75. mylink = Entry(mainw,width=30)
  76. text1 = Label(mainw, text='My link:',font=14)
  77. text2 = Label(mainw,text='My folder:',font=14)
  78. b = Button(text='...',height=1,width=22,command=opendir)
  79. b2 = Button(height=6,width=18,bg='#80DAEB',text='Start',fg='purple',font=18,command=go)
  80. b2.place(x=80,y=100)
  81. b.place(x=90,y=45)
  82. text1.place(x=8,y=10)
  83. text2.place(x=8,y=48)
  84. mylink.place(x=75,y=10)
  85. mylink.bind(lambda event='<Control-v>' : copypast)
  86.  
  87. mainw.mainloop()
Runtime error #stdin #stdout #stderr 0.24s 33400KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
/bin/sh: 1: cannot create /dev/null: Permission denied
/bin/sh: 1: cannot create /dev/null: Permission denied
/bin/sh: 1: cannot create /dev/null: Permission denied
/bin/sh: 1: cannot create /dev/null: Permission denied
Traceback (most recent call last):
  File "./prog.py", line 70, in <module>
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1854, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable