Skip to content

Instantly share code, notes, and snippets.

@tuankiet65
Last active October 13, 2017 13:36
Show Gist options
  • Save tuankiet65/ef2886cebb21554b0cc403e5fec8742a to your computer and use it in GitHub Desktop.
Save tuankiet65/ef2886cebb21554b0cc403e5fec8742a to your computer and use it in GitHub Desktop.
Script to un-delete deleted but restorable files on 4Share (requires user account). Script depends on requests and beautifulsoup4.
import requests
import re
import time
from bs4 import BeautifulSoup
# Login by some means (in the browser, curl, etc) and paste the cookie value here
COOKIES = {
"__tawkuuid": "",
"SHARINGSESSID4S": ""
}
session = requests.Session()
# Change this number to something above your total number of files
item_per_page = 10000
print("Setting item per page to {}".format(item_per_page))
req = session.get("https://4share.vn/cloud/index/filter/type/set_n_item_a_page/n_item/".format(item_per_page),
cookies = COOKIES,
allow_redirects = False)
assert(req.status_code == 302)
print("Getting file list")
req = session.get("https://4share.vn/cloud/index", cookies = COOKIES, allow_redirects = False)
req.raise_for_status()
page = BeautifulSoup(req.text, 'lxml')
files_to_undelete = []
for elem in page.find_all('a', href=re.compile("un-delete")):
files_to_undelete.append(elem['href'])
counter = len(files_to_undelete)
print("{} files to undelete".format(counter))
for file in files_to_undelete:
print("Undeleting {}".format(file))
req = session.post("https://4share.vn/{}".format(file), cookies = COOKIES, allow_redirects = False)
assert(req.status_code == 302)
assert(req.headers['Location'] == "/cloud/index")
counter -= 1
print("Undelete successfully, waiting for 5s before next request")
print("{} files left to go".format(counter))
# Sleep for 5 sec to reduce request rate
# Or else you might get banned (I haven't but take this as a warning)
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment