Skip to content

Commit 3c81006

Browse files
committed
Merge branch 'media-servers'
2 parents c5624c6 + 0c814e9 commit 3c81006

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

pyrogram/connection/connection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ class Connection:
3838
4: TCPIntermediateO
3939
}
4040

41-
def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, mode: int = 3):
41+
def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False, mode: int = 3):
4242
self.dc_id = dc_id
4343
self.test_mode = test_mode
4444
self.ipv6 = ipv6
4545
self.proxy = proxy
46-
self.address = DataCenter(dc_id, test_mode, ipv6)
46+
self.media = media
47+
self.address = DataCenter(dc_id, test_mode, ipv6, media)
4748
self.mode = self.MODES.get(mode, TCPAbridged)
4849

4950
self.protocol = None # type: TCP
@@ -60,11 +61,13 @@ async def connect(self):
6061
self.protocol.close()
6162
await asyncio.sleep(1)
6263
else:
63-
log.info("Connected! {} DC{} - IPv{} - {}".format(
64+
log.info("Connected! {} DC{} - IPv{} - {}{} {}".format(
6465
"Test" if self.test_mode else "Production",
6566
self.dc_id,
6667
"6" if self.ipv6 else "4",
67-
self.mode.__name__
68+
self.mode.__name__,
69+
" (media)" if self.media else "",
70+
self.address
6871
))
6972
break
7073
else:

pyrogram/session/internals/data_center.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,66 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from typing import Tuple
20+
21+
1922
class DataCenter:
2023
TEST = {
2124
1: "149.154.175.10",
2225
2: "149.154.167.40",
2326
3: "149.154.175.117",
24-
121: "95.213.217.195"
2527
}
2628

2729
PROD = {
2830
1: "149.154.175.53",
2931
2: "149.154.167.51",
3032
3: "149.154.175.100",
3133
4: "149.154.167.91",
32-
5: "91.108.56.130",
33-
121: "95.213.217.195"
34+
5: "91.108.56.130"
35+
}
36+
37+
PROD_MEDIA = {
38+
2: "149.154.167.151",
39+
4: "149.154.164.250"
3440
}
3541

3642
TEST_IPV6 = {
3743
1: "2001:b28:f23d:f001::e",
3844
2: "2001:67c:4e8:f002::e",
3945
3: "2001:b28:f23d:f003::e",
40-
121: "2a03:b0c0:3:d0::114:d001"
4146
}
4247

4348
PROD_IPV6 = {
4449
1: "2001:b28:f23d:f001::a",
4550
2: "2001:67c:4e8:f002::a",
4651
3: "2001:b28:f23d:f003::a",
4752
4: "2001:67c:4e8:f004::a",
48-
5: "2001:b28:f23f:f005::a",
49-
121: "2a03:b0c0:3:d0::114:d001"
53+
5: "2001:b28:f23f:f005::a"
5054
}
5155

52-
def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool):
53-
if ipv6:
54-
return (
55-
(cls.TEST_IPV6[dc_id], 80)
56-
if test_mode
57-
else (cls.PROD_IPV6[dc_id], 443)
58-
)
56+
PROD_IPV6_MEDIA = {
57+
2: "2001:067c:04e8:f002:0000:0000:0000:000b",
58+
4: "2001:067c:04e8:f004:0000:0000:0000:000b"
59+
}
60+
61+
def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool, media: bool) -> Tuple[str, int]:
62+
if test_mode:
63+
if ipv6:
64+
ip = cls.TEST_IPV6[dc_id]
65+
else:
66+
ip = cls.TEST[dc_id]
67+
68+
return ip, 80
5969
else:
60-
return (
61-
(cls.TEST[dc_id], 80)
62-
if test_mode
63-
else (cls.PROD[dc_id], 443)
64-
)
70+
if ipv6:
71+
if media:
72+
ip = cls.PROD_IPV6_MEDIA.get(dc_id, cls.PROD_IPV6[dc_id])
73+
else:
74+
ip = cls.PROD_IPV6[dc_id]
75+
else:
76+
if media:
77+
ip = cls.PROD_MEDIA.get(dc_id, cls.PROD[dc_id])
78+
else:
79+
ip = cls.PROD[dc_id]
80+
81+
return ip, 443

pyrogram/session/session.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ async def start(self):
120120
self.dc_id,
121121
self.test_mode,
122122
self.client.ipv6,
123-
self.client.proxy
123+
self.client.proxy,
124+
self.is_media
124125
)
125126

126127
try:

0 commit comments

Comments
 (0)