1
uploader_tools/domains/fetcher/v1/exported.go

80 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// NNM-Club torrent filess mass downloader
// Created for Uploaders group
// Copyright (c) 2012-2019 Vladimir "fat0troll" Hodakov
package fetcherv1
import (
"net/http"
"github.com/PuerkitoBio/goquery"
"github.com/rs/zerolog"
"gitlab.com/pztrn/flagger"
"gitlab.com/fat0troll/uploader_tools/internal/context"
)
var (
c *context.Context
dclient http.Client
dlog zerolog.Logger
forumPages map[int]*goquery.Document
forumPagesLinks map[string]string
forumTopics map[int]*forumTopic
forumTopicInProgress int
outputDirPath string
totalLength int64
uberDebug bool
)
// New initializes package
func New(cc *context.Context) {
c = cc
dlog = c.Logger.With().Str("модуль", "fetcher").Int("версия", 1).Logger()
_ = c.Flagger.AddFlag(&flagger.Flag{
Name: "forum",
Description: "Номер форума, торренты с которого нужно скачать",
Type: "int",
DefaultValue: 0,
})
_ = c.Flagger.AddFlag(&flagger.Flag{
Name: "fetcherDebug",
Description: "Запустить модуль fetcher в дебаг-режиме",
Type: "bool",
DefaultValue: false,
})
_ = c.Flagger.AddFlag(&flagger.Flag{
Name: "outputDir",
Description: "Директория, в которую будут помещены скачанные торрент-файлы",
Type: "string",
DefaultValue: "./",
})
forumPages = make(map[int]*goquery.Document)
forumPagesLinks = make(map[string]string)
forumTopics = make(map[int]*forumTopic)
dlog.Info().Msg("Модуль инициализирован")
}
// Process handles authorization
func Process() {
uberDebug, _ = c.Flagger.GetBoolValue("fetcherDebug")
forumID, _ := c.Flagger.GetIntValue("forum")
if forumID == 0 {
dlog.Fatal().Msg("Номер форума не указан. Используйте ключ -forum XXX, чтобы указать номер форума")
}
outputDirPathPrefix, _ := c.Flagger.GetStringValue("outputDir")
dlog.Info().Int("forum ID", forumID).Msg("Получен ID форума, начинаем работу...")
createOutputDir(outputDirPathPrefix, forumID)
fetch(forumID)
printStats()
}