用户工具

站点工具


mangacon:downloader-en

Third-party Downloader Support of MangaCon

简体中文版本>>

Although MangaCon provides an internal downloader, but sometimes you may still need a third-party downloader to download the images parsed by MangaCon. For this purpose, MangaCon provides some downloader APIs, you can write a component to support your third-party downloaders yourself.

Downloader API

You can get downloader APIs and a demo component from here.

Component Specification

The downloader component of MangaCon should obey the specifications below:

  1. The component must be named as MangaDownloader.dll.
  2. The component must export a function named McGetDownloaderManager:
    MangaCon::DownloaderManager* WINAPI McGetDownloaderManager(void);

DownloaderManager Interface

class DownloaderManager
{
public:
    typedef void (WINAPI * EnumProc)(PCSTR pszID, PCWSTR pwzName, PVOID pvParam);
    virtual void WINAPI EnumDownloaders(EnumProc pfnEnum, PVOID pvParam) = 0;
 
    virtual Downloader* WINAPI GetDownloader(PCSTR pszID) = 0;
};

DownloaderManager is the interface of downloader manager, it is implemented by the component.

Methods

  • EnumDownloaders: Enumerates all downloader's identifiers and names, MangaCon will call this method in settings dialog.
  • GetDownloader: Get the specified downloader.

Downloader Interface

class Downloader
{
public:
    virtual void WINAPI ClearTasks(void) = 0;
    virtual DownloadTask* WINAPI NewTask(Manga *pManga, PCWSTR pwzVol, PCSTR pszVolURL) = 0;
    virtual void WINAPI CommitTasks(void) = 0;
    virtual void WINAPI SetActive(bool bActive) { /* Nothing */ }
};

Downloader is the interface of downloader, it is implemented by the component.

Methods

  • ClearTasks: Clear all existing tasks.
  • NewTask: Create a new task for a new volume.
  • CommitTasks: Commit all existing tasks, and start downloader.
  • SetActive: Enable/Disable the downloader.

DownloadTask Interface

class DownloadTask
{
public:
    virtual void WINAPI AddImageURL(PCSTR pszURL, PCSTR pszRef) = 0;
    virtual void WINAPI SetCookies(PCSTR pszCookies) = 0;
    virtual void WINAPI SetHeaders(PCSTR pszHeaders) { /* Nothing */ }
    virtual void WINAPI Done(void) = 0;
};

DownloadTask is the interface of download task, it is implemented by the component.

Methods

  • AddImageURL: Add a URL for an image.
  • SetCookies: Set the cookies for current task.
  • SetHeaders: Set the extra HTTP headers for current task.
  • Done: All images are added.

Manga Interface

class Manga
{
public:
    enum InfoType {
        URL = 0,
        RawContent,
        Name,
        Author,
        Cover,
        Intro,
        Category,
        MAX
    };
    virtual bool WINAPI GetInfo(int nInfo, MemObject *pDst) const = 0;
    virtual bool WINAPI GetFinishStatus(bool *bFinished) const = 0;
};

Manga is the interface of manga object, it is implemented by MangaCon.

Methods

  • GetInfo: Get the specified information for the manga.
  • GetFinishStatus: Get if the manga is finished.

Pseudo Code

And here is some pseudo code to show how to call downloader component in MangaCon.

Downloader *dl = CurrentDownloader();
 
for (size_t i = 0; i < m_Tasks.size(); ++i) {
    const TaskItem &ti = m_Tasks.at(i);
    DownloadTask *t = dl->NewTask(GetMangaObject(i), ti.m_wsName.c_str(), ti.m_strURL.c_str());
    if (NULL == t)
        break;
 
    if (!ti.Cookie.empty())
        t->SetCookies(ti.Cookie.c_str());
    if (!ti.Headers.empty())
        t->SetHeaders(ti.Headers.c_str());
 
    for (size_t j = 0; j < ti.Images.size(); ++j) {
        const ImageItem& ii = ti.Images.at(j);
        t->AddImageURL(ii.m_strURL.c_str(), ii.m_strRef.c_str());
    }
    t->Done();
}
 
dl->CommitTasks();
最后更改: 2013-10-09 01:39 由 李马

页面工具