%global _empty_manifest_terminate_build 0 Name: python-tgchizu Version: 1.5.5 Release: 1 Summary: A Telegram Bot written in Python language to mirror files on the internet to Google Drive License: GNU General Public License v3 (GPLv3) URL: https://github.com/reaitten/tgchizu Source0: https://mirrors.aliyun.com/pypi/web/packages/54/12/31775ebc507936249bc7a650b18e1e9b9dd073290dec5349c905ac3fa596/tgchizu-1.5.5.tar.gz BuildArch: noarch Requires: python3-requests Requires: python3-psutil Requires: python3-bs4 Requires: python3-appdirs Requires: python3-telegram-bot Requires: python3-Pillow Requires: python3-google-api-python-client Requires: python3-google-auth-httplib2 Requires: python3-google-auth-oauthlib Requires: python3-aria2p Requires: python3-dotenv Requires: python3-tenacity Requires: python3-magic Requires: python3-beautifulsoup4 Requires: python3-Pyrogram Requires: python3-TgCrypto Requires: python3-youtube-dl Requires: python3-feedparser Requires: python3-natsort Requires: python3-heroku3 Requires: python3-aiohttp Requires: python3-speedtest-cli Requires: python3-messages Requires: python3-js2py Requires: python3-lxml Requires: python3-telegraph Requires: python3-pytz Requires: python3-megasdkrestclient %description # Description: A Telegram Bot written in Python language to mirror files on the internet to Google Drive # Credits: - This repository is a fork-clone of the following repositories. > [ksssomesh's tg-mirror-bot](https://github.com/ksssomesh12/tg-mirror-bot) > [lzzy12's python-aria-mirror-bot](https://github.com/lzzy12/python-aria-mirror-bot) > [afdulfauzan's python-aria-mirror-bot](https://github.com/afdulfauzan/python-aria-mirror-bot) > [magneto261290's magneto-python-aria](https://github.com/magneto261290/magneto-python-aria) > [breakdowns's slam-mirrorbot](https://github.com/breakdowns/slam-mirrorbot) All credits goes to the maintainers of the above repositories. - Few useful additional features have been implemented on top of them. - This repository utilises trackers for torrent/magnet downloads from [Trackerslist Website](https://trackerslist.com). # Supported Features: ## From Source Repos - Mirror Torrents - Mirror Direct Links - Mirror Telegram Files - Upload Files after Archiving/Unarchiving - Download and Upload Progress, Speeds and ETAs - Docker Support - Uploading To Team Drives - Index Link Support - Shortener Support - Service Account Support - Mirror 'youtube-dl' Supported Links ## Additional Features - Dynamic Config Support, to facilitate easier and streamlined experience for editing config files. - Sync Config Files at every /restart command. - Edit values of environment variables in 'config.env' from within the bot using InlineKeyboardButtons. - 'aria2c' daemon starts as a subprocess from within the 'bot' python module, facilitating better handling of processes. This also results in both 'aria2c' daemon and the 'bot' python module restarting with every '/restart' command. - Support for using custom tracker list formatted as a text file, as required by 'aria2c' daemon. ## Supported Archive File Types ``` ZIP RAR TAR 7Z ISO WIM CAB GZIP BZIP2 APM ARJ CHM CPIO CramFS DEB DMG FAT HFS LZH LZMA LZMA2 MBR MSI MSLZ NSIS NTFS RPM SquashFS UDF VHD XAR Z ``` # Development Status: ## To-Dos - Add option to select files for torrent/magnet downloads. **NOTE:** All the above to-dos are aimed at achieving zero human-intervention after initial deploy to Heroku. ## Info of Branches - **master** : most stable environment for production deploys. - **staging** : testing new features, fixes or better implementations of already existing ones. - **dev** : major feature updates that are under development - currently, added support for 'mega-dl'. # Deploying: ## Prerequisites - Install Python3. ``` sudo apt install python3 ``` ## Cloning and Setting Up Config File - Download and Extract the [Latest Release Package](https://github.com/ksssomesh12/tg-mirror-bot/releases): ``` mkdir ~/Downloads/deploy_heroku mv ~/Downloads/deploy_release_v* ~/Downloads/deploy_heroku cd ~/Downloads/deploy_heroku tar xzvf deploy_release_v* rm -v deploy_release_v* ``` - Copy and Edit the Config file: ``` cp config_sample.env config.env nano config.env ``` - Remove the first line saying: ``` _____REMOVE_THIS_LINE_____=True ``` Fill up rest of the fields. The description of each field is given below. ### Required Fields - **BOT_TOKEN** : The telegram bot token that you get from [@BotFather](https://t.me/botfather). - **GDRIVE_FOLDER_ID** : This is the folder ID of the Google Drive folder to which you want to upload all the mirrors. - **DOWNLOAD_DIR** : The path to the folder where the downloads will be downloaded locally, before uploading to Google Drive. - **OWNER_ID** : The Telegram user ID (not username) of the owner of the bot. - **DOWNLOAD_STATUS_UPDATE_INTERVAL** : A short interval of time in seconds after which the Mirror progress message is updated (5 seconds at least). - **AUTO_DELETE_MESSAGE_DURATION** : Interval of time (in seconds), after which the bot deletes its message (and command message) which is expected to be viewed instantly (set to '-1' to never automatically delete messages). - **TELEGRAM_API** : This is to authenticate to your telegram account for downloading Telegram files. You can get this from [here](https://my.telegram.org). - **TELEGRAM_HASH** : This is to authenticate to your telegram account for downloading Telegram files. You can get this from [here](https://my.telegram.org). - **MAX_DOWNLOAD_SPEED** : Set the maximum download speed. By default, it is set to '0' (unlimited). - **MAX_CONCURRENT_DOWNLOADS** : Set the maximum concurrent downloads. By default, it is set to '3'. - **TRACKERSLIST** : Set the URL of the trackerslist text file. By default, it is set to 'https://trackerslist.com/all_aria2.txt'. - **USE_TELEGRAPH** : Set to "true" to use Telegra.ph for search results from '/list' bot command, or else set to "false". **NOTE:** The trackerslist text file must contain tracker URLs in a single line, separated by commas, as required by 'aria2c'. ### Optional Fields (leave empty if unsure) - **IS_TEAM_DRIVE** : Set to "true" if GDRIVE_FOLDER_ID is from a Team Drive, or else set to "false" or leave it empty. - **USE_SERVICE_ACCOUNTS** : Whether to use service accounts or not. For this to work see "Using service accounts" section below. - **STOP_DUPLICATE_MIRROR** : Set this to "true", if you want to check for duplicate files (using file name, and not file hash) in Google Drive matching the requested download and stop the download if found any. - **INDEX_URL** : Refer to [GDIndex repo](https://github.com/maple3142/GDIndex/). The URL should not have any trailing '/'. - **SHORTENER** : URL of the Shortener. - **SHORTENER_API** : API Key of the Shortener. Supported Shorteners: > exe.io > gplinks.io > shrinkme.io > urlshortx.com > shortzon.com Additionally, some other shorteners are also supported unofficially. ## Getting Google OAuth API Credential File - Visit the [Google Cloud Console](https://console.developers.google.com/apis/credentials). - Go to the OAuth Consent tab, fill it, and save. - Go to the Credentials tab and click Create Credentials -> OAuth Client ID. - Choose Other and Create. - Use the download button to download your credentials. - Move the downloaded file to the 'deploy_heroku' folder, and rename it to 'credentials.json'. - Visit [Google API Library](https://console.developers.google.com/apis/library). - Search for Drive and enable it if it is disabled. ## Setup - Install Requirements: ``` pip3 install -r requirements.txt ``` - Use 'pipenv' for better compatibility (optional): ``` pipenv install -r requirements.txt pipenv shell ``` - Run 'setup.py', and authorize the AppFlow to generate 'token.pickle': ``` python3 setup.py ``` - Enter the appropriate choice in the input prompt, to use static/dynamic config. In case of static config, the setup is complete here. In case of dynamic config, continue to the next section. ### Dynamic Config (optional) - If you are running this setup script for the first time, enter the appropriate choice in the input prompt and continue to the next step. - Create a new folder in your personal Google Drive, irrespective of the folder you use for uploading files with this bot (no constraints at all). - Change the permissions of this newly created folder to 'Anyone on the Internet with this link can view'. - Enter the FolderId of the newly created folder in the input prompt, and continue with the setup. - For 'DL_WAIT_TIME' reference, see below: > **DL_WAIT_TIME** : Time to wait for aria2c to download the config files. By default it's set to '5' seconds, which is more than enough for deploying the bot to Heroku. If 'DL_WAIT_TIME' lapses, and the config files are not downloaded due to any reason, the bot exits with exit code (1). - The config files will be uploaded to Google Drive, and then deleted, except for 'dynamic.env'. - The setup script will exit with 'Setup Completed' message. - Now, the docker image can be deployed with 'dynamic.env' file. **NOTE:** If you have already run this setup script and want to update the existing config files in drive, enter the appropriate choice in the input prompt. In the next step, enter the FileId of the existing 'dynamic.env' in the input prompt, and the updated files will be uploaded to Google Drive. Now, you can choose to keep the old config files or delete them. # Deploy to Heroku: ## Creating a Heroku App - Create a [free Heroku Account](https://id.heroku.com/signup/login). - Install Heroku CLI: ``` sudo snap install --classic heroku ``` - Login into your Heroku Account: ``` heroku login ``` - Visit [Heroku Dashboard](https://dashboard.heroku.com) and create a new app with any name (for our reference, your-mirror-bot) and with any region you prefer, for your app to be served from. - In the Deploy tab of your app dashboard, select 'Heroku Git' in Deployment Method. - Change the Stack for the App using Heroku CLI: ``` heroku stack:set container --app your-mirror-bot ``` - Initialise the project files as a Git Repository, push the Repo to 'Heroku Git' and build the Docker Image: ``` cd ~/Downloads/deploy_heroku git init git add . git commit -m "initial commit" heroku git:remote --app your-mirror-bot git push heroku master ``` - If the Docker Image Build succeeds, then, your push to the remote repository will succeed, otherwise, your push to the remote repository is rejected as the Docker Image Build fails. ## Run/Terminate the App You can run/terminate the app by allocating/deallocating dynos to the app. ### Using Dashboard - In the app dashboard, under resources tab, use the 'Edit Dyno Formation' button in Dynos section to change the working state of the app. ### Using CLI - To Run: ``` heroku ps:scale worker=1 --app your-mirror-bot ``` - To Terminate: ``` heroku ps:scale worker=0 --app your-mirror-bot ``` - To Check Status: ``` heroku ps --app your-mirror-bot ``` - To Tail App Logs: ``` heroku logs --tail --app your-mirror-bot ``` # Bot Commands: - **start** - Start the bot - **mirror** - Mirror the provided link to Google Drive - **unzipmirror** - Mirror the provided link and if the file is in archive format, it is extracted and then uploaded to Google Drive - **tarmirror** - Mirror the provided link and upload in archive format (.tar) to Google Drive - **cancel** - Reply with this command to the source message, and the download will be cancelled - **cancelall** - Cancels all running tasks (downloads, uploads, archiving, unarchiving) - **list** - Searches the Google Drive folder for any matches with the search term and presents the search results in a Telegraph page - **status** - Shows the status of all downloads and uploads in progress - **authorize** - Authorize a group chat or, a specific user to use the bot - **unauthorize** - Unauthorize a group chat or, a specific user to use the bot - **ping** - Ping the bot - **restart** - Restart the bot - **stats** - Shows the stats of the machine that the bot is hosted on - **help** - To get the help message - **log** - Sends the log file of the bot and the log file of 'aria2c' daemon (can be used to analyse crash reports, if any) - **clone** - Clone folders in Google Drive (owned by someone else) to your Google Drive - **watch** - Mirror through 'youtube-dl' to Google Drive - **tarwatch** - Mirror through 'youtube-dl' and upload in archive format (.tar) to Google Drive - **delete** - Delete files in Google Drive matching the given string - **config** - Edit 'config.env' file **NOTE:** The above listed command descriptions can be copied and pasted in 'edit bot commands' section, when editing the bot settings with [@BotFather](https://t.me/botfather). %package -n python3-tgchizu Summary: A Telegram Bot written in Python language to mirror files on the internet to Google Drive Provides: python-tgchizu BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-tgchizu # Description: A Telegram Bot written in Python language to mirror files on the internet to Google Drive # Credits: - This repository is a fork-clone of the following repositories. > [ksssomesh's tg-mirror-bot](https://github.com/ksssomesh12/tg-mirror-bot) > [lzzy12's python-aria-mirror-bot](https://github.com/lzzy12/python-aria-mirror-bot) > [afdulfauzan's python-aria-mirror-bot](https://github.com/afdulfauzan/python-aria-mirror-bot) > [magneto261290's magneto-python-aria](https://github.com/magneto261290/magneto-python-aria) > [breakdowns's slam-mirrorbot](https://github.com/breakdowns/slam-mirrorbot) All credits goes to the maintainers of the above repositories. - Few useful additional features have been implemented on top of them. - This repository utilises trackers for torrent/magnet downloads from [Trackerslist Website](https://trackerslist.com). # Supported Features: ## From Source Repos - Mirror Torrents - Mirror Direct Links - Mirror Telegram Files - Upload Files after Archiving/Unarchiving - Download and Upload Progress, Speeds and ETAs - Docker Support - Uploading To Team Drives - Index Link Support - Shortener Support - Service Account Support - Mirror 'youtube-dl' Supported Links ## Additional Features - Dynamic Config Support, to facilitate easier and streamlined experience for editing config files. - Sync Config Files at every /restart command. - Edit values of environment variables in 'config.env' from within the bot using InlineKeyboardButtons. - 'aria2c' daemon starts as a subprocess from within the 'bot' python module, facilitating better handling of processes. This also results in both 'aria2c' daemon and the 'bot' python module restarting with every '/restart' command. - Support for using custom tracker list formatted as a text file, as required by 'aria2c' daemon. ## Supported Archive File Types ``` ZIP RAR TAR 7Z ISO WIM CAB GZIP BZIP2 APM ARJ CHM CPIO CramFS DEB DMG FAT HFS LZH LZMA LZMA2 MBR MSI MSLZ NSIS NTFS RPM SquashFS UDF VHD XAR Z ``` # Development Status: ## To-Dos - Add option to select files for torrent/magnet downloads. **NOTE:** All the above to-dos are aimed at achieving zero human-intervention after initial deploy to Heroku. ## Info of Branches - **master** : most stable environment for production deploys. - **staging** : testing new features, fixes or better implementations of already existing ones. - **dev** : major feature updates that are under development - currently, added support for 'mega-dl'. # Deploying: ## Prerequisites - Install Python3. ``` sudo apt install python3 ``` ## Cloning and Setting Up Config File - Download and Extract the [Latest Release Package](https://github.com/ksssomesh12/tg-mirror-bot/releases): ``` mkdir ~/Downloads/deploy_heroku mv ~/Downloads/deploy_release_v* ~/Downloads/deploy_heroku cd ~/Downloads/deploy_heroku tar xzvf deploy_release_v* rm -v deploy_release_v* ``` - Copy and Edit the Config file: ``` cp config_sample.env config.env nano config.env ``` - Remove the first line saying: ``` _____REMOVE_THIS_LINE_____=True ``` Fill up rest of the fields. The description of each field is given below. ### Required Fields - **BOT_TOKEN** : The telegram bot token that you get from [@BotFather](https://t.me/botfather). - **GDRIVE_FOLDER_ID** : This is the folder ID of the Google Drive folder to which you want to upload all the mirrors. - **DOWNLOAD_DIR** : The path to the folder where the downloads will be downloaded locally, before uploading to Google Drive. - **OWNER_ID** : The Telegram user ID (not username) of the owner of the bot. - **DOWNLOAD_STATUS_UPDATE_INTERVAL** : A short interval of time in seconds after which the Mirror progress message is updated (5 seconds at least). - **AUTO_DELETE_MESSAGE_DURATION** : Interval of time (in seconds), after which the bot deletes its message (and command message) which is expected to be viewed instantly (set to '-1' to never automatically delete messages). - **TELEGRAM_API** : This is to authenticate to your telegram account for downloading Telegram files. You can get this from [here](https://my.telegram.org). - **TELEGRAM_HASH** : This is to authenticate to your telegram account for downloading Telegram files. You can get this from [here](https://my.telegram.org). - **MAX_DOWNLOAD_SPEED** : Set the maximum download speed. By default, it is set to '0' (unlimited). - **MAX_CONCURRENT_DOWNLOADS** : Set the maximum concurrent downloads. By default, it is set to '3'. - **TRACKERSLIST** : Set the URL of the trackerslist text file. By default, it is set to 'https://trackerslist.com/all_aria2.txt'. - **USE_TELEGRAPH** : Set to "true" to use Telegra.ph for search results from '/list' bot command, or else set to "false". **NOTE:** The trackerslist text file must contain tracker URLs in a single line, separated by commas, as required by 'aria2c'. ### Optional Fields (leave empty if unsure) - **IS_TEAM_DRIVE** : Set to "true" if GDRIVE_FOLDER_ID is from a Team Drive, or else set to "false" or leave it empty. - **USE_SERVICE_ACCOUNTS** : Whether to use service accounts or not. For this to work see "Using service accounts" section below. - **STOP_DUPLICATE_MIRROR** : Set this to "true", if you want to check for duplicate files (using file name, and not file hash) in Google Drive matching the requested download and stop the download if found any. - **INDEX_URL** : Refer to [GDIndex repo](https://github.com/maple3142/GDIndex/). The URL should not have any trailing '/'. - **SHORTENER** : URL of the Shortener. - **SHORTENER_API** : API Key of the Shortener. Supported Shorteners: > exe.io > gplinks.io > shrinkme.io > urlshortx.com > shortzon.com Additionally, some other shorteners are also supported unofficially. ## Getting Google OAuth API Credential File - Visit the [Google Cloud Console](https://console.developers.google.com/apis/credentials). - Go to the OAuth Consent tab, fill it, and save. - Go to the Credentials tab and click Create Credentials -> OAuth Client ID. - Choose Other and Create. - Use the download button to download your credentials. - Move the downloaded file to the 'deploy_heroku' folder, and rename it to 'credentials.json'. - Visit [Google API Library](https://console.developers.google.com/apis/library). - Search for Drive and enable it if it is disabled. ## Setup - Install Requirements: ``` pip3 install -r requirements.txt ``` - Use 'pipenv' for better compatibility (optional): ``` pipenv install -r requirements.txt pipenv shell ``` - Run 'setup.py', and authorize the AppFlow to generate 'token.pickle': ``` python3 setup.py ``` - Enter the appropriate choice in the input prompt, to use static/dynamic config. In case of static config, the setup is complete here. In case of dynamic config, continue to the next section. ### Dynamic Config (optional) - If you are running this setup script for the first time, enter the appropriate choice in the input prompt and continue to the next step. - Create a new folder in your personal Google Drive, irrespective of the folder you use for uploading files with this bot (no constraints at all). - Change the permissions of this newly created folder to 'Anyone on the Internet with this link can view'. - Enter the FolderId of the newly created folder in the input prompt, and continue with the setup. - For 'DL_WAIT_TIME' reference, see below: > **DL_WAIT_TIME** : Time to wait for aria2c to download the config files. By default it's set to '5' seconds, which is more than enough for deploying the bot to Heroku. If 'DL_WAIT_TIME' lapses, and the config files are not downloaded due to any reason, the bot exits with exit code (1). - The config files will be uploaded to Google Drive, and then deleted, except for 'dynamic.env'. - The setup script will exit with 'Setup Completed' message. - Now, the docker image can be deployed with 'dynamic.env' file. **NOTE:** If you have already run this setup script and want to update the existing config files in drive, enter the appropriate choice in the input prompt. In the next step, enter the FileId of the existing 'dynamic.env' in the input prompt, and the updated files will be uploaded to Google Drive. Now, you can choose to keep the old config files or delete them. # Deploy to Heroku: ## Creating a Heroku App - Create a [free Heroku Account](https://id.heroku.com/signup/login). - Install Heroku CLI: ``` sudo snap install --classic heroku ``` - Login into your Heroku Account: ``` heroku login ``` - Visit [Heroku Dashboard](https://dashboard.heroku.com) and create a new app with any name (for our reference, your-mirror-bot) and with any region you prefer, for your app to be served from. - In the Deploy tab of your app dashboard, select 'Heroku Git' in Deployment Method. - Change the Stack for the App using Heroku CLI: ``` heroku stack:set container --app your-mirror-bot ``` - Initialise the project files as a Git Repository, push the Repo to 'Heroku Git' and build the Docker Image: ``` cd ~/Downloads/deploy_heroku git init git add . git commit -m "initial commit" heroku git:remote --app your-mirror-bot git push heroku master ``` - If the Docker Image Build succeeds, then, your push to the remote repository will succeed, otherwise, your push to the remote repository is rejected as the Docker Image Build fails. ## Run/Terminate the App You can run/terminate the app by allocating/deallocating dynos to the app. ### Using Dashboard - In the app dashboard, under resources tab, use the 'Edit Dyno Formation' button in Dynos section to change the working state of the app. ### Using CLI - To Run: ``` heroku ps:scale worker=1 --app your-mirror-bot ``` - To Terminate: ``` heroku ps:scale worker=0 --app your-mirror-bot ``` - To Check Status: ``` heroku ps --app your-mirror-bot ``` - To Tail App Logs: ``` heroku logs --tail --app your-mirror-bot ``` # Bot Commands: - **start** - Start the bot - **mirror** - Mirror the provided link to Google Drive - **unzipmirror** - Mirror the provided link and if the file is in archive format, it is extracted and then uploaded to Google Drive - **tarmirror** - Mirror the provided link and upload in archive format (.tar) to Google Drive - **cancel** - Reply with this command to the source message, and the download will be cancelled - **cancelall** - Cancels all running tasks (downloads, uploads, archiving, unarchiving) - **list** - Searches the Google Drive folder for any matches with the search term and presents the search results in a Telegraph page - **status** - Shows the status of all downloads and uploads in progress - **authorize** - Authorize a group chat or, a specific user to use the bot - **unauthorize** - Unauthorize a group chat or, a specific user to use the bot - **ping** - Ping the bot - **restart** - Restart the bot - **stats** - Shows the stats of the machine that the bot is hosted on - **help** - To get the help message - **log** - Sends the log file of the bot and the log file of 'aria2c' daemon (can be used to analyse crash reports, if any) - **clone** - Clone folders in Google Drive (owned by someone else) to your Google Drive - **watch** - Mirror through 'youtube-dl' to Google Drive - **tarwatch** - Mirror through 'youtube-dl' and upload in archive format (.tar) to Google Drive - **delete** - Delete files in Google Drive matching the given string - **config** - Edit 'config.env' file **NOTE:** The above listed command descriptions can be copied and pasted in 'edit bot commands' section, when editing the bot settings with [@BotFather](https://t.me/botfather). %package help Summary: Development documents and examples for tgchizu Provides: python3-tgchizu-doc %description help # Description: A Telegram Bot written in Python language to mirror files on the internet to Google Drive # Credits: - This repository is a fork-clone of the following repositories. > [ksssomesh's tg-mirror-bot](https://github.com/ksssomesh12/tg-mirror-bot) > [lzzy12's python-aria-mirror-bot](https://github.com/lzzy12/python-aria-mirror-bot) > [afdulfauzan's python-aria-mirror-bot](https://github.com/afdulfauzan/python-aria-mirror-bot) > [magneto261290's magneto-python-aria](https://github.com/magneto261290/magneto-python-aria) > [breakdowns's slam-mirrorbot](https://github.com/breakdowns/slam-mirrorbot) All credits goes to the maintainers of the above repositories. - Few useful additional features have been implemented on top of them. - This repository utilises trackers for torrent/magnet downloads from [Trackerslist Website](https://trackerslist.com). # Supported Features: ## From Source Repos - Mirror Torrents - Mirror Direct Links - Mirror Telegram Files - Upload Files after Archiving/Unarchiving - Download and Upload Progress, Speeds and ETAs - Docker Support - Uploading To Team Drives - Index Link Support - Shortener Support - Service Account Support - Mirror 'youtube-dl' Supported Links ## Additional Features - Dynamic Config Support, to facilitate easier and streamlined experience for editing config files. - Sync Config Files at every /restart command. - Edit values of environment variables in 'config.env' from within the bot using InlineKeyboardButtons. - 'aria2c' daemon starts as a subprocess from within the 'bot' python module, facilitating better handling of processes. This also results in both 'aria2c' daemon and the 'bot' python module restarting with every '/restart' command. - Support for using custom tracker list formatted as a text file, as required by 'aria2c' daemon. ## Supported Archive File Types ``` ZIP RAR TAR 7Z ISO WIM CAB GZIP BZIP2 APM ARJ CHM CPIO CramFS DEB DMG FAT HFS LZH LZMA LZMA2 MBR MSI MSLZ NSIS NTFS RPM SquashFS UDF VHD XAR Z ``` # Development Status: ## To-Dos - Add option to select files for torrent/magnet downloads. **NOTE:** All the above to-dos are aimed at achieving zero human-intervention after initial deploy to Heroku. ## Info of Branches - **master** : most stable environment for production deploys. - **staging** : testing new features, fixes or better implementations of already existing ones. - **dev** : major feature updates that are under development - currently, added support for 'mega-dl'. # Deploying: ## Prerequisites - Install Python3. ``` sudo apt install python3 ``` ## Cloning and Setting Up Config File - Download and Extract the [Latest Release Package](https://github.com/ksssomesh12/tg-mirror-bot/releases): ``` mkdir ~/Downloads/deploy_heroku mv ~/Downloads/deploy_release_v* ~/Downloads/deploy_heroku cd ~/Downloads/deploy_heroku tar xzvf deploy_release_v* rm -v deploy_release_v* ``` - Copy and Edit the Config file: ``` cp config_sample.env config.env nano config.env ``` - Remove the first line saying: ``` _____REMOVE_THIS_LINE_____=True ``` Fill up rest of the fields. The description of each field is given below. ### Required Fields - **BOT_TOKEN** : The telegram bot token that you get from [@BotFather](https://t.me/botfather). - **GDRIVE_FOLDER_ID** : This is the folder ID of the Google Drive folder to which you want to upload all the mirrors. - **DOWNLOAD_DIR** : The path to the folder where the downloads will be downloaded locally, before uploading to Google Drive. - **OWNER_ID** : The Telegram user ID (not username) of the owner of the bot. - **DOWNLOAD_STATUS_UPDATE_INTERVAL** : A short interval of time in seconds after which the Mirror progress message is updated (5 seconds at least). - **AUTO_DELETE_MESSAGE_DURATION** : Interval of time (in seconds), after which the bot deletes its message (and command message) which is expected to be viewed instantly (set to '-1' to never automatically delete messages). - **TELEGRAM_API** : This is to authenticate to your telegram account for downloading Telegram files. You can get this from [here](https://my.telegram.org). - **TELEGRAM_HASH** : This is to authenticate to your telegram account for downloading Telegram files. You can get this from [here](https://my.telegram.org). - **MAX_DOWNLOAD_SPEED** : Set the maximum download speed. By default, it is set to '0' (unlimited). - **MAX_CONCURRENT_DOWNLOADS** : Set the maximum concurrent downloads. By default, it is set to '3'. - **TRACKERSLIST** : Set the URL of the trackerslist text file. By default, it is set to 'https://trackerslist.com/all_aria2.txt'. - **USE_TELEGRAPH** : Set to "true" to use Telegra.ph for search results from '/list' bot command, or else set to "false". **NOTE:** The trackerslist text file must contain tracker URLs in a single line, separated by commas, as required by 'aria2c'. ### Optional Fields (leave empty if unsure) - **IS_TEAM_DRIVE** : Set to "true" if GDRIVE_FOLDER_ID is from a Team Drive, or else set to "false" or leave it empty. - **USE_SERVICE_ACCOUNTS** : Whether to use service accounts or not. For this to work see "Using service accounts" section below. - **STOP_DUPLICATE_MIRROR** : Set this to "true", if you want to check for duplicate files (using file name, and not file hash) in Google Drive matching the requested download and stop the download if found any. - **INDEX_URL** : Refer to [GDIndex repo](https://github.com/maple3142/GDIndex/). The URL should not have any trailing '/'. - **SHORTENER** : URL of the Shortener. - **SHORTENER_API** : API Key of the Shortener. Supported Shorteners: > exe.io > gplinks.io > shrinkme.io > urlshortx.com > shortzon.com Additionally, some other shorteners are also supported unofficially. ## Getting Google OAuth API Credential File - Visit the [Google Cloud Console](https://console.developers.google.com/apis/credentials). - Go to the OAuth Consent tab, fill it, and save. - Go to the Credentials tab and click Create Credentials -> OAuth Client ID. - Choose Other and Create. - Use the download button to download your credentials. - Move the downloaded file to the 'deploy_heroku' folder, and rename it to 'credentials.json'. - Visit [Google API Library](https://console.developers.google.com/apis/library). - Search for Drive and enable it if it is disabled. ## Setup - Install Requirements: ``` pip3 install -r requirements.txt ``` - Use 'pipenv' for better compatibility (optional): ``` pipenv install -r requirements.txt pipenv shell ``` - Run 'setup.py', and authorize the AppFlow to generate 'token.pickle': ``` python3 setup.py ``` - Enter the appropriate choice in the input prompt, to use static/dynamic config. In case of static config, the setup is complete here. In case of dynamic config, continue to the next section. ### Dynamic Config (optional) - If you are running this setup script for the first time, enter the appropriate choice in the input prompt and continue to the next step. - Create a new folder in your personal Google Drive, irrespective of the folder you use for uploading files with this bot (no constraints at all). - Change the permissions of this newly created folder to 'Anyone on the Internet with this link can view'. - Enter the FolderId of the newly created folder in the input prompt, and continue with the setup. - For 'DL_WAIT_TIME' reference, see below: > **DL_WAIT_TIME** : Time to wait for aria2c to download the config files. By default it's set to '5' seconds, which is more than enough for deploying the bot to Heroku. If 'DL_WAIT_TIME' lapses, and the config files are not downloaded due to any reason, the bot exits with exit code (1). - The config files will be uploaded to Google Drive, and then deleted, except for 'dynamic.env'. - The setup script will exit with 'Setup Completed' message. - Now, the docker image can be deployed with 'dynamic.env' file. **NOTE:** If you have already run this setup script and want to update the existing config files in drive, enter the appropriate choice in the input prompt. In the next step, enter the FileId of the existing 'dynamic.env' in the input prompt, and the updated files will be uploaded to Google Drive. Now, you can choose to keep the old config files or delete them. # Deploy to Heroku: ## Creating a Heroku App - Create a [free Heroku Account](https://id.heroku.com/signup/login). - Install Heroku CLI: ``` sudo snap install --classic heroku ``` - Login into your Heroku Account: ``` heroku login ``` - Visit [Heroku Dashboard](https://dashboard.heroku.com) and create a new app with any name (for our reference, your-mirror-bot) and with any region you prefer, for your app to be served from. - In the Deploy tab of your app dashboard, select 'Heroku Git' in Deployment Method. - Change the Stack for the App using Heroku CLI: ``` heroku stack:set container --app your-mirror-bot ``` - Initialise the project files as a Git Repository, push the Repo to 'Heroku Git' and build the Docker Image: ``` cd ~/Downloads/deploy_heroku git init git add . git commit -m "initial commit" heroku git:remote --app your-mirror-bot git push heroku master ``` - If the Docker Image Build succeeds, then, your push to the remote repository will succeed, otherwise, your push to the remote repository is rejected as the Docker Image Build fails. ## Run/Terminate the App You can run/terminate the app by allocating/deallocating dynos to the app. ### Using Dashboard - In the app dashboard, under resources tab, use the 'Edit Dyno Formation' button in Dynos section to change the working state of the app. ### Using CLI - To Run: ``` heroku ps:scale worker=1 --app your-mirror-bot ``` - To Terminate: ``` heroku ps:scale worker=0 --app your-mirror-bot ``` - To Check Status: ``` heroku ps --app your-mirror-bot ``` - To Tail App Logs: ``` heroku logs --tail --app your-mirror-bot ``` # Bot Commands: - **start** - Start the bot - **mirror** - Mirror the provided link to Google Drive - **unzipmirror** - Mirror the provided link and if the file is in archive format, it is extracted and then uploaded to Google Drive - **tarmirror** - Mirror the provided link and upload in archive format (.tar) to Google Drive - **cancel** - Reply with this command to the source message, and the download will be cancelled - **cancelall** - Cancels all running tasks (downloads, uploads, archiving, unarchiving) - **list** - Searches the Google Drive folder for any matches with the search term and presents the search results in a Telegraph page - **status** - Shows the status of all downloads and uploads in progress - **authorize** - Authorize a group chat or, a specific user to use the bot - **unauthorize** - Unauthorize a group chat or, a specific user to use the bot - **ping** - Ping the bot - **restart** - Restart the bot - **stats** - Shows the stats of the machine that the bot is hosted on - **help** - To get the help message - **log** - Sends the log file of the bot and the log file of 'aria2c' daemon (can be used to analyse crash reports, if any) - **clone** - Clone folders in Google Drive (owned by someone else) to your Google Drive - **watch** - Mirror through 'youtube-dl' to Google Drive - **tarwatch** - Mirror through 'youtube-dl' and upload in archive format (.tar) to Google Drive - **delete** - Delete files in Google Drive matching the given string - **config** - Edit 'config.env' file **NOTE:** The above listed command descriptions can be copied and pasted in 'edit bot commands' section, when editing the bot settings with [@BotFather](https://t.me/botfather). %prep %autosetup -n tgchizu-1.5.5 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-tgchizu -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Fri Jun 09 2023 Python_Bot - 1.5.5-1 - Package Spec generated