mikf / gallery-dl

Command-line program to download image galleries and collections from several image hosting sites
GNU General Public License v2.0
11.3k stars 922 forks source link

Gallery dl won't detect my cache file or reddit refresh token #5452

Open vraixen opened 5 months ago

vraixen commented 5 months ago

In my python code i specify a config file with the argument --config. it does seems to detect it however when i try to download a reddit album it ignore the refresh token in it. also i tried specifying the cache file and i get the same thing

this is my config file

{
    "extractor": {

    },
    "downloader": {

    },
    "output": {

    },
    "postprocessor": {

    },
    "cache": {
        "file": "../data/gallery-dl_cache.sqlite3"
    }
}

my python code

@classmethod
    def download_album(cls, url):
        config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "data", "gallery-dl_config.json")
        images = []
        success = True
        try:
            command = f'gallery-dl -g --config "{config_path}" {url}'
            result = subprocess.run(command, shell=True, capture_output=True, text=True)
            print(result.stdout)
            print(result.stderr)
            if "error" not in result.stderr.lower():
                for image_url in result.stdout.splitlines():
                    extension = os.path.splitext(image_url)[1]
                    filename = f"content_{uuid.uuid4().hex}{extension}"
                    final_file_path = os.path.join(cls.TMP_PATH, filename)
                    command = f'gallery-dl --config "{config_path}" -o "{final_file_path}" "{image_url}"'
                    download_result = subprocess.run(command, shell=True, capture_output=True, text=True)
                    print(download_result.stdout)
                    print(download_result.stderr)
                    images.append(final_file_path)
            else:
                cls.logger.error(f"Errore durante il download dell'album: {result.stderr}")
                success = False
        except Exception as e:
            cls.logger.error(f"Errore durante il download dell'album: {e}")
            success = False

        return success, images

My objective is to keep all the configurations in the project data folder so i can move it somewhere else.

mikf commented 5 months ago
        "file": "../data/gallery-dl_cache.sqlite3"

Relative paths are relative to your working directory, not your script or config file. Maybe that's the problem.

While you are already using a config file, why not put your Reddit refresh token directly in there instead of relying on a cache file?

vraixen commented 5 months ago
        "file": "../data/gallery-dl_cache.sqlite3"

Relative paths are relative to your working directory, not your script or config file. Maybe that's the problem.

While you are already using a config file, why not put your Reddit refresh token directly in there instead of relying on a cache file?

because i tried but it doesn't seems to detect it. i also tried using it outside python using the powershell and it doesn't detect it.

mikf commented 5 months ago
        "file": "../data/gallery-dl_cache.sqlite3"

Relative paths are relative to your working directory, not your script or config file. Maybe that's the problem. While you are already using a config file, why not put your Reddit refresh token directly in there instead of relying on a cache file?

because i tried but it doesn't seems to detect it. i also tried using it outside python using the powershell and it doesn't detect it.

What makes you think that?

429 errors are unrelated to a refresh token, by the way. For those you need a custom client ID and user agent.

vraixen commented 5 months ago
        "file": "../data/gallery-dl_cache.sqlite3"

Relative paths are relative to your working directory, not your script or config file. Maybe that's the problem. While you are already using a config file, why not put your Reddit refresh token directly in there instead of relying on a cache file?

because i tried but it doesn't seems to detect it. i also tried using it outside python using the powershell and it doesn't detect it.

What makes you think that?

429 errors are unrelated to a refresh token, by the way. For those you need a custom client ID and user agent.

because when i try to download an album it gives me this output

[reddit][info] Requesting public access token [reddit][info] Register your own OAuth application and use its credentials to prevent this error: https://github.com/mikf/gallery-dl/blob/master/docs/configuration.rst#extractorredditclient-id--user-agent [reddit][info] Waiting until 10:40:09 for rate limit reset.

vraixen commented 5 months ago

https://github.com/mikf/gallery-dl/assets/58710194/06e5d199-8c21-446e-8707-373064692733

and if you wonder if i tried putting the refresh token in the config yes i already tried. maybe you can show me an example on how it should placed correctly inside the json maybe i did somethings wrong.

Hrxn commented 5 months ago
{
    "extractor":
    {
        "base-directory": "./gallery-dl/",

        "reddit":
        {
            "other_options": "here",

            "refresh-token": "<token here>"
        }
    }
}
vraixen commented 5 months ago
{
    "extractor":
    {
        "base-directory": "./gallery-dl/",

        "reddit":
        {
            "other_options": "here",

            "refresh-token": "<token here>"
        }
    }
}

is it correct if this appear? [reddit][info] Refreshing private access token

Hrxn commented 5 months ago

Yes, that's normal.

Neltherion commented 4 months ago

@vraixen

I'm having the same problem as you with a nearly exact Python code. Were you able to fix the problem?