Update utils/streamer/custom_dl.py
Browse files- utils/streamer/custom_dl.py +26 -2
utils/streamer/custom_dl.py
CHANGED
|
@@ -15,6 +15,7 @@ class ByteStreamer:
|
|
| 15 |
self.clean_timer = 30 * 60
|
| 16 |
self.client: Client = client
|
| 17 |
self.cached_file_ids: Dict[int, FileId] = {}
|
|
|
|
| 18 |
asyncio.create_task(self.clean_cache())
|
| 19 |
|
| 20 |
async def get_file_properties(self, channel, message_id: int) -> FileId:
|
|
@@ -38,12 +39,33 @@ class ByteStreamer:
|
|
| 38 |
media_session = client.media_sessions.get(file_id.dc_id, None)
|
| 39 |
|
| 40 |
if media_session is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
if file_id.dc_id != await client.storage.dc_id():
|
| 42 |
media_session = Session(
|
| 43 |
client,
|
| 44 |
file_id.dc_id,
|
|
|
|
|
|
|
| 45 |
await Auth(
|
| 46 |
-
client, file_id.dc_id, await client.storage.test_mode()
|
| 47 |
).create(),
|
| 48 |
await client.storage.test_mode(),
|
| 49 |
is_media=True,
|
|
@@ -74,6 +96,8 @@ class ByteStreamer:
|
|
| 74 |
media_session = Session(
|
| 75 |
client,
|
| 76 |
file_id.dc_id,
|
|
|
|
|
|
|
| 77 |
await client.storage.auth_key(),
|
| 78 |
await client.storage.test_mode(),
|
| 79 |
is_media=True,
|
|
@@ -196,4 +220,4 @@ class ByteStreamer:
|
|
| 196 |
while True:
|
| 197 |
await asyncio.sleep(self.clean_timer)
|
| 198 |
self.cached_file_ids.clear()
|
| 199 |
-
logger.debug("Cleaned the cache")
|
|
|
|
| 15 |
self.clean_timer = 30 * 60
|
| 16 |
self.client: Client = client
|
| 17 |
self.cached_file_ids: Dict[int, FileId] = {}
|
| 18 |
+
self.dc_options = None
|
| 19 |
asyncio.create_task(self.clean_cache())
|
| 20 |
|
| 21 |
async def get_file_properties(self, channel, message_id: int) -> FileId:
|
|
|
|
| 39 |
media_session = client.media_sessions.get(file_id.dc_id, None)
|
| 40 |
|
| 41 |
if media_session is None:
|
| 42 |
+
if not self.dc_options:
|
| 43 |
+
config = await client.invoke(raw.functions.help.GetConfig())
|
| 44 |
+
self.dc_options = config.dc_options
|
| 45 |
+
|
| 46 |
+
ip = None
|
| 47 |
+
port = None
|
| 48 |
+
for option in self.dc_options:
|
| 49 |
+
if option.id == file_id.dc_id and not option.ipv6 and not option.cdn and not option.media_only:
|
| 50 |
+
ip = option.ip_address
|
| 51 |
+
port = option.port
|
| 52 |
+
break
|
| 53 |
+
|
| 54 |
+
if not ip:
|
| 55 |
+
for option in self.dc_options:
|
| 56 |
+
if option.id == file_id.dc_id and not option.ipv6 and not option.cdn:
|
| 57 |
+
ip = option.ip_address
|
| 58 |
+
port = option.port
|
| 59 |
+
break
|
| 60 |
+
|
| 61 |
if file_id.dc_id != await client.storage.dc_id():
|
| 62 |
media_session = Session(
|
| 63 |
client,
|
| 64 |
file_id.dc_id,
|
| 65 |
+
ip,
|
| 66 |
+
port,
|
| 67 |
await Auth(
|
| 68 |
+
client, file_id.dc_id, ip, port, await client.storage.test_mode()
|
| 69 |
).create(),
|
| 70 |
await client.storage.test_mode(),
|
| 71 |
is_media=True,
|
|
|
|
| 96 |
media_session = Session(
|
| 97 |
client,
|
| 98 |
file_id.dc_id,
|
| 99 |
+
ip,
|
| 100 |
+
port,
|
| 101 |
await client.storage.auth_key(),
|
| 102 |
await client.storage.test_mode(),
|
| 103 |
is_media=True,
|
|
|
|
| 220 |
while True:
|
| 221 |
await asyncio.sleep(self.clean_timer)
|
| 222 |
self.cached_file_ids.clear()
|
| 223 |
+
logger.debug("Cleaned the cache")
|