diff --git a/.gitignore b/.gitignore index bfb8e83..78c9960 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ __pycache__/ build/ dist/ main.spec +.vscode/launch.json +app.log +bookmarkList.json +downloadHistory.json diff --git a/GoGoDownloaderCLI.py b/GoGoDownloaderCLI.py new file mode 100644 index 0000000..c5050c7 --- /dev/null +++ b/GoGoDownloaderCLI.py @@ -0,0 +1,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() diff --git a/README.md b/README.md index 62c2176..990f7a6 100644 --- a/README.md +++ b/README.md @@ -57,16 +57,20 @@ If you want to run from source, or are using Linux/Mac you can run directly from ## Usage -The anime name is separated by "-". You can either type it manually, or go to [gogoanime.film](https://gogoanime.film/) and search for the anime you want to download and copy the name from the URL. +The anime name is separated by "-". You can either type it manually, or go to [gogoanime.gg](https://gogoanime.gg/) and search for the anime you want to download and copy the name from the URL. ### Examples ##### One word title -- https://gogoanime.film/category/bakemonogatari >> bakemonogatari -- https://gogoanime.film/category/steinsgate >> steinsgate +- https://gogoanime.gg/category/bakemonogatari >> bakemonogatari +- https://gogoanime.gg/category/steinsgate >> steinsgate ##### Multiple word title -- https://gogoanime.film/category/shadows-house >> shadows-house -- https://gogoanime.film/category/kono-subarashii-sekai-ni-shukufuku-wo- >> kono-subarashii-sekai-ni-shukufuku-wo- +- https://gogoanime.gg/category/shadows-house >> shadows-house +- https://gogoanime.gg/category/kono-subarashii-sekai-ni-shukufuku-wo- >> kono-subarashii-sekai-ni-shukufuku-wo- + + +# GoGoDownloader CLI +I have now also created the GoGoDownloader CLI, this tool can be used to run on a scheduled basis, it will login and get the latest episodes from your GoGoAnime bookmarks, and download the latest episode if it has not been downloaded yet. \ No newline at end of file diff --git a/backend.py b/backend.py index 0a42c22..9b79c69 100644 --- a/backend.py +++ b/backend.py @@ -213,6 +213,42 @@ class gogoanime: files = dl.download() return files + def get_show_from_bookmark(self): + print(f"{IN}Loading shows from bookmarks") + bookmarkList = [] + a = dict(auth=gogoanime.get_gogoanime_auth_cookie(self)) + resp = requests.get( + f"https://gogoanime.{self.config['CurrentGoGoAnimeDomain']}/user/bookmark", + cookies=a, + ) + soup = BeautifulSoup(resp.text, "html.parser") + table = soup.find("div", attrs={"class": "article_bookmark"}) + splitTableLines = table.text.split("Remove") + for rows in splitTableLines: + fullRow = " ".join(rows.split()) + if "Anime name" in fullRow: + fullRow = fullRow.replace("Anime name Latest", "") + splitRow = fullRow.split("Latest") + elif fullRow == "Status": + break + else: + fullRow = fullRow.replace("Status ", "") + splitRow = fullRow.split("Latest") + animeName = splitRow[0].strip().encode("ascii", "ignore").decode() + animeName = re.sub("[^A-Za-z0-9 ]+", "", animeName) + animeDownloadName = animeName.replace(" ", "-").lower() + episodeNum = splitRow[-1].split()[-1] + bookmarkList.append( + { + "showName": animeName, + "latestEpisode": int(episodeNum), + "downloadURL": f"https://gogoanime.{self.config['CurrentGoGoAnimeDomain']}/{animeDownloadName}-episode-{str(episodeNum)}", + } + ) + with open("bookmarkList.json", "w") as f: + json.dump(bookmarkList, f) + return bookmarkList + @dataclass(init=True) class CustomMessage(Exception): diff --git a/config.json.default b/config.json.default index 210af6f..5bce992 100644 --- a/config.json.default +++ b/config.json.default @@ -3,5 +3,8 @@ "GoGoAnime_Password":"", "MaxConcurrentDownloads": 4, "CurrentGoGoAnimeDomain": "gg", - "OverwriteDownloads": 0 + "OverwriteDownloads": 0, + "CLIQuality":"720", + "CLIDownloadLocation": "CLIOutput", + "CleanUpFileName": false } diff --git a/version.txt b/version.txt index 50e47c8..a4f52a5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.1.1 \ No newline at end of file +3.2.0 \ No newline at end of file