80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
// NNM-Club torrent files mass downloader
|
||
// Created for Uploaders group
|
||
// Copyright (c) 2012-2022 Vladimir "fat0troll" Hodakov
|
||
|
||
package fetcher
|
||
|
||
import (
|
||
"net/http"
|
||
|
||
"github.com/PuerkitoBio/goquery"
|
||
"github.com/rs/zerolog"
|
||
"gitlab.com/pztrn/flagger"
|
||
|
||
"lab.hodakov.me/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()
|
||
}
|