Compare commits
4 commits
dff20d26ca
...
92191d0b74
Author | SHA1 | Date | |
---|---|---|---|
92191d0b74 | |||
a3ec00fdda | |||
18a9c5a465 | |||
46d587d685 |
6 changed files with 106 additions and 3 deletions
|
@ -13,3 +13,17 @@ pipeline:
|
|||
- echo $REGISTRY_SECRET | apko login --username Nulo --password-stdin gitea.nulo.in
|
||||
- apko publish --debug --arch x86_64 --repository-append "$(pwd)/packages" --keyring-append melange.rsa.pub apko.yaml gitea.nulo.in/nulo/dlbot4:latest
|
||||
secrets: [REGISTRY_SECRET]
|
||||
|
||||
telegram-bot-api:
|
||||
image: docker.io/woodpeckerci/plugin-docker-buildx
|
||||
settings:
|
||||
repo: gitea.nulo.in/Nulo/dlbot4/telegram-bot-api
|
||||
context: ./telegram-bot-api-container
|
||||
registry: https://gitea.nulo.in
|
||||
username: Nulo
|
||||
password:
|
||||
from_secret: registry_secret
|
||||
secrets: [REGISTRY_SECRET]
|
||||
when:
|
||||
branch: "antifascista"
|
||||
event: "push"
|
||||
|
|
|
@ -11,3 +11,12 @@ tasks:
|
|||
- ssh -p993 root@nulo.in sv stop dlbot
|
||||
- scp -P993 dlbot dlbot@nulo.in:/home/dlbot/bin/
|
||||
- ssh -p993 root@nulo.in sv start dlbot
|
||||
ko:
|
||||
cmds:
|
||||
- podman run --rm -it
|
||||
-v ~/.docker/:/docker-config:Z,ro
|
||||
-v $PWD:/work:Z
|
||||
--workdir=/work
|
||||
-e KO_DOCKER_REPO=gitea.nulo.in/nulo/dlbot4
|
||||
-e DOCKER_CONFIG=/docker-config
|
||||
cgr.dev/chainguard/ko build --bare .
|
||||
|
|
|
@ -26,6 +26,9 @@ func (r *Instagram) Respond(url *url.URL) (*common.Uploadable, common.Error) {
|
|||
lookup, err := r.lookup(url.String())
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
if strings.Index(url.Path, "/p/") != 0 {
|
||||
return nil, common.NotValid
|
||||
}
|
||||
return nil, common.HadError
|
||||
}
|
||||
|
||||
|
|
21
main.go
21
main.go
|
@ -29,10 +29,10 @@ func (fu FileURL) NeedsUpload() bool {
|
|||
func (fu FileURL) UploadData() (string, io.Reader, error) {
|
||||
res, err := http.Get(string(fu))
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
return "", nil, errors.Join(errors.New("error while uploading FileURL"), err)
|
||||
}
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return "", nil, errors.New(res.Status)
|
||||
return "", nil, errors.New("error while uploading FileURL: " + res.Status)
|
||||
}
|
||||
return "url.mp4", res.Body, nil
|
||||
}
|
||||
|
@ -142,7 +142,15 @@ func main() {
|
|||
debug = true
|
||||
}
|
||||
|
||||
bot, err := tgbotapi.NewBotAPI(token)
|
||||
apiEndpoint := os.Getenv("TELEGRAM_API_ENDPOINT")
|
||||
var bot *tgbotapi.BotAPI
|
||||
var err error
|
||||
if apiEndpoint == "" {
|
||||
bot, err = tgbotapi.NewBotAPI(token)
|
||||
} else {
|
||||
log.Printf("Setting endpoint to %s", apiEndpoint)
|
||||
bot, err = tgbotapi.NewBotAPIWithAPIEndpoint(token, apiEndpoint)
|
||||
}
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
@ -151,6 +159,13 @@ func main() {
|
|||
|
||||
log.Printf("Authorized on account %s", bot.Self.UserName)
|
||||
|
||||
if len(os.Args) > 1 && os.Args[1] == "logout" {
|
||||
logout := tgbotapi.LogOutConfig{}
|
||||
bot.Send(logout)
|
||||
log.Println("Logged out.")
|
||||
return
|
||||
}
|
||||
|
||||
u := tgbotapi.NewUpdate(0)
|
||||
u.Timeout = 60
|
||||
|
||||
|
|
29
readme.md
29
readme.md
|
@ -7,3 +7,32 @@ Un bot para Telegram que permite descargar videos de distintos lugares.
|
|||
## TikTok
|
||||
|
||||
Previamente este bot descargaba directo de TikTok a través de distintas APIs internas, usando programas externos como yt-dlp. Lamentablemente TikTok seguía parcheando estas APIs internas, que hacía mantener un sideproject molesto. Por suerte, encontré [TikMate](https://tikmate.app) que es un sitio que los descarga por vos. Asumo que tiene desarrollador(es?) que mantienen el sitio. Así, uso su API interna (muy simple) y listo.
|
||||
|
||||
## Correr tu propio servidor de bot
|
||||
|
||||
El servidor de bots de Telegram por defecto (`https://api.telegram.org`) tiene un limite de subida de 50MB, y tenés que usar tu [propio servidor](https://github.com/tdlib/telegram-bot-api) para poder subir hasta 2000MB.
|
||||
|
||||
En ./telegram-bot-api-container hay un Containerfile para hostear este servidor.
|
||||
|
||||
Cuando ya tengas tu propio servidor, empezá deslogeandote del oficial (no vas a poder volver a logearte por 10 minutos):
|
||||
|
||||
```
|
||||
dlbot logout
|
||||
```
|
||||
|
||||
Después, tenés que reiniciar dlbot con el endpoint especificado con este formato: `$endpoint/bot%s/%s"`. Un ejemplo en docker-compose:
|
||||
|
||||
```
|
||||
dlbot:
|
||||
image: gitea.nulo.in/nulo/dlbot4
|
||||
environment:
|
||||
TELEGRAM_TOKEN: "${DLBOT_TELEGRAM_TOKEN}"
|
||||
TELEGRAM_API_ENDPOINT: http://dlbot-telegram-bot-api:8081/bot%s/%s
|
||||
links:
|
||||
- dlbot-telegram-bot-api
|
||||
dlbot-telegram-bot-api:
|
||||
image: gitea.nulo.in/nulo/dlbot4/telegram-bot-api
|
||||
entrypoint: ["telegram-bot-api", "--api-id=$DLBOT_TELEGRAM_API_ID", "--api-hash=$DLBOT_TELEGRAM_API_HASH", "--local"]
|
||||
```
|
||||
|
||||
Podés ver como está hecho en producción [en la repo de infra](https://gitea.nulo.in/Nulo/infra/commit/1067c632d203f7b7304fabd7bc4e818eb9d90386).
|
||||
|
|
33
telegram-bot-api-container/Containerfile
Normal file
33
telegram-bot-api-container/Containerfile
Normal file
|
@ -0,0 +1,33 @@
|
|||
FROM docker.io/alpine:3.18 AS build
|
||||
|
||||
RUN apk add --no-cache \
|
||||
make cmake \
|
||||
g++ \
|
||||
gperf \
|
||||
linux-headers openssl-dev \
|
||||
zlib-dev \
|
||||
git
|
||||
|
||||
RUN git clone --recursive https://github.com/tdlib/telegram-bot-api.git && \
|
||||
cd telegram-bot-api/ && \
|
||||
mkdir build && \
|
||||
cd build
|
||||
|
||||
WORKDIR telegram-bot-api/build
|
||||
|
||||
RUN cmake .. -DCMAKE_BUILD_TYPE=Release \
|
||||
&& cmake --build . --target install
|
||||
|
||||
FROM docker.io/alpine:3.18
|
||||
ENV TZ=America/Argentina/Buenos_Aires
|
||||
|
||||
RUN apk add --no-cache \
|
||||
openssl \
|
||||
zlib \
|
||||
libstdc++
|
||||
|
||||
COPY --from=build /usr/local/bin/telegram-bot-api /usr/local/bin/telegram-bot-api
|
||||
|
||||
ENTRYPOINT telegram-bot-api
|
||||
|
||||
EXPOSE 8081
|
Reference in a new issue