Coder Social home page Coder Social logo

voltflake / video-bot Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 2.16 MB

Discord bot which replies with content to TikTok, Instagram and YouTube links

License: MIT License

TypeScript 100.00%
tiktok discord-js instagram discordbot ffmpeg nodejs instagram-reels youtube youtube-shorts

video-bot's Introduction

Open-Source Discord Bot that replies to links with content

This README.md is outdated. It will be changed soon.

Currently works fine with Instagram✅ / TikTok✅ / Youtube✅

🤝 If you encountered a problem or want some help feel free to sumbit an issue. Feedback is appriciated!

2023 September Update

  • Added support for instagram posts with multiple items
  • YouTube videos are now beeing sent to channel by default but only if they fit into 25MB Discord limit
  • Improved processing speed when requesting multiple links in one message
  • Improved logging when compressing videos
  • Improved error reporting in channel

Features✨

  • Lets everyone view the video directly in Discord
  • Sends videos as reply to original message
  • Supports multiple links in one message
  • No TikTok watermark on videos
  • Can be hosted on Raspberry Pi (read Raspberry Pi section)
  • Settings wizzard is built into bot
  • Also supports Instagram and YouTube links with some additional setup

Known issues⚠️

  • Photo tiktoks may be stretched too much if different image sizes used
  • When sending too many atttachments to discord at the same time, some replies may repeat (Discord.JS issue?)
  • Videos which are saved onto disk to be compressed later and compression results are not automatically deleted from /logs for debugging and statistic purposes. Uncomment two lines with unlink() function in video_compression.ts to delete them automatically when they're no longer needed
  • (Unverified) When processing multiple instagram links at the same time instagram.com may reject some requests
  • Bot threats Private/Unavailable content as backend errors. (post from private Instagram profile or removed youtube video for example)

Installation

  1. Make sure recent version of node.js and npm is installed on your system
  2. Build bot with these commands
cd ~
git clone https://github.com/voltflake/video-bot
cd video-bot
npm install
npx tsc
  1. Now you can start this bot
node .

Getting Raspberry Pi to work

Required to run

Instalation should be pretty straighfoward.
Download Node Version Manager
Install Node with nvm (v18.16.1 should work fine on raspbian buster, newer may fail)

nvm install --lts node

Follow above instalation instructions

Support Instagram links

Install python3 and python3-pip

sudo apt install python3 python3-pip

Install gallery-dl python package

pip3 install gallery-dl

Update PATH variable if you get a warning that script is not in PATH

PATH=$PATH:/home/pi/.local/bin

Log into instagram.com from your browser and exctract cookies.txt from it.
Place cookies.txt into video-bot folder and Instagram feature should work fine.

Support YouTube links

Install python3 and python3-pip

sudo apt install python3 python3-pip

Install yt-dlp python package

pip3 install yt-dlp

Update PATH variable if you get a warning that script is not in PATH

PATH=$PATH:/home/pi/.local/bin

Support hardware accelerated video compression

Make sure your OS is Raspbian Buster also known as Raspbian Legacy,
h264_omx hardware encoder doesn't work on newer Raspbian Bulseye on my 3A+ board.
Install ffmpeg

sudo apt install ffmpeg

Run bot on system startup (systemd service)

  1. Create service file
sudo nano /etc/systemd/system/video-bot.service
  1. Fill in the file (working example)
[Unit]
Description=Discord Bot for easier video viewing
After=network.target

[Service]
Environment=PATH=/home/pi/.local/bin:/home/pi/.nvm/versions/node/v18.16.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games
Type=simple
User=pi
WorkingDirectory=/home/pi/video-bot
ExecStart=/home/pi/video-bot/start.sh

[Install]
WantedBy=multi-user.target
  1. Create start.sh file in project directory
sudo nano /home/pi/video-bot/start.sh
  1. Fill in the file
#!/bin/sh
node .
  1. Make start.sh executable
chmod +x /home/pi/video-bot/start.sh

Explanation of settings.json

  • token - Discord bot token to use.
  • embeded_mode - always send videos using URL message in Discord, may have not cleanest look but works realy fast if you have slow internet.
  • enable_compression - setting which enables compression for videos bigger than 8MB so they can be sent as single video file to discord, without links. If compression is disabled videos will be sent as embeded link and can expire after a week or so.
  • codec - specifies which video codec ffmpeg will use during compression. You can specify this as "omx_h264" on raspberry pi to use hardware accelerated encoding. By default uses "h264".

video-bot's People

Contributors

voltflake avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

video-bot's Issues

It does not work

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined
at new NodeError (node:internal/errors:387:5)
at validateString (node:internal/validators:121:11)
at Url.parse (node:url:168:3)
at Object.urlParse [as parse] (node:url:155:13)
at dispatchHttpRequest (/home/.algo/tiktok-to-discord/node_modules/axios/lib/adapters/http.js:124:22)
at new Promise ()
at httpAdapter (/home/.algo/tiktok-to-discord/node_modules/axios/lib/adapters/http.js:48:10)
at dispatchRequest (/home/.algo/tiktok-to-discord/node_modules/axios/lib/core/dispatchRequest.js:58:10)
at Axios.request (/home/.algo/tiktok-to-discord/node_modules/axios/lib/core/Axios.js:108:15)
at Axios. [as get] (/home/.algo/tiktok-to-discord/node_modules/axios/lib/core/Axios.js:129:17) {
code: 'ERR_INVALID_ARG_TYPE'
}

npx tsc error also their is no settings.json or config.json

`npx tsc
src/main.ts:37:27 - error TS2339: Property 'sendTyping' does not exist on type 'DMChannel | PartialDMChannel | NewsChannel | StageChannel | TextChannel | PrivateThreadChannel | PublicThreadChannel<...> | VoiceChannel'.
Property 'sendTyping' does not exist on type 'StageChannel'.

37 await message.channel.sendTyping();
~~~~~~~~~~

src/main.ts:39:29 - error TS2339: Property 'sendTyping' does not exist on type 'DMChannel | PartialDMChannel | NewsChannel | StageChannel | TextChannel | PrivateThreadChannel | PublicThreadChannel<...> | VoiceChannel'.
Property 'sendTyping' does not exist on type 'StageChannel'.

39 await message.channel.sendTyping();
~~~~~~~~~~

Found 2 errors in the same file, starting at: src/main.ts:37
`

gallery-dl cookies

Error when getting video data: Can't extract video from instagram url after 3 tries: Error #1: extracting raw video failed: gallery-dl error, check cookies Error #2: extracting raw video failed: gallery-dl error, check cookies Error #3: extracting raw video failed: gallery-dl error, check cookies

*only for instagram urls

*hosting on Aws EC2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.