Skip to content

Commit

Permalink
Changed the thumb type from ['sticker'] to ['document']
Browse files Browse the repository at this point in the history
  • Loading branch information
om1ji committed Jul 15, 2021
1 parent 0ab5f48 commit f41aa82
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
16 changes: 13 additions & 3 deletions downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests

import telebot
from PIL import Image

from regex import *
from _logging import _log
Expand Down Expand Up @@ -52,14 +53,23 @@ def download_from_queue(QUEUE_DIR):

_log(LOGFILE, f"Folder: {folder}, path to .description file: {track_descr_path}", 1)
single_file = {'document': open(folder + basename + '.mp3', 'rb')}
thumbnail = open(folder + basename + '.jpg', 'rb')

try:
thumb_conv = Image.open(folder + basename + '.webp')
thumb_conv.save(folder + basename + '.jpg', 'jpeg')
except FileNotFoundError:
_log(LOGFILE, "jpg already exists!", 2)

thumbnail = {'document': open(folder + basename + '.jpg', 'rb')}

_log(LOGFILE, "Sending to temp channel...", 1)
the_file = requests.post(f"https://api.telegram.org/bot{TOKEN}/sendDocument?chat_id={TMP_CHAT_ID}", files=single_file)
# BOT.send_audio(CHAT_ID, audio=single_file.content)
the_thumb = requests.post(f"https://api.telegram.org/bot{TOKEN}/sendDocument?chat_id={TMP_CHAT_ID}", files=thumbnail)


try:
_log(LOGFILE, "Result: " + str(json.loads(the_file.text)['result']), 1)
_log(LOGFILE, "Result: " + str(json.loads(the_file.text)), 1)
file_id = json.loads(the_file.text)['result']['audio']['file_id']
except KeyError:
file_id = json.loads(the_file.text)['result']['document']['file_id']
Expand All @@ -71,7 +81,7 @@ def download_from_queue(QUEUE_DIR):

message_id = json.loads(the_file.text)['result']['message_id']
_log(LOGFILE, "thumb result: " + str(json.loads(the_thumb.text)['result']), 1)
thumb_id = json.loads(the_thumb.text)['result']['sticker']['thumb']['file_id']
thumb_id = json.loads(the_thumb.text)['result']['document']['file_id']

file_path = BOT.get_file(file_id).file_path
_log(LOGFILE, f"File path: {file_path}; File id: {file_id}; Message id: {message_id}", 2)
Expand Down
4 changes: 0 additions & 4 deletions regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def get_album_title(desc):
ОЧЕНЬ ВАЖНО!! В аргумент функций artist, title и orig_link подаётся НАЗВАНИЕ описания, а не его содержимое
"""

def _dbgl():
"""для дебагинга, не трогать"""
return inspect.currentframe().f_back.f_lineno

def get_upload_type(desc):
"""
Returns the upload type of the video:
Expand Down
27 changes: 27 additions & 0 deletions template config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
###########################
# !Mandatory parameters!: #
###########################

# Directory for all the files
DIRECTORY: "/home/bot/HATE/"
# Your bot token, acquired through @BotFather
TOKEN: "1591601193:AAHWLplYpkAPwbwq7c-0A51169BQpf9N04s"
# Channel IDs, where MAIN_CHAT_ID is your main channel,
# where all the final posts will be made, and
# TEMP_CHAT_ID is your temporary channel.
MAIN_CHAT_ID: "-1001389676477"
TEMP_CHAT_ID: "-1001170446896"



#########################
# All of the parameters below are optional,
# but are recommended to being configured.
# Default values are provided.
#########################
results_dir: "tmp/"
queue_name: "queue.db"
create_logs: 1

# REGEXES:
re_original_link: "([a-zA-Z0-9_-]{11})(?:\.\.?description)$"

0 comments on commit f41aa82

Please sign in to comment.