Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

musahi0128/teldrive-upload.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

teldrive-upload.sh

An alternative to Teldrive Upload

This script upload files via api call to a locally running telegram-bot-api so it should upload faster than uploading directly to telegram api server.

Archival notice

This code is no longer works with updated version of teldrive

Prerequisite

  1. Run telegram-bot-api locally
docker run -p 8081:8081 ghcr.io/bots-house/docker-telegram-bot-api:latest --local --api-id="$API_ID" --api-hash="$API_HASH" --max-webhook-connections=100000 --verbosity=2

Read this to get your API_ID and API_HASH

  1. Install required package
sudo apt-get update
sudo apt-get install postgresql-client parallel
  1. Adjust variables inside the script
TG_API_SERVER="http://localhost:8081"
TG_BOT_TOKEN="${2:-xxx:abcd}" # xxx:abcd being your bot token
TG_CHAT_ID="-1001234" # see notes
MAX_PART_SIZE=2097152000 # 2GB in bytes
DB_CONNECTION_STRING="postgres://username:password@host:port/database" # use the same as Teldrive
TELDRIVE_USER_ID="12345" # see notes
TELDRIVE_PARENT_ID="1a2b3c4d" # see notes
LOG_FILE="upload.sh.log"

Note: run following SQL statement on your Teldrive database to get TG_CHAT_ID (channel_id), TELDRIVE_USER_ID (user_id) and TELDRIVE_PARENT_ID (parent_id). This will help you get the values needed to upload to the root directory. Make sure you have at least one file in the root directory.

SELECT distinct concat(-100, channel_id), user_id, parent_id FROM files WHERE TYPE = 'file' and parent_id = (SELECT id FROM files WHERE parent_id = 'root')

Usage

  • Upload single file

    teldrive-upload.sh '/path/to/file'
    
  • Upload multiple file within a directory recursively. The directory structure WILL NOT be perserved

    find /path/to/directory -type f | parallel -j 4 teldrive-upload.sh "{}"
    
  • If you supply TG_BOT_TOKEN as the second argument to the script, it will be used instead of the one you specify inside the script. You can use it to upload using multiple bot token to avoid getting a failed upload.

    Example: command.txt

    teldrive-upload.sh '/path/to/file1' BOT:TOKEN1
    teldrive-upload.sh '/path/to/file2' BOT:TOKEN2
    teldrive-upload.sh '/path/to/file3' BOT:TOKEN3
    teldrive-upload.sh '/path/to/file4' BOT:TOKEN4
    

    Run it like this

    cat command.txt | parallel -j 4 {}
    

Tested on Ubuntu 22.04.2 LTS running on Google Colab

Thanks to @divyam234 for his creation of Teldrive.

Join Discord channel for Teldrive here.

About

teldrive-upload.sh

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages