KurtBestor / Hitomi-Downloader

:cake: Desktop utility to download images/videos/music/text from various websites, and more.
22.23k stars 2.05k forks source link

How to process url before downloading #4455

Open itinybad opened 2 years ago

itinybad commented 2 years ago

I noticed the hook script, but only after the hook task is completed in the provided sample script, is there any related support?

KurtBestor commented 2 years ago

There are 3 hooks supported:

Hook.task_about_to_start
Hook.task_about_to_download
Hook.task_finished
itinybad commented 2 years ago

There are 3 hooks supported:

Hook.task_about_to_start
Hook.task_about_to_download
Hook.task_finished

Thanks for the reply, can you provide detailed documentation, or a sample script

KurtBestor commented 2 years ago

Here is a sample:

from utils import Hook
import os

@Hook.task_about_to_start('test')
def hook(cw):
    cw.print_('Hook: about_to_start')
    cw.print_(f'type: {cw.type}')

@Hook.task_about_to_download('test')
def hook(cw):
    cw.print_('Hook: about_to_download')

@Hook.task_finished('test')
def hook(cw):
    cw.print_('Hook: finished')
    if not cw.valid:
        return
    with open(os.path.join(cw.dir, 'hook_test.txt'), 'wb') as f:
        f.write('url: {}'.format(cw.url).encode('utf8'))