Giter Site home page Giter Site logo

tgmount's Introduction

Overview

The main purpose of the program is to make audio files posted on Telegram available to regular desktop audio players. This is done via VFS by mapping remote files from telegram's cloud to local file system. Tested with audio players quodlibet, deadbeef, clementine.

This version is not maintained anymore. Use new version instead https://github.com/nktknshn/tgmount-ng

Libraries used

Running

$ virtualenv .venv3.7 -p python3.7
$ source .venv3.7/bin/activate
$ pip install -r requirements.txt
$ python tgmount/tgmount.py --list-dialogs

Usage

To obtain your API id follow official manual. Running the program for the first time will require authentication.

$ export TGAPP=1234567:deadbeef0d04a3efe93e1af778773d6f0

Print your dialogs along with their numeric id's:

$ tgmount.py --list-dialogs

Print 10 newest available documents:

$ tgmount.py --list-documents --id 793392913 --limit 10

Print 10 oldest available documents:

$ tgmount.py --list-documents --id 793392913 --limit 10 --reverse

Using global telegram username:

$ tgmount.py --list-documents --id techtroit --limit 10 --reverse

Json output:

$ tgmount.py --list-documents --id techtroit --limit 10 --json

Mount channel techtroit to /mnt/techtroit/ loading all the audio files posted after message with id 11286

$ tgmount.py --mount /mnt/techtroit/ --id techtroit --offset 11286 --reverse

Download files

$ tgmount.py --download /ssd/tgfs/download/ --id techtroit --files 11823,11822

Download all files uploaded after message with id 11837

$ tgmount.py --download /ssd/tgfs/download/ --id techtroit --files $(tgmount.py --list-documents --id techtroit --offset-id 11837 --reverse --json | jq -r 'map(.message_id) | join(",")')

More options:

usage: tgmount.py [-h] [--id ID] [--mount DIR] [--list-dialogs]
                  [--list-documents] [--download DIR] [--files FILES]
                  [--all-files] [--no-updates] [--reverse] [--limit LIMIT]
                  [--offset-id OFFSET_ID] [--session SESSION]
                  [--fsname FSNAME] [--socks SOCKS] [--debug] [--debug-fuse]
                  [--json]

optional arguments:
  -h, --help            show this help message and exit
  --id ID               chat or channel ID. Telegram username or numeric ID
  --mount DIR           mount to DIR
  --list-dialogs        print available telegram dialogs
  --list-documents      print available documents
  --download DIR        save files to DIR. Use with --files parameter
  --files FILES         comma separated list of document IDs
  --all-files           Retrieve all type of files, not only audio files.
                        Default: no
  --no-updates          don't listen for new files. Default: no
  --reverse             documents will be searched in reverse order (from
                        oldest to newest). Default: from newest to oldest
  --limit LIMIT         limit number of documents or dialogs. default:
                        unlimited
  --offset-id OFFSET_ID
                        offset message ID. Only documents previous to the
                        given ID will be retrieved
  --session SESSION     telegram session name. Default: tgfs
  --fsname FSNAME       VFS name. Default: tgfs
  --socks SOCKS         SOCKS5 proxy i.e. 127.0.0.1:9050
  --debug               enable debugging output
  --debug-fuse          enable FUSE debugging output
  --json                json output. Default: no

tgmount's People

Contributors

juniorjpdj avatar nktknshn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tgmount's Issues

Bot support

Hi,
I tried logging in as bot, when I found out that there's no way, I tried to put already logged in bot session to bot, but it failed:

