diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9480486 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +tgd.txt +tgd +tgd.exe +tgd.spec +build/* +dist/* \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c628d51 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# TGD (TeleGram Downloader) + +### Download all types of media from Telegram to your local system even if it is restricted + +#### To get stared, download binaries form [Releases Section](https://github.com/bipinkrish/tgd/releases), supports [Windows](https://github.com/bipinkrish/tgd/releases/download/v1.0/tgd.exe) and [Linux](https://github.com/bipinkrish/tgd/releases/download/v1.0/tgd) + +* If you do not have `Session String` of your account then it will ask login credentials to genrate one, phone number should be in the form of + +``` + +``` +Example : `910123456789` (here `91` is the code (India) and `0123456789` is the number) + +* `API ID` and `API HASH` can be obtained from [my.telegram.org](https://my.telegram.org) + +* All these will be stored in `tgd.txt` for future use \ No newline at end of file diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..0e41c18 --- /dev/null +++ b/build.bat @@ -0,0 +1,7 @@ +@echo off +pip install -r requirements.txt +pip install pyinstaller +pyinstaller --noconfirm --onefile --console tgd.py +move dist\tgd.exe tgd.exe +rmdir /s /q build dist +del tgd.spec diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..56ebd48 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +pip install -r requirements.txt +pip install pyinstaller +pyinstaller --noconfirm --onefile --console tgd.py +mv dist/tgd tgd +chmod 777 tgd +rm -r build/ dist/ tgd.spec diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a5c924d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pyrogram +tgcrypto \ No newline at end of file diff --git a/tgd.py b/tgd.py new file mode 100644 index 0000000..d2678a9 --- /dev/null +++ b/tgd.py @@ -0,0 +1,91 @@ +from pyrogram import Client +from os.path import exists +from os import remove +from sys import stdout + +configfile = "tgd.txt" + +if not exists(configfile): + api_id = input("\nAPI ID: ") + api_hash = input("API HASH: ") + check = input("Do you have String Session? (y/n): ") + if check.lower() == "y": + ss = input("SESSION STRING: ") + else: + print() + with Client("TGD", api_id=api_id, api_hash=api_hash, in_memory=True) as temp: + ss = temp.export_session_string() + print() + with open(configfile,"w") as file: + file.write(api_id + "\n" + api_hash + "\n" + ss) +else: + with open(configfile, "r") as file: + data = file.readlines() + try: + api_id, api_hash, ss = data + except: + remove(configfile) + print("Retry...") + exit(0) + + +acc = Client("myacc" ,api_id=api_id, api_hash=api_hash, session_string=ss) +try: + with acc: + me = acc.get_me() + print("\nLogged in as:", me.id) +except: + remove(configfile) + print("\nMaybe Wrong Crenditals...") + exit(0) + + +def progress(current, total, length=50): + progress_percent = current * 100 / total + completed = int(length * current / total) + bar = f"[{'#' * completed}{' ' * (length - completed)}] {progress_percent:.1f}%" + stdout.write(f"\r{bar}") + stdout.flush() + + +print(""" +Examples: + + https://t.me/xxxx/1423 + https://t.me/c/xxxx/10 + https://t.me/xxxx/1001-1010 + https://t.me/c/xxxx/101 - 120\n\n""") + +link = input("Enter the link: ") +print() + + +if link.startswith("https://t.me/"): + datas = link.split("/") + temp = datas[-1].replace("?single","").split("-") + fromID = int(temp[0].strip()) + try: toID = int(temp[1].strip()) + except: toID = fromID + + if link.startswith("https://t.me/c/"): + chatid = int("-100" + datas[4]) + else: + chatid = datas[3] + +else: + print("Not a Telegram Link") + exit(0) + +with acc: + total = toID+1 - fromID + for msgid in range(fromID, toID+1): + msg = acc.get_messages(chatid, msgid) + + print("Downloding:", msgid, f"({(msgid - fromID + 1)}/{total})") + try: + file = acc.download_media(msg, progress=progress) + print("\nSaved at", file, "\n") + except ValueError as e: + print(e, "\n") + +input("Press enter to exit...")