File size: 3,304 Bytes
18b952c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python3
"""
Session String Generator for Telegram Multi-Part File Streamer
Generates Pyrogram session strings for multi-session load balancing
"""

import asyncio
import sys
from pyrogram import Client


async def generate_session_string():
    """Generate a Pyrogram session string"""
    print("=" * 60)
    print("Telegram Session String Generator")
    print("=" * 60)
    print()
    
    # Get credentials
    try:
        api_id = input("Enter your API_ID: ").strip()
        if not api_id:
            print("❌ API_ID is required!")
            return
        
        api_id = int(api_id)
        
        api_hash = input("Enter your API_HASH: ").strip()
        if not api_hash:
            print("❌ API_HASH is required!")
            return
        
        print()
        print("πŸ” Credentials validated!")
        print()
        print("πŸ“± You will now receive a code on your Telegram app.")
        print("   Please enter the code when prompted.")
        print()
        
    except ValueError:
        print("❌ Invalid API_ID! Must be a number.")
        return
    except KeyboardInterrupt:
        print("\n\n❌ Cancelled by user.")
        return
    
    # Create client
    client = Client(
        name="session_generator",
        api_id=api_id,
        api_hash=api_hash,
        in_memory=True
    )
    
    try:
        # Start client (will prompt for phone number and code)
        await client.start()
        
        # Get session string
        session_string = await client.export_session_string()
        
        # Get user info
        me = await client.get_me()
        
        print()
        print("=" * 60)
        print("βœ… Session String Generated Successfully!")
        print("=" * 60)
        print()
        print(f"πŸ‘€ Account: {me.first_name} {me.last_name or ''}")
        print(f"πŸ“ž Phone: +{me.phone_number}")
        print(f"πŸ†” Username: @{me.username or 'N/A'}")
        print()
        print("πŸ“‹ Session String:")
        print("-" * 60)
        print(session_string)
        print("-" * 60)
        print()
        print("⚠️  IMPORTANT:")
        print("   1. Keep this session string PRIVATE and SECURE")
        print("   2. Anyone with this string can access your account")
        print("   3. Add this to SESSION_STRINGS in your .env file")
        print("   4. You can generate multiple session strings for")
        print("      load balancing (comma-separated)")
        print()
        print("πŸ’‘ Example .env configuration:")
        print("-" * 60)
        print(f"SESSION_STRINGS={session_string},YOUR_SECOND_SESSION_STRING")
        print("-" * 60)
        print()
        
        # Stop client
        await client.stop()
        
    except Exception as e:
        print(f"\n❌ Error: {str(e)}")
        if "PASSWORD" in str(e).upper():
            print("\n⚠️  Your account has 2FA enabled.")
            print("   Please enter your password when prompted.")
        return
    
    finally:
        if client.is_connected:
            await client.stop()


def main():
    """Main function"""
    try:
        asyncio.run(generate_session_string())
    except KeyboardInterrupt:
        print("\n\n❌ Cancelled by user.")
        sys.exit(1)


if __name__ == "__main__":
    main()