Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bipinkrish committed Dec 13, 2023
0 parents commit 5909b9f
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tgd.txt
tgd
tgd.exe
tgd.spec
build/*
dist/*
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

```
<contrycode><number>
```
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
7 changes: 7 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyrogram
tgcrypto
91 changes: 91 additions & 0 deletions tgd.py
Original file line number Diff line number Diff line change
@@ -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...")

0 comments on commit 5909b9f

Please sign in to comment.