Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Bump to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCaduceus authored Jun 12, 2023
1 parent 892b73d commit 7711406
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 24 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ List of flags that are usable with tg-upload's download module, while flags with
--dl - Enable download module of tg-upload.
--links - Telegram file links to be downloaded (separated with space).
--txt_file - .txt file path containing telegram file links to be downloaded (1 link / line).
--range - Find and download messages in between of two given links of same chat.
--range - Find and download messages in between of two given links or message ids of same chat.
--chat_id (common) - Identity of chat to download the file from? can be username, phone number (international format) or ID number, by default to Saved Messages.
--msg_id - Identity number of message which needs to be downloaded.
--msg_id - Identity number of messages to be downloaded.
--filename (common) - To download data with custom name.
--replace (common) - Replace given character or keyword in filename. Requires two arguments including 'text to replace' 'text to replace from'.
--prefix (common) - Add given prefix text to each filename (prefix + filename).
Expand Down Expand Up @@ -295,10 +295,10 @@ Flags that does not fit in above categories are listed in this category:
|`TG_UPLOAD_NO_WARN` |`--no_warn` |True or False |
|`TG_UPLOAD_NO_UPDATE` |`--no_update` |True or False |
|`TG_UPLOAD_DL` |`--dl` |True or False |
|`TG_UPLOAD_LINKS` |`--links` |Same as flag |
|`TG_UPLOAD_LINKS` |`--links` |Separate both values using "," (comma).|
|`TG_UPLOAD_TXT_FILE` |`--txt_file` |Same as flag |
|`TG_UPLOAD_RANGE` |`--range` |True or False |
|`TG_UPLOAD_MSG_ID` |`--msg_id` |Same as flag |
|`TG_UPLOAD_MSG_ID` |`--msg_id` |Separate both values using "," (comma).|
|`TG_UPLOAD_DL_DIR` |`--dl_dir` |Same as flag |
|`TG_UPLOAD_DEVICE_MODEL` |`--device_model` |Same as flag |
|`TG_UPLOAD_SYSTEM_VERSION` |`--system_version` |Same as flag |
Expand Down
71 changes: 51 additions & 20 deletions tg-upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import argparse
import hashlib

tg_upload = "1.0.9"
tg_upload = "1.1.0"
versions = f"tg-upload: {tg_upload} \
Python: {py_ver[0]}.{py_ver[1]}.{py_ver[2]} \
Pyrogram: {get_dist('pyrogram').version} \
Expand Down Expand Up @@ -86,10 +86,10 @@

# DOWNLOAD FLAGS
parser.add_argument("--dl", default=env.get("TG_UPLOAD_DL", "False").lower() in {"true", "t", "1"}, action="store_true", help="Enable download module of tg-upload.")
parser.add_argument("--links", metavar="TG_UPLOAD_LINKS", nargs="+", type=str, default=env.get("TG_UPLOAD_LINKS", []), help="Telegram file links to be downloaded (separated with space).")
parser.add_argument("--links", metavar="TG_UPLOAD_LINKS", nargs="+", type=str, default=env.get("TG_UPLOAD_LINKS", "").split(","), help="Telegram file links to be downloaded (separated with space).")
parser.add_argument("--txt_file", metavar="TG_UPLOAD_TXT_FILE", default=env.get("TG_UPLOAD_TXT_FILE", None), help=".txt file path containing telegram file links to be downloaded (1 link / line).")
parser.add_argument("--range", default=env.get("TG_UPLOAD_RANGE", "False").lower() in {"true", "t", "1"}, action="store_true", help="Find and download messages in between of two given links of same chat.")
parser.add_argument("--msg_id", metavar="TG_UPLOAD_MSG_ID", type=int, default=env.get("TG_UPLOAD_MSG_ID", None), help="Identity number of message which needs to be downloaded.")
parser.add_argument("--range", default=env.get("TG_UPLOAD_RANGE", "False").lower() in {"true", "t", "1"}, action="store_true", help="Find and download messages in between of two given links or message ids of same chat.")
parser.add_argument("--msg_id", nargs="+", metavar="TG_UPLOAD_MSG_ID", type=int, default=env.get("TG_UPLOAD_MSG_ID", "").split(","), help="Identity number of messages to be downloaded.")
parser.add_argument("--dl_dir", metavar="TG_UPLOAD_DL_DIR", default=env.get("TG_UPLOAD_DL_DIR", None), help="Change the download directory, by default 'downloads' in current working directory.")

# UTILITY FLAGS
Expand Down Expand Up @@ -462,8 +462,11 @@ def get_chatid(raw_id):
with open(args.txt_file, 'r') as txt_file:
args.links = txt_file.readlines()

if args.links and len(args.links) != 0:
if len(args.links) != 0 and args.links[0]:
if args.range:
if not len(args.links) >= 2:
exit("Error: Using --range flag requires two different links of same chat.")

_chat_id , _message_id = validate_link(args.links[0])
__chat_id, __message_id = validate_link(args.links[1])

Expand Down Expand Up @@ -508,24 +511,52 @@ def get_chatid(raw_id):
client.download_media(message, progress=download_progress, file_name=filename)
except ValueError as error_code:
print(f"\n{error_code} - {link}")
elif args.chat_id and args.msg_id:
elif args.chat_id and len(args.msg_id) != 0 and args.msg_id[0]:
args.chat_id = get_chatid(args.chat_id)
try:
message = client.get_messages(args.chat_id, args.msg_id)
except errors.exceptions.bad_request_400.ChannelInvalid:
exit(f"Error: No access to {args.chat_id}.")
except ValueError as error_code:
exit(f"\n{error_code} - {args.chat_id}")

filename, filesize = msg_info(message)
start_time = time()

try:
client.download_media(message, progress=download_progress, file_name=filename)
except ValueError:
exit(f"\nError: No downloadable media found - {args.message_id}")
if args.range:
if not len(args.msg_id) >= 2:
exit("Error: Using --range requires two different MSG IDs of same chat.")
elif args.msg_id[0] == args.msg_id[1]:
exit("Error: MSG_IDs should be different.")

message_ids = range(args.msg_id[0], args.msg_id[1]+1) if args.msg_id[0] < args.msg_id[1] else range(args.msg__id[1], args.msg_id[0]+1)

for message_id in message_ids:
try:
message = client.get_messages(args.chat_id, message_id)
except ValueError:
print(f"\nMessage ID not found: {message_id}")
continue

filename, filesize = msg_info(message)
start_time = time()

try:
client.download_media(message, progress=download_progress, file_name=filename)
except ValueError:
print(f"\nNo Media: MSG_{message_id}")
except Exception as error_code:
print(f"\n{error_code}")

else:
for msg_id in args.msg_id:
try:
message = client.get_messages(args.chat_id, args.msg_id)
except errors.exceptions.bad_request_400.ChannelInvalid:
exit(f"Error: No access to {args.chat_id}.")
except ValueError as error_code:
exit(f"\n{error_code} - {args.chat_id}")

filename, filesize = msg_info(message)
start_time = time()

try:
client.download_media(message, progress=download_progress, file_name=filename)
except ValueError:
exit(f"\nError: No downloadable media found - {msg_id}")
else:
exit("Error: No link provided to download.")
exit("Error: No link or message id provided to download.")
else:
if not args.path:
exit("Error: Path is not provided.")
Expand Down

0 comments on commit 7711406

Please sign in to comment.