-
Notifications
You must be signed in to change notification settings - Fork 0
/
Downloader_Renamer_Stable.py
100 lines (85 loc) · 3.51 KB
/
Downloader_Renamer_Stable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from bs4 import BeautifulSoup
from tqdm import tqdm
import requests
from requests import get
import os
import re
import time
# -------Enter Your Desired FTP Domain Address-------
try:
domain = 'http://fs.ebox.live'
page = requests.get(input('Enter URL: '))
filetype = '.' + input('Enter File Extension Excluding DOT : ')
soup = BeautifulSoup(page.text, 'html.parser')
# ------The Download Will Begin----------
# ------The Downloaded Files Will Be In Same Directory Where Py File Is-------
exception_occured = False
chunk_size = 1024
for link in soup.find_all('a'):
url = link.get('href')
if(url[-4:] == filetype):
url = domain + url
r = requests.get(url, stream=True)
total_size = int(r.headers['content-length'])
file_name = url.split('/')[-1]
print(file_name)
try:
with open(file_name, 'wb') as file:
for data in tqdm(iterable=r.iter_content(chunk_size=chunk_size), total=total_size/chunk_size, unit='KB'):
file.write(data)
except KeyboardInterrupt as e:
print("Dear User You Have Pressed Ctrl + C")
exception_occured = True
break
if(file.closed != True):
file.close
exception_occured = True
print("File Closed")
except Exception as e:
exception_occured = True
print("Write Failed")
if(not exception_occured):
print("All Files Have Been Downloaded Successfully")
# ------All Files Would Have Been Downloaded By Now-----------
# ------Taking Input For File Extention------
extention = input("Enter Desired File Extention : ")
currentDir = os.getcwd()
print("", end='\n')
print("The Following Files Will Be In : " + extention)
print("", end='\n')
time.sleep(0.5)
print("The Following Files Will Be Renamed To This File FORMAT")
print("", end='\n')
time.sleep(2.0)
# -------Getting File Information Before Renaming-------
series_name_list = []
for files in os.listdir(currentDir):
series_name = files
match_found = re.search(r'\w\d\d\w\d\d', series_name)
if(match_found != None):
series_name = series_name.replace('.', ' ')
match_index_start, match_index_stop = match_found.span()
series_name = series_name[:match_index_stop]
series_name = series_name+"."+extention
series_name_list.append(series_name)
print(series_name)
time.sleep(0.5)
print("", end='\n')
print("Do You Want To Continue : Y/N")
input_value = input("Enter Your Choice : ")
input_value = input_value.lower()
iterator = 0
# --------Renaming Procedure Of The Files--------
if(input_value == 'y'):
for files in os.listdir(currentDir):
series_name = files
match_found = re.search(r'\w\d\d\w\d\d', series_name)
if(match_found != None):
try:
os.rename(series_name, series_name_list[iterator])
iterator = iterator+1
except Exception as e:
print("File Rename Failed"+series_name)
print("The Files Have Been Renamed Succesfully")
except KeyboardInterrupt as e:
print("Dear User You Have Pressed Ctrl + C")