$ ./tgmount.py --id -1001410674750 --list-documents                                                                                                                                                         
Traceback (most recent call last):
  File "./tgmount.py", line 209, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "./tgmount.py", line 70, in main
    await list_documents(await client(),
  File "/home/juniorjpdj/dev/tgmount/tgmount/tgmount/functions.py", line 50, in list_documents
    documents = await client.get_documents(entity,
  File "/home/juniorjpdj/dev/tgmount/tgmount/tgmount/tgclient.py", line 313, in get_documents
    [messages, documents] = await self._get_documents(entity,
  File "/home/juniorjpdj/dev/tgmount/tgmount/tgmount/tgclient.py", line 292, in _get_documents
    messages = await self.get_messages(entity, limit=limit, offset_id=offset_id, reverse=reverse,
  File "/usr/lib/python3.8/site-packages/telethon/client/messages.py", line 531, in get_messages
    return await it.collect()
  File "/usr/lib/python3.8/site-packages/telethon/requestiter.py", line 113, in collect
    async for message in self:
  File "/usr/lib/python3.8/site-packages/telethon/requestiter.py", line 74, in __anext__
    if await self._load_next_chunk():
  File "/usr/lib/python3.8/site-packages/telethon/client/messages.py", line 165, in _load_next_chunk
    r = await self.client(self.request)
  File "/usr/lib/python3.8/site-packages/telethon/client/users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "/usr/lib/python3.8/site-packages/telethon/client/users.py", line 77, in _call
    result = await future
telethon.errors.rpcerrorlist.BotMethodInvalidError: The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by SearchRequest)

Also when I tried to mount:

./tgmount.py --id -1001410674750 --mount ./dir --debug --debug-fuse                                                                                                                                         46.175.44.195   93%  ─╯
DEBUG   [root]  Namespace(all_files=False, debug=True, debug_fuse=True, download=None, files=[], fsname='tgfs', id='-1001410674750', json=False, limit=None, list_dialogs=False, list_documents=False, mount='./dir', no_updates=False, offset_id=0, reverse=False, session='tgfs', socks=None)
DEBUG   [tgclient]      Connecting to Telegram servers...
INFO    [telethon.network.mtprotosender]        Connecting to 149.154.167.92:443/TcpFull...
INFO    [telethon.network.mtprotosender]        Connection to 149.154.167.92:443/TcpFull complete!
DEBUG   [tgclient]      Connected
DEBUG   [pyfuse3]       Calling fuse_session_unmount
[1]    143926 segmentation fault (core dumped)  ./tgmount.py --id -1001410674750 --mount ./dir --debug --debug-fuse

TypeError: 'Message' object is not subscriptable

$ python3 tgmount.py --download /tmp/files/ --id blahblah --files 17525,17526
INFO    [root]  Download files [17525, 17526] from blahblah to /tmp/files/
Traceback (most recent call last):
  File "tgmount.py", line 168, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "tgmount.py", line 81, in main
    await download(await client(),
  File "/home/media/tgmount/tgmount/tgmount/actions.py", line 156, in download
    ([d['attributes']['file_name'] for m, d in documents],))
  File "/home/media/tgmount/tgmount/tgmount/actions.py", line 156, in <listcomp>
    ([d['attributes']['file_name'] for m, d in documents],))
TypeError: 'Message' object is not subscriptable

Blocks any reads after few hours of operation

I'm having weird problem.
Everything works at least good at start and few hours later, but at some moment reads just block.
No network activity is observed after file open, read of old files is just stuck. New files are working good.

Sometimes file's are corrupted

I cannot really say when it happens, but it happens.
The same file downloads with errors and then after some time - correctly.
I can hear it in music player, it looks like it downloads the same file part or chunk two times and returns it twice.

Eg. I'm listening to music and after some time there's glitched part: It plays again the same part of track second time or skips some fragment (very short, fraction of second, but disturbing).
When I listen close player and play this track again, there's no glitch anymore.

Block on file open request

Hi,
When I try to open file there's infinite (or just long enough for me to stop waiting) block of any program trying to do so.
Not even reading file, just opening.
There's an example:
Screenshot_20200816_010417

ZIP file as directory support

Me and my friends are sharing music with each other, but when we share albums - those are ZIPed.
What if your filesystem could mount those ZIP files as directories in filesystem?
There's very easy to use Zipfile lib in python stdlib.

Could not find the input entity for PeerUser

Unfortunately, it is throwing up an error.

$ python3 tgmount.py --list-documents --id 793392913 --limit 10
Traceback (most recent call last):
  File "tgmount.py", line 168, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "tgmount.py", line 59, in main
    await list_documents(await client(),
  File "/home/media/tgmount/tgmount/tgmount/actions.py", line 39, in list_documents
    entity = await client.get_entity(id)
  File "/home/media/.local/lib/python3.8/site-packages/telethon/client/users.py", line 292, in get_entity
    inputs.append(await self.get_input_entity(x))
  File "/home/media/.local/lib/python3.8/site-packages/telethon/client/users.py", line 466, in get_input_entity
    raise ValueError(
ValueError: Could not find the input entity for PeerUser(user_id=793392913) (PeerUser). Please read https://docs.telethon.dev/en/stable/concepts/entities.html to find out more details.

timeout raises IOError

Screenshot_20210507_145313

$ cp flaczkownia/66556\ DJ\ Wielki\ Huj\ -\ Halloween\ EP\ 2\ \(2018\).zip .
cp: error reading 'flaczkownia/66556 DJ Wielki Huj - Halloween EP 2 (2018).zip': Input/output error

Could you add a way to retry on timeout and make retries amount configurable?
I can't use it right now as it breaks everything when telegram is lagging a bit.

Keep the same naming scheme

Hi!
I'm trying to automate detection of new files posted on group I mounted.
The problem is your filenames are not consistent.

def message_doc_filename_format(msg: Message, doc: TgmountDocument):
attr_file_name = doc.atrributes.get('file_name')
if attr_file_name:
return ("%s %s" % (msg.id, attr_file_name)).encode()
else:
return ("msg_%s_doc" % msg.id).encode()

Could you please always prepend your names with ID, not make special case when name starts with msg and ID is somewhere inside? It will also fix sorting of files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.