forked from Arctic4161/gogo-downloader
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGoGoDownloaderCLI.py
128 lines (109 loc) · 3.69 KB
/
GoGoDownloaderCLI.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import json
import io
import os
import re
from backend import *
def renameFile(filename: str):
"""_summary_
Args:
filename (str): _description_
Returns:
_type_: _description_
"""
newFileName = "".join(re.split("\(|\)|\[|\]", filename)[::2])
try:
os.rename(filename, newFileName)
return True
except OSError as err:
return err
def loadDownloadHistory():
"""Loads the downloadHistory.json, creates it if it doesn't exist
Returns:
object: download history list
"""
if os.path.isfile("./downloadHistory.json") and os.access(
"./downloadHistory.json", os.R_OK
):
return json.load(open("./downloadHistory.json"))
else:
with io.open(os.path.join("./", "downloadHistory.json"), "w") as db_file:
db_file.write(json.dumps([]))
return json.load(open("./downloadHistory.json"))
def writeShowToDownloadHistory(showName: str, downloadHistory: list):
"""Writes the showName and latestEpisode to the downloadHistory.json file
Args:
showName (str): _description_
downloadHistory (list): _description_
Returns:
_type_: _description_
"""
downloadHistory.append(showName)
with io.open(os.path.join("./", "downloadHistory.json"), "w") as db_file:
db_file.write(json.dumps(downloadHistory))
return json.load(open("./downloadHistory.json"))
def readDownloadHistory(fileNameObject: object, downloadHistory: list):
"""Reads the downloadHistory.json and checks if the fileName is present
Args:
fileNameObject (str): _description_
downloadHistory (list): _description_
Returns:
_type_: _description_
"""
dhFileName = (
fileNameObject["showName"] + " - " + str(fileNameObject["latestEpisode"])
)
if dhFileName not in downloadHistory:
writeShowToDownloadHistory(dhFileName, downloadHistory)
return False
else:
return True
def main():
dh = loadDownloadHistory()
config = config_check()
downloader = gogoanime(
config,
1,
config["CLIQuality"],
"a",
1,
1,
1,
config["CLIDownloadLocation"],
)
list = downloader.get_show_from_bookmark()
dl_links = {}
for ep in list:
if readDownloadHistory(ep, dh):
showName = ep["showName"] + " - " + str(ep["latestEpisode"])
print(f"{IN}{showName} already downloaded")
else:
print(
f"{IN}Scraping DL for "
+ ep["showName"]
+ " Ep "
+ str(ep["latestEpisode"])
)
dl_links[downloader.get_download_link(ep["downloadURL"])] = (
ep["showName"],
ep["latestEpisode"],
)
result = downloader.file_downloader(dl_links)
if config["CleanUpFileName"]:
for file in result.data:
renameFile(file)
if len(result.errors) > 0:
while len(result.errors) > 0:
print(f"{ERR}{len(result.errors)} links failed retrying.")
print(f"{IN}Re-Scraping Links")
dl_links.clear()
for ep in list:
dl_links[downloader.get_download_link(ep["downloadURL"])] = (
ep["showName"],
ep["latestEpisode"],
)
result = downloader.file_downloader(dl_links, overwrite_downloads=0)
if config["CleanUpFileName"]:
for file in result.data:
renameFile(file)
if __name__ == "__main__":
main()