mirror of
				https://github.com/karl0ss/GoGoDownloader.git
				synced 2025-11-03 16:11:02 +00:00 
			
		
		
		
	working CLI tool
This commit is contained in:
		
							parent
							
								
									fc19a690bd
								
							
						
					
					
						commit
						8210e0b07b
					
				@ -1,24 +1,81 @@
 | 
				
			|||||||
from backend import *
 | 
					 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
import io
 | 
					import io
 | 
				
			||||||
import os
 | 
					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():
 | 
					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(
 | 
					    if os.path.isfile("./downloadHistory.json") and os.access(
 | 
				
			||||||
        "./downloadHistory.json", os.R_OK
 | 
					        "./downloadHistory.json", os.R_OK
 | 
				
			||||||
    ):
 | 
					    ):
 | 
				
			||||||
        return json.load(open("./downloadHistory.json"))
 | 
					        return json.load(open("./downloadHistory.json"))
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        print("Either file is missing or is not readable, creating file...")
 | 
					 | 
				
			||||||
        with io.open(os.path.join("./", "downloadHistory.json"), "w") as db_file:
 | 
					        with io.open(os.path.join("./", "downloadHistory.json"), "w") as db_file:
 | 
				
			||||||
            db_file.write(json.dumps([]))
 | 
					            db_file.write(json.dumps([]))
 | 
				
			||||||
        return json.load(open("./downloadHistory.json"))
 | 
					        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():
 | 
					def main():
 | 
				
			||||||
    dh = loadDownloadHistory()
 | 
					    dh = loadDownloadHistory()
 | 
				
			||||||
 | 
					 | 
				
			||||||
    config = config_check()
 | 
					    config = config_check()
 | 
				
			||||||
    downloader = gogoanime(
 | 
					    downloader = gogoanime(
 | 
				
			||||||
        config,
 | 
					        config,
 | 
				
			||||||
@ -33,18 +90,28 @@ def main():
 | 
				
			|||||||
    list = downloader.get_show_from_bookmark()
 | 
					    list = downloader.get_show_from_bookmark()
 | 
				
			||||||
    dl_links = {}
 | 
					    dl_links = {}
 | 
				
			||||||
    for ep in list:
 | 
					    for ep in list:
 | 
				
			||||||
        print(
 | 
					        if readDownloadHistory(ep, dh):
 | 
				
			||||||
            "{OK}Scraping DL for " + ep["showName"] + " Ep " + str(ep["latestEpisode"])
 | 
					            showName = ep["showName"] + " - " + str(ep["latestEpisode"])
 | 
				
			||||||
        )
 | 
					            print(f"{IN}{showName} already downloaded")
 | 
				
			||||||
        dl_links[downloader.get_download_link(ep["downloadURL"])] = (
 | 
					        else:
 | 
				
			||||||
            ep["showName"],
 | 
					            print(
 | 
				
			||||||
            ep["latestEpisode"],
 | 
					                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)
 | 
					    result = downloader.file_downloader(dl_links)
 | 
				
			||||||
 | 
					    if config["CleanUpFileName"]:
 | 
				
			||||||
 | 
					        for file in result.data:
 | 
				
			||||||
 | 
					            renameFile(file)
 | 
				
			||||||
    if len(result.errors) > 0:
 | 
					    if len(result.errors) > 0:
 | 
				
			||||||
        while len(result.errors) > 0:
 | 
					        while len(result.errors) > 0:
 | 
				
			||||||
            print(f"{ERR}{len(result.errors)} links failed retrying.")
 | 
					            print(f"{ERR}{len(result.errors)} links failed retrying.")
 | 
				
			||||||
            print(f"{OK}Re-Scraping Links")
 | 
					            print(f"{IN}Re-Scraping Links")
 | 
				
			||||||
            dl_links.clear()
 | 
					            dl_links.clear()
 | 
				
			||||||
            for ep in list:
 | 
					            for ep in list:
 | 
				
			||||||
                dl_links[downloader.get_download_link(ep["downloadURL"])] = (
 | 
					                dl_links[downloader.get_download_link(ep["downloadURL"])] = (
 | 
				
			||||||
@ -52,6 +119,9 @@ def main():
 | 
				
			|||||||
                    ep["latestEpisode"],
 | 
					                    ep["latestEpisode"],
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            result = downloader.file_downloader(dl_links, overwrite_downloads=0)
 | 
					            result = downloader.file_downloader(dl_links, overwrite_downloads=0)
 | 
				
			||||||
 | 
					            if config["CleanUpFileName"]:
 | 
				
			||||||
 | 
					                for file in result.data:
 | 
				
			||||||
 | 
					                    renameFile(file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										14
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								README.md
									
									
									
									
									
								
							@ -57,16 +57,20 @@ If you want to run from source, or are using Linux/Mac you can run directly from
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## Usage
 | 
					## 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
 | 
					### Examples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##### One word title
 | 
					##### One word title
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- https://gogoanime.film/category/bakemonogatari >> bakemonogatari
 | 
					- https://gogoanime.gg/category/bakemonogatari >> bakemonogatari
 | 
				
			||||||
- https://gogoanime.film/category/steinsgate >> steinsgate
 | 
					- https://gogoanime.gg/category/steinsgate >> steinsgate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##### Multiple word title
 | 
					##### Multiple word title
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- https://gogoanime.film/category/shadows-house >> shadows-house
 | 
					- https://gogoanime.gg/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/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.
 | 
				
			||||||
@ -214,10 +214,11 @@ class gogoanime:
 | 
				
			|||||||
        return files
 | 
					        return files
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_show_from_bookmark(self):
 | 
					    def get_show_from_bookmark(self):
 | 
				
			||||||
 | 
					        print(f"{IN}Loading shows from bookmarks")
 | 
				
			||||||
        bookmarkList = []
 | 
					        bookmarkList = []
 | 
				
			||||||
        a = dict(auth=gogoanime.get_gogoanime_auth_cookie(self))
 | 
					        a = dict(auth=gogoanime.get_gogoanime_auth_cookie(self))
 | 
				
			||||||
        resp = requests.get(
 | 
					        resp = requests.get(
 | 
				
			||||||
            "https://gogoanime.gg/user/bookmark",
 | 
					            f"https://gogoanime.{self.config['CurrentGoGoAnimeDomain']}/user/bookmark",
 | 
				
			||||||
            cookies=a,
 | 
					            cookies=a,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        soup = BeautifulSoup(resp.text, "html.parser")
 | 
					        soup = BeautifulSoup(resp.text, "html.parser")
 | 
				
			||||||
 | 
				
			|||||||
@ -5,5 +5,6 @@
 | 
				
			|||||||
    "CurrentGoGoAnimeDomain": "gg",
 | 
					    "CurrentGoGoAnimeDomain": "gg",
 | 
				
			||||||
    "OverwriteDownloads": 0,
 | 
					    "OverwriteDownloads": 0,
 | 
				
			||||||
    "CLIQuality":"720",
 | 
					    "CLIQuality":"720",
 | 
				
			||||||
    "CLIDownloadLocation": "CLIOutput"
 | 
					    "CLIDownloadLocation": "CLIOutput",
 | 
				
			||||||
 | 
					    "CleanUpFileName": false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user