Skip to content

Commit 9e22878

Browse files
authored
Merge pull request #386
v7.5
2 parents 30391ba + d2c23aa commit 9e22878

File tree

8 files changed

+79
-61
lines changed

8 files changed

+79
-61
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ dmypy.json
131131
# video file extensions
132132
*.mp4
133133
*.flv
134-
cookies.json
135-
telegram.json
136134

137135
# telegram session file
138136
*.session

src/cookies.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"sessionid_ss": "",
3+
"tt-target-idc": "useast2a"
4+
}

src/requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ruff~=0.12.0
2+
pre-commit~=4.3.0

src/requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
argparse~=1.4.0
22
ffmpeg-python~=0.2.0
3-
Pyrogram~=2.0.0
3+
telethon~=1.42.0
44
distro~=1.9.0
55
curl_cffi~=0.12.0
66
requests~=2.32.0
7-
ruff~=0.12.0
8-
pre-commit~=4.3.0

src/telegram.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"api_id": "",
33
"api_hash": "",
4-
"bot_token": "",
5-
"chat_id": 1110107842
4+
"chat_id": "me"
65
}

src/upload/telegram.py

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import asyncio
12
from pathlib import Path
23

3-
from pyrogram import Client
4-
from pyrogram.enums import ParseMode
4+
from telethon import TelegramClient
55

66
from utils.logger_manager import logger
77
from utils.utils import read_telegram_config
@@ -17,58 +17,71 @@ def __init__(self):
1717

1818
self.api_id = config["api_id"]
1919
self.api_hash = config["api_hash"]
20-
self.bot_token = config["bot_token"]
2120
self.chat_id = config["chat_id"]
2221

23-
self.app = Client(
24-
"telegram_session",
22+
self.client = TelegramClient(
23+
"tiktok_live_recorder_session",
2524
api_id=self.api_id,
2625
api_hash=self.api_hash,
27-
bot_token=self.bot_token,
2826
)
2927

3028
def upload(self, file_path: str):
3129
"""
32-
Upload a file to the bot's own chat (saved messages).
30+
Upload a file to the user's Saved Messages via Telethon.
3331
"""
34-
try:
35-
self.app.start()
36-
37-
me = self.app.get_me()
38-
is_premium = me.is_premium
39-
max_size = (
40-
PREMIUM_USER_MAX_FILE_SIZE if is_premium else FREE_USER_MAX_FILE_SIZE
41-
)
42-
43-
file_size = Path(file_path).stat().st_size
44-
logger.info(
45-
f"File to upload: {Path(file_path).name} "
46-
f"({round(file_size / (1024 * 1024))} MB)"
47-
)
48-
49-
if file_size > max_size:
50-
logger.warning(
51-
"The file is too large to be uploaded with this type of account."
32+
33+
async def _upload():
34+
try:
35+
await self.client.connect()
36+
37+
if not await self.client.is_user_authorized():
38+
await self.client.start()
39+
40+
me = await self.client.get_me()
41+
is_premium = me.premium
42+
max_size = (
43+
PREMIUM_USER_MAX_FILE_SIZE
44+
if is_premium
45+
else FREE_USER_MAX_FILE_SIZE
46+
)
47+
48+
file_size = Path(file_path).stat().st_size
49+
logger.info(
50+
f"File to upload: {Path(file_path).name} "
51+
f"({round(file_size / (1024 * 1024))} MB)"
52+
)
53+
54+
if file_size > max_size:
55+
logger.warning(
56+
"The file is too large to be uploaded "
57+
"with this type of account."
58+
)
59+
return
60+
61+
logger.info(
62+
"Uploading video on Telegram... "
63+
"This may take a while depending on file size."
64+
)
65+
66+
await self.client.send_file(
67+
entity=self.chat_id,
68+
file=file_path,
69+
caption=(
70+
"🎥 <b>Video recorded via "
71+
'<a href="https://github.com/Michele0303/'
72+
'tiktok-live-recorder">'
73+
"TikTok Live Recorder</a></b>"
74+
),
75+
parse_mode="html",
76+
force_document=True,
5277
)
53-
return
54-
55-
logger.info(
56-
"Uploading video on Telegram... This may take a while depending on the file size."
57-
)
58-
self.app.send_document(
59-
chat_id=self.chat_id,
60-
document=file_path,
61-
caption=(
62-
'🎥 <b>Video recorded via <a href="https://github.com/Michele0303/tiktok-live-recorder">'
63-
"TikTok Live Recorder</a></b>"
64-
),
65-
parse_mode=ParseMode.HTML,
66-
force_document=True,
67-
)
68-
logger.info("File successfully uploaded to Telegram.\n")
69-
70-
except Exception as e:
71-
logger.error(f"Error during Telegram upload: {e}\n")
72-
73-
finally:
74-
self.app.stop()
78+
79+
logger.info("File successfully uploaded to Telegram.\n")
80+
81+
except Exception as e:
82+
logger.error(f"Error during Telegram upload: {e}\n")
83+
84+
finally:
85+
await self.client.disconnect()
86+
87+
asyncio.run(_upload())

src/utils/dependencies.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ def check_requests_library():
120120
return False
121121

122122

123-
def check_pyrogram_library():
123+
def check_telethon_library():
124124
try:
125-
import pyrogram
125+
import telethon
126126

127-
_ = pyrogram # to avoid linting issues
127+
_ = telethon # to avoid linting issues
128128

129129
return True
130130
except ModuleNotFoundError:
131-
logger.error("pyrogram library is not installed")
131+
logger.error("telethon library is not installed")
132132
return False
133133

134134

@@ -162,7 +162,7 @@ def check_and_install_dependencies():
162162
check_argparse_library(),
163163
check_curl_cffi_library(),
164164
check_requests_library(),
165-
check_pyrogram_library(),
165+
check_telethon_library(),
166166
check_ffmpeg_binary(),
167167
]
168168

src/utils/enums.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ def __str__(self):
118118
def __iter__(self):
119119
return iter(self.value)
120120

121-
NEW_FEATURES = ["Fixed followers mode", "Minor"]
121+
NEW_FEATURES = [
122+
"Replaced pyrogram to telethon library.",
123+
"Fixed termux dependencies error.",
124+
"Minor.",
125+
]
122126

123-
VERSION = 7.4
127+
VERSION = 7.5
124128
BANNER = rf"""
125129
126130
_____ _ _ _____ _ _ _ ___ _

0 commit comments

Comments
 (0)