TGConvertor

repository·master·Indexed 41 days ago

https://github.com/nazar220160/tgconvertor

A utility module and CLI tool for converting Telegram authorization sessions between various formats, including Telethon, Pyrogram, Kurigram, and Telegram Desktop (tdata). Version 0.1.4 supports session conversion via files or strings and provides a SessionManager Python API for programmatic access.

Tokens
1.5K
Snippets
7
Records
11
Agent score
50%

What's inside TGConvertor

  1. How TGConvertor works

    master
    TGConvertor operates by extracting the authorization key and necessary connection data from an existing Telegram session. It then creates an instance of a TelegramSession object based on this data. This object provides a high-level interface to export that session data into various supported formats (Telethon, Pyrogram, Kurigram, or Tdata).
  2. Convert Telegram sessions via CLI

    master

    Use the convert command to transform sessions. You must specify the source format (-f), the target format (-t), and the output destination (-o).

    Conversion Scenarios

    ScenarioCommand Example
    File to Filetgconvertor convert session.session -f telethon -t pyrogram -o new_session.session
    String to Filetgconvertor convert "1:AAFqwer..." -f telethon -t pyrogram -o session.session
    File to Stringtgconvertor convert session.session -f telethon -t pyrogram -o string
    String to Stringtgconvertor convert "1:AAFqwer..." -f telethon -t pyrogram -o string
    String to tdatatgconvertor convert "1:AAFqwer..." -f telethon -t tdata -o tdata_folder
    tdata to Stringtgconvertor convert tdata_folder/tdata -f tdata -t telethon -o string

    Specifying API Types

    You can specify the client API type using the --api flag. Supported values are:

    • desktop (default)
    • android
    • ios
    • macos
    • web

    Example: tgconvertor convert session.session -f telethon -t pyrogram --api android

    # Convert from file to file
    tgconvertor convert session.session -f telethon -t pyrogram -o new_session.session
  3. Install TGConvertor

    master

    Install the base package using pip. You can also install optional dependencies for specific format support using extras:

    • For Pyrogram support: pip install TGConvertor[pyrogram]
    • For Kurigram support: pip install TGConvertor[kurigram]
    $ pip install TGConvertor[pyrogram]
    # OR
    $ pip install TGConvertor[kurigram]
  4. Use the SessionManager Python API

    master

    For programmatic access, use the SessionManager class from the TGConvertor module. The workflow involves creating a session instance from a source and then calling a conversion method.

    Note: Some methods are asynchronous and require await.

    from TGConvertor import SessionManager
    
    # Convert from string (Synchronous example)
    session = SessionManager.from_pyrogram_string('session_str')
    print(session.to_pyrogram_string())
    
    # Convert from file (Asynchronous example)
    import asyncio
    
    async def main():
        # Convert from file
        session = await SessionManager.from_telethon_file('session.session')
        await session.to_pyrogram_file('new_session.session')
    
    asyncio.run(main())
  5. Reference: Supported Formats and API Types

    master

    Supported Formats

    • telethon: Telethon session files (.session)
    • pyrogram: Pyrogram session files (.session)
    • tdata: Telegram Desktop format (directory)

    API Types

    • desktop: Telegram Desktop client (default)
    • android: Telegram Android client
    • ios: Telegram iOS client
    • macos: Telegram macOS client
    • web: Telegram Web client
  6. Inspect session information via CLI

    master

    Use the info command to view details of an existing session. You must provide the input path and the format (-f).

    # Show Telethon session info
    tgconvertor info session.session -f telethon
    
    # Show Pyrogram session info
    tgconvertor info my_session.session -f pyrogram
    tgconvertor info session.session -f telethon
  7. Use the TGConvertor CLI

    master

    The tgconvertor command-line tool allows you to convert Telegram sessions between different formats and inspect session details.

    Available Commands

    • tgconvertor --help: Show help and available commands.
    • tgconvertor list-formats: List all supported formats and API types.
    • tgconvertor convert <input> ...: The primary command for session conversion.
    • tgconvertor info <input> ...: Inspect session details.
    tgconvertor --help
    tgconvertor list-formats
  8. Display information about a Telegram session

    master

    Use the info command to inspect a session file and view its metadata, such as DC ID, User ID, Phone number, and validity status.

    Arguments

    • session_path: The path to the session file or directory.

    Options

    • --format, -f: The format of the session (telethon, pyrogram, or tdata).
    # Show Telethon session info
    tgconvertor info session.session -f telethon
    
    # Show Pyrogram session info
    tgconvertor info my_session.session -f pyrogram