Skip to content

Commit

Permalink
let's try pyrogram 2.x again
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyThink committed Dec 17, 2023
1 parent acacfe5 commit f7243a4
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 235 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env
venv
db_data
.ash_history
.DS_Store
.DS_Store
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,6 @@ reinforcement/*
/ytdlbot/ytdl-main.session
/ytdlbot/ytdl-celery.session-journal
/ytdlbot/ytdl-celery.session
/ytdlbot/main.session
/ytdlbot/tasks.session
/ytdlbot/tasks.session-journal
Empty file removed .gitmodules
Empty file.
9 changes: 0 additions & 9 deletions .gitpod.yml

This file was deleted.

11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
FROM python:3.11-alpine as builder

RUN apk update && apk add --no-cache tzdata alpine-sdk libffi-dev ca-certificates
FROM python:3.11 as builder
ADD requirements.txt /tmp/
RUN pip3 install --user -r /tmp/requirements.txt && rm /tmp/requirements.txt


FROM python:3.11-alpine
FROM python:3.11-slim
WORKDIR /ytdlbot/ytdlbot
ENV TZ=Europe/Stockholm
ENV TZ=Europe/London

COPY apk.txt /tmp/
RUN apk update && xargs apk add < /tmp/apk.txt
RUN apt update && apt install -y --no-install-recommends --no-install-suggests ffmpeg vnstat git aria2
COPY --from=builder /root/.local /usr/local
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ This bot can be deployed on any platform that supports Python.
To deploy this bot, follow these steps:

1. Install bot dependencies
* Install Python 3.8 or a later version, FFmpeg.
* Install Python 3.10 or a later version, FFmpeg.
* (optional)Aria2 and add it to the PATH.

2. Clone the code from the repository and cd into it.
Expand Down Expand Up @@ -153,7 +153,6 @@ You can configure all the following environment variables:
* AUTHORIZED_USER: only authorized users can use the bot
* REQUIRED_MEMBERSHIP: group or channel username, user must join this group to use the bot
* ENABLE_CELERY: celery mode, default: disable
* ENABLE_QUEUE: celery queue
* BROKER: celery broker, should be redis://redis:6379/0
* MYSQL_HOST:MySQL host
* MYSQL_USER: MySQL username
Expand Down Expand Up @@ -291,11 +290,11 @@ https://twitter.com/BennyThinks/status/1475836588542341124

## Test instagram

https://www.instagram.com/p/ClBSqo3PkJw/

https://www.instagram.com/p/CaiAHoWDnrM/

https://www.instagram.com/p/CZtUDyyv1u1/
* single image: https://www.instagram.com/p/CXpxSyOrWCA/
* single video: https://www.instagram.com/p/Cah_7gnDVUW/
* reels: https://www.instagram.com/p/C0ozGsjtY0W/
* image carousel: https://www.instagram.com/p/C0ozPQ5o536/
* video and image carousel: https://www.instagram.com/p/C0ozhsVo-m8/

# Donation

Expand Down
1 change: 0 additions & 1 deletion apk.txt

This file was deleted.

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pyrogram==1.4.16
pyrogram==2.0.106
tgcrypto==1.2.5
yt-dlp==2023.11.16
APScheduler==3.10.4
Expand All @@ -11,7 +11,7 @@ flower==2.0.1
psutil==5.9.6
influxdb==5.3.1
beautifulsoup4==4.12.2
fakeredis==2.20.0
fakeredis==2.20.1
supervisor==4.2.5
tgbot-ping==1.0.7
redis==5.0.1
Expand Down
8 changes: 3 additions & 5 deletions ytdlbot/client_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
from config import APP_HASH, APP_ID, PYRO_WORKERS, TOKEN, IPv6


def create_app(session: str, workers: int = PYRO_WORKERS) -> Client:
_app = Client(
session,
def create_app(name: str, workers: int = PYRO_WORKERS) -> Client:
return Client(
name,
APP_ID,
APP_HASH,
bot_token=TOKEN,
workers=workers,
ipv6=IPv6,
)

return _app
6 changes: 2 additions & 4 deletions ytdlbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from blinker import signal

# general settings
WORKERS: int = int(os.getenv("WORKERS", 100))
PYRO_WORKERS: int = int(os.getenv("PYRO_WORKERS", min(64, (os.cpu_count() + 4) * 10)))
WORKERS: int = int(os.getenv("WORKERS", 10))
PYRO_WORKERS: int = int(os.getenv("PYRO_WORKERS", min(32, (os.cpu_count() or 0) + 4)))
APP_ID: int = int(os.getenv("APP_ID", 198214))
APP_HASH = os.getenv("APP_HASH", "1234b90")
TOKEN = os.getenv("TOKEN", "1234")
Expand All @@ -36,7 +36,6 @@

# celery related
ENABLE_CELERY = os.getenv("ENABLE_CELERY", False)
ENABLE_QUEUE = os.getenv("ENABLE_QUEUE", False)
BROKER = os.getenv("BROKER", f"redis://{REDIS}:6379/4")

MYSQL_HOST = os.getenv("MYSQL_HOST", "mysql")
Expand All @@ -49,7 +48,6 @@
IPv6 = os.getenv("IPv6", False)
ENABLE_FFMPEG = os.getenv("ENABLE_FFMPEG", False)


PLAYLIST_SUPPORT = os.getenv("PLAYLIST_SUPPORT", False)
M3U8_SUPPORT = os.getenv("M3U8_SUPPORT", False)
ENABLE_ARIA2 = os.getenv("ENABLE_ARIA2", False)
Expand Down
4 changes: 2 additions & 2 deletions ytdlbot/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self):
self.r = redis.StrictRedis(host=REDIS, db=0, decode_responses=True)
self.r.ping()
except Exception:
logging.warning("Redis connection failed, using fake redis instead.")
logging.debug("Redis connection failed, using fake redis instead.")
self.r = fakeredis.FakeStrictRedis(host=REDIS, db=0, decode_responses=True)

db_banner = "=" * 20 + "DB data" + "=" * 20
Expand Down Expand Up @@ -256,7 +256,7 @@ def __init__(self):
host=MYSQL_HOST, user=MYSQL_USER, passwd=MYSQL_PASS, db="ytdl", charset="utf8mb4"
)
except Exception:
logging.warning("MySQL connection failed, using fake mysql instead.")
logging.debug("MySQL connection failed, using fake mysql instead.")
self.con = FakeMySQL()

self.con.ping(reconnect=True)
Expand Down
15 changes: 5 additions & 10 deletions ytdlbot/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,19 @@
import filetype
import requests
import yt_dlp as ytdl
from pyrogram import types
from tqdm import tqdm

from config import (
AUDIO_FORMAT,
ENABLE_ARIA2,
ENABLE_FFMPEG,
TG_MAX_SIZE,
IPv6,
)
from config import AUDIO_FORMAT, ENABLE_ARIA2, ENABLE_FFMPEG, TG_MAX_SIZE, IPv6
from limit import Payment
from utils import adjust_formats, apply_log_formatter, current_time, sizeof_fmt

r = fakeredis.FakeStrictRedis()
apply_log_formatter()


def edit_text(bot_msg, text: str):
key = f"{bot_msg.chat.id}-{bot_msg.message_id}"
def edit_text(bot_msg: types.Message, text: str):
key = f"{bot_msg.chat.id}-{bot_msg.id}"
# if the key exists, we shouldn't send edit message
if not r.exists(key):
time.sleep(random.random())
Expand Down Expand Up @@ -87,7 +82,7 @@ def remove_bash_color(text):


def download_hook(d: dict, bot_msg):
# since we're using celery, server location may be located in different continent.
# since we're using celery, server location may be located in different region.
# Therefore, we can't trigger the hook very often.
# the key is user_id + download_link
original_url = d["info_dict"]["original_url"]
Expand Down
2 changes: 1 addition & 1 deletion ytdlbot/limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def check_payment(self):

cur.execute("select user_id, payment_id from payment where payment_id like 'tron,0,T%'")
data = cur.fetchall()
logging.info("Checking unpaid payment...%s", data)
for row in data:
logging.info("Checking user payment %s", row)
user_id = row[0]
addr, index = row[1].split(",")[2:]
try:
Expand Down
Loading

1 comment on commit f7243a4

@SanujaNS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏👏👏

Please sign in to comment.