Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTipo01 committed Nov 20, 2022
0 parents commit b3caaa9
Show file tree
Hide file tree
Showing 13 changed files with 1,421 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Code Scanning - Action"

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
CodeQL-Build:
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
runs-on: ubuntu-latest

permissions:
# required for all workflows
security-events: write

# only required for workflows in private repositories
actions: read
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
# Override language selection by uncommenting this and choosing your languages
with:
languages: go

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# ✏️ If the Autobuild fails above, remove it and uncomment the following
# three lines and modify them (or add more) to build your code if your
# project uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: goreleaser

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19.3
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164 changes: 164 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Created by https://www.toptal.com/developers/gitignore/api/go,jetbrains+all,linux,windows
# Edit at https://www.toptal.com/developers/gitignore?templates=go,jetbrains+all,linux,windows

### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

### Go Patch ###
/vendor/
/Godeps/

### JetBrains+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### JetBrains+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

.idea/*

!.idea/codeStyles
!.idea/runConfigurations

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/go,jetbrains+all,linux,windows

config.yml
videoDownloader
temp/
38 changes: 38 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
before:
hooks:
- go mod download
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- windows
- linux
- darwin
goarch:
- amd64
- 386
- arm
- arm64
archives:
- format: zip
replacements:
'386': i386
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
files:
- README.md
- LICENSE
- example_config.yml
checksum:
name_template: checksums.txt
snapshot:
name_template: '{{ .Tag }}-next'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Manuel Raimo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# videoDownloader

[![Go Report Card](https://goreportcard.com/badge/github.com/TheTipo01/videoDownloader)](https://goreportcard.com/report/github.com/TheTipo01/videoDownloader)

This telegram bot downloads videos from the configured sites and sends them back in the chat.
It also supports inline queries.

## Installation
Just grab the latest release from the [releases page](https://github.com/TheTipo01/videoDownloader/releases/), modify the included `example_config.yml` file, rename it to `config.yml` and run the bot.

Make sure to have ffmpeg and yt-dlp installed and in your PATH.
74 changes: 74 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"github.com/bwmarrin/lit"
tele "gopkg.in/telebot.v3"
"strings"
)

func videoDownload(c tele.Context) error {
for _, t := range strings.Split(c.Text(), " ") {
if isValidURL(t) && contains(t, cfg.URLs) {
filename := downloadVideo(t)
err := c.Reply(c.Message(), &tele.Video{File: tele.FromURL(cfg.Host + filename), FileName: filename, MIME: "video/mp4"})
if err != nil {
lit.Error(err.Error())
}
}
}

return nil
}

// For twitter we send the same url with only fx appended to it
func twitterReplacer(c tele.Context) error {
for _, t := range strings.Split(c.Text(), " ") {
if isValidURL(t) && strings.HasPrefix(t, "https://twitter.com") {
err := c.Reply(c.Message(), strings.Replace(t, "https://twitter.com", "https://fxtwitter.com", 1))
if err != nil {
lit.Error(err.Error())
}
}
}

return nil
}

func inlineQuery(c tele.Context) error {
var (
results = make([]tele.Result, 1)
text = c.Query().Text
)

if isValidURL(text) && contains(text, cfg.URLs) {
fileName := downloadVideo(text)

// Create result
results[0] = &tele.VideoResult{
URL: cfg.Host + fileName,
Title: "Send video",
MIME: "video/mp4",
ThumbURL: cfg.Host + "icon.jpg",
}

results[0].SetResultID(fileName)

// Send video
return c.Answer(&tele.QueryResponse{
Results: results,
CacheTime: 86400, // one day
})
} else {
results[0] = &tele.ArticleResult{
Title: "Not a valid instagram URL!",
}

results[0].SetResultID(text)

// Send error
return c.Answer(&tele.QueryResponse{
Results: results,
CacheTime: 86400, // one day
})
}
}
Loading

0 comments on commit b3caaa9

Please sign in to comment.