-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separated telegram related code from download upload related code
Signed-off-by: lzzy12 <[email protected]>
- Loading branch information
Showing
13 changed files
with
373 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,7 @@ config.ini | |
downloads/* | ||
download/* | ||
data* | ||
.vscode | ||
.vscode | ||
.idea | ||
*.json | ||
*.pickle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive.\n | ||
Documentation is coming as soon as we finish implementing all the basic features of the bot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
aria2c --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --max-connection-per-server=10 --rpc-max-request-size=1024M --seed-time=0.01 --min-split-size=10M --follow-torrent=mem --split=10 --daemon=true --allow-overwrite=true | ||
aria2c --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --max-connection-per-server=10 --rpc-max-request-size=1024M --seed-time=0.01 --min-split-size=10M --follow-torrent=mem --split=10 --daemon=true --allow-overwrite=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Message: | ||
pass | ||
|
||
class Download: | ||
def __init__(self, gid, download): | ||
self.isDownloading = download.is_complete | ||
self.gid = gid | ||
self.download = download |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import aria2p | ||
from time import sleep | ||
from bot import LOGGER, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_list | ||
from bot.helper.listeners import * | ||
from urllib.parse import urlparse | ||
from aria2p import Options | ||
|
||
|
||
def is_url(url: str): | ||
try: | ||
urlparse(url) | ||
return True | ||
except ValueError: | ||
return False | ||
|
||
|
||
def is_magnet(url: str): | ||
if "magnet" in url: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
class DownloadHelper: | ||
|
||
def __init__(self, listener: MirrorListeners): | ||
self.__aria2 = aria2p.API( | ||
aria2p.Client( | ||
host="http://localhost", | ||
port=6800, | ||
secret="", | ||
) | ||
) | ||
self.__listener = listener | ||
|
||
def add_download(self, link: str): | ||
download = None | ||
if is_url(link): | ||
download = self.__aria2.add_uris([link], {'dir': DOWNLOAD_DIR + str(self.__listener.update.update_id), | ||
'max_download_limit': 1}) | ||
elif is_magnet(link): | ||
download = self.__aria2.add_magnet(link, {'dir': DOWNLOAD_DIR}) | ||
else: | ||
self.__listener.onDownloadError("No download URL or URL malformed") | ||
return | ||
download_list[self.__listener.update.update_id] = download.gid | ||
self.__listener.onDownloadStarted(link) | ||
self.__update_download_status() | ||
|
||
def get_downloads_status_str_list(self): | ||
""" | ||
Generates a human readable string of progress of all the downloads | ||
:return: list of strings of progress of all the downloads | ||
""" | ||
str_list = [] | ||
LOGGER.info(download_list) | ||
for gid in list(download_list.values()): | ||
download = self.__aria2.get_download(gid) | ||
str_list.append("<b>" + download.name + "</b>:- " | ||
+ download.progress_string() + " of " | ||
+ download.total_length_string() | ||
+ " at " + download.download_speed_string() | ||
+ " ,ETA: " + download.eta_string() | ||
) | ||
return str_list | ||
|
||
def __get_download(self): | ||
return self.__aria2.get_download(download_list[self.__listener.update.update_id]) | ||
|
||
def __update_download_status(self): | ||
# TODO: Try to find a way to move this code to mirror.py and send only a | ||
# list of Download objects to onDownloadProgress() | ||
previous = None | ||
LOGGER.info(self.get_downloads_status_str_list()) | ||
while not self.__get_download().is_complete: | ||
if self.__get_download().has_failed: | ||
self.__listener.onDownloadError(self.__get_download().error_message) | ||
break | ||
progress_str_list = self.get_downloads_status_str_list() | ||
if progress_str_list != previous: | ||
self.__listener.onDownloadProgress(progress_str_list) | ||
previous = progress_str_list | ||
sleep(DOWNLOAD_STATUS_UPDATE_INTERVAL) | ||
|
||
self.__listener.onDownloadComplete(self.__get_download()) |
Oops, something went wrong.