Skip to content

Commit

Permalink
dev: upgrade ltorrent-async
Browse files Browse the repository at this point in the history
  • Loading branch information
hlf20010508 committed Dec 5, 2023
1 parent da6e7a1 commit a1569f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ FROM python:3.8.16-alpine3.17
WORKDIR /telegram-onedrive
COPY ./ ./
RUN apk add --update --no-cache libgcc git &&\
pip install --no-cache-dir telethon requests flask onedrivesdk==1.1.8 git+https://github.com/hlf20010508/LTorrent.git@1.5.0#subdirectory=ltorrent_async &&\
pip install --no-cache-dir telethon requests flask onedrivesdk==1.1.8 git+https://github.com/hlf20010508/LTorrent.git@1.6.0#subdirectory=ltorrent_async &&\
apk del git
COPY --from=cryptg_builder /cryptg /usr/local/lib/python3.8/site-packages
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ flask = "*"
telethon = "*"
requests = "*"
cryptg = "==0.4.0"
ltorrent-async = {ref = "1.5.0", git = "git+https://github.com/hlf20010508/LTorrent.git", subdirectory = "ltorrent_async"}
ltorrent-async = {ref = "1.6.0", git = "git+https://github.com/hlf20010508/LTorrent.git", subdirectory = "ltorrent_async"}
4 changes: 2 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions modules/handlers/magnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from time import time
from io import BytesIO
from telethon import events
from ltorrent_async.client import Client, CustomStorage
from ltorrent_async.client import Client
from ltorrent_async.storage import StorageBase
from ltorrent_async.log import LoggerBase
from modules.client import tg_bot, onedrive
from modules.env import tg_user_name, server_uri
Expand All @@ -17,10 +18,10 @@

port = int(server_uri.rstrip('/').split(':')[-1])

class MyStorage(CustomStorage):
def __init__(self, file_info_list):
CustomStorage.__init__(self)
self.file_info_list = file_info_list
class MyStorage(StorageBase):
def __init__(self):
StorageBase.__init__(self)
self.file_info_list = []
self.uploader_session_dict = {}

async def write(self, file_piece_list, data):
Expand Down Expand Up @@ -88,9 +89,10 @@ async def DEBUG(self, *args):
@check_od_login
async def magnet_handler(event):
my_logger = MyLogger(tg_bot, event.respond)
my_storage = MyStorage()
client = Client(
port=port,
custom_storage=True,
storage=my_storage,
stdout=my_logger,
sequential=True
)
Expand All @@ -102,21 +104,21 @@ async def magnet_handler(event):
await client.load(magnet_link=cmd[1])
# '0' for all
await client.select_file(selection='0')
client.custom_storage = MyStorage(client.torrent.file_names)
client.storage.file_info_list = client.torrent.file_names
await client.run()
else:
await event.reply('Format wrong.')
elif len(cmd) == 1:
# /magnet list magnet:?xt=urn:btih:xxxxxxxxxxxx
await event.reply('Format wrong.')
elif len(cmd) == 3 and cmd[1] == 'list' and cmd[2].startswith('magnet:?'):
# /magnet list magnet:?xt=urn:btih:xxxxxxxxxxxx
await client.load(magnet_link=cmd[2])
await client.list_file()
elif len(cmd) >2 and cmd[1].startswith('magnet:?'):
# /magnet magnet:?xt=urn:btih:xxxxxxxxxxxx 1 3-6 9
await client.load(magnet_link=cmd[1])
await client.select_file(selection=' '.join(cmd[2:]))
client.custom_storage = MyStorage(client.torrent.file_names)
client.storage.file_info_list = client.torrent.file_names
await client.run()

raise events.StopPropagation

0 comments on commit a1569f3

Please sign in to comment.