Skip to content

Commit

Permalink
Env toggle to enable / disable Playlist download (tgbot-collection#200)
Browse files Browse the repository at this point in the history
* Env toggle to enable / disable Playlist download

* i think this else is obsolete
  • Loading branch information
Bartixxx32 authored Feb 5, 2023
1 parent dfbd69d commit 2d58289
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ you can configure all the following environment variables:
* AUDIO_FORMAT: audio format, default is m4a. You can set to any known and supported format for ffmpeg. For
example,`mp3`, `flac`, etc. ⚠️ m4a is the fastest. Other formats may affect performance.
* ARCHIVE_ID: group or channel id/username. All downloads will send to this group first and then forward to end user.
* PLAYLIST_SUPPORT: `True` or `False`, Ability to enable or disable downloads of playlist / channels by bot. Default: `False`.
**Inline button will be lost during the forwarding.**

## 3.2 Set up init data
Expand Down
1 change: 1 addition & 0 deletions ytdlbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@
RATE = float(os.getenv("RATE", 0.01))
BURST = int(os.getenv("BURST", 3))
PROVIDER_TOKEN = os.getenv("PROVIDER_TOKEN") or "1234"
PLAYLIST_SUPPORT = os.getenv("PLAYLIST_SUPPORT", False)
11 changes: 6 additions & 5 deletions ytdlbot/ytdl_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from client_init import create_app
from config import (AUTHORIZED_USER, BURST, ENABLE_CELERY, ENABLE_FFMPEG,
ENABLE_VIP, MULTIPLY, OWNER, PROVIDER_TOKEN, QUOTA, RATE,
REQUIRED_MEMBERSHIP)
REQUIRED_MEMBERSHIP, PLAYLIST_SUPPORT)
from constant import BotText
from db import InfluxDB, MySQL, Redis
from limit import VIP, verify_payment
Expand Down Expand Up @@ -331,10 +331,11 @@ def download_handler(client: "Client", message: "types.Message"):
message.reply_text("I think you should send me a link.", quote=True)
return

if re.findall(r"^https://www\.youtube\.com/channel/", VIP.extract_canonical_link(url)) or "list" in url:
message.reply_text("Channel/list download is disabled now. Please send me individual video link.", quote=True)
red.update_metrics("reject_channel")
return
if not PLAYLIST_SUPPORT:
if re.findall(r"^https://www\.youtube\.com/channel/", VIP.extract_canonical_link(url)) or "list" in url:
message.reply_text("Channel/list download is disabled now. Please send me individual video link.", quote=True)
red.update_metrics("reject_channel")
return
# non vip user, consume too many token
if (not VIP().check_vip(chat_id)) and (not lim.consume(str(chat_id).encode(), 1)):
red.update_metrics("rate_limit")
Expand Down

0 comments on commit 2d58289

Please sign in to comment.