omniline 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
omniline-0.1/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OkLine contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ NOTE: OkLine is an unofficial, independent project. It is not affiliated with,
26
+ endorsed by, or sponsored by LINE Corporation. "LINE" is a trademark of its
27
+ respective owner. Use it only with your own account and in compliance with
28
+ LINE's Terms of Service.
omniline-0.1/PKG-INFO ADDED
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: omniline
3
+ Version: 0.1
4
+ Summary: User-friendly CLI and terminal UI for LINE Messenger, powered by OkLine.
5
+ Author: Greg Chao-Kuei Hung
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ckhung/OmniLine
8
+ Project-URL: Documentation, https://github.com/ckhung/OmniLine/tree/main/docs
9
+ Project-URL: Repository, https://github.com/ckhung/OmniLine
10
+ Project-URL: Issues, https://github.com/ckhung/OmniLine/issues
11
+ Project-URL: Changelog, https://github.com/ckhung/OmniLine/blob/main/CHANGELOG.md
12
+ Keywords: line,line-messenger,line-api,line-bot,line-messenger-api,line-chrome,line-chrome-extension-api,line-client,line-sdk,python-line,unofficial-line,line-personal-account,line-qr-login,line-login-qr-code,letter-sealing,line-e2ee,e2ee,end-to-end-encryption,line-notify-alternative,linepy-alternative,line-selfbot,line-automation,line-mcp,chatbot,automation,messaging,reverse-engineering,chrome-extension,thrift,x-hmac,okline
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: End Users/Desktop
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Natural Language :: English
17
+ Classifier: Natural Language :: Chinese (Traditional)
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Communications :: Chat
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Classifier: Topic :: Internet :: WWW/HTTP
27
+ Classifier: Typing :: Typed
28
+ Requires-Python: >=3.9
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Requires-Dist: requests>=2.28
32
+ Requires-Dist: cryptography>=41.0
33
+ Requires-Dist: qrcode>=7.0
34
+ Requires-Dist: prompt-toolkit>=3.0.52
35
+ Requires-Dist: wcwidth>=0.9.4
36
+ Requires-Dist: okline>=2.7.0
37
+ Provides-Extra: test
38
+ Requires-Dist: pytest>=7.0; extra == "test"
39
+ Provides-Extra: dev
40
+ Requires-Dist: pytest>=7.0; extra == "dev"
41
+ Requires-Dist: ruff>=0.6; extra == "dev"
42
+ Requires-Dist: mypy>=1.8; extra == "dev"
43
+ Requires-Dist: types-requests; extra == "dev"
44
+ Requires-Dist: pre-commit>=3.5; extra == "dev"
45
+ Requires-Dist: build>=1.0; extra == "dev"
46
+ Requires-Dist: twine>=5.0; extra == "dev"
47
+ Dynamic: license-file
48
+
49
+ # OmniLine
50
+
51
+ OmniLine is a combination of 3 frontends for LINE, a popular messaging app in Taiwan. OmniLine only provides the user interfaces; the underlying heavy work of authentication and communication is provided by [OkLine](https://nicedayzc.github.io/OkLine/) and created by nicedayzc. The 3 frontends are:
52
+ - **omniline cli**: a barebone command line version mostly used for testing
53
+ - **omniline tui**: a terminal user interface more or less usable for text-reading and sending
54
+ - **omniline web**: to be written
55
+
56
+ ## License
57
+
58
+ [MIT](LICENSE)
omniline-0.1/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # OmniLine
2
+
3
+ OmniLine is a combination of 3 frontends for LINE, a popular messaging app in Taiwan. OmniLine only provides the user interfaces; the underlying heavy work of authentication and communication is provided by [OkLine](https://nicedayzc.github.io/OkLine/) and created by nicedayzc. The 3 frontends are:
4
+ - **omniline cli**: a barebone command line version mostly used for testing
5
+ - **omniline tui**: a terminal user interface more or less usable for text-reading and sending
6
+ - **omniline web**: to be written
7
+
8
+ ## License
9
+
10
+ [MIT](LICENSE)
@@ -0,0 +1 @@
1
+ """OmniLine frontends and their shared user-facing models."""
@@ -0,0 +1,78 @@
1
+ """OmniLine frontend dispatch and session lifecycle."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import os
7
+ import sys
8
+ from collections.abc import Sequence
9
+ from pathlib import Path
10
+
11
+ from okline import OkLine
12
+ from okline._util import reconfigure_stdout_utf8
13
+
14
+ from .cli import run_history, run_list
15
+ from .tui import run_tui
16
+
17
+
18
+ def _build_parser() -> argparse.ArgumentParser:
19
+ parser = argparse.ArgumentParser(prog="omniline")
20
+ frontends = parser.add_subparsers(dest="frontend", required=True)
21
+ tui = frontends.add_parser("tui", help="read-only terminal UI")
22
+ tui.add_argument("--tokens-file", default=None, help="session JSON file")
23
+ cli = frontends.add_parser("cli", help="command-line frontend")
24
+ commands = cli.add_subparsers(dest="command", required=True)
25
+
26
+ listing = commands.add_parser("list", help="list friends and groups")
27
+ listing.add_argument("-s", "--sort", choices=("lmtime", "name"), default="name")
28
+ listing.add_argument("--json", action="store_true", help="full JSON output")
29
+ listing.add_argument("--csv", action="store_true", help="short CSV output")
30
+ listing.add_argument("-f", "--full", action="store_true", help="full JSON output")
31
+ listing.add_argument("--tokens-file", default=None, help="session JSON file")
32
+
33
+ history = commands.add_parser("hist", help="dump recent history for one chat")
34
+ history.add_argument("-n", type=int, default=50, help="maximum number of messages")
35
+ history.add_argument("needle", help="substring of a chat MID or display name")
36
+ history.add_argument("--tokens-file", default=None, help="session JSON file")
37
+ return parser
38
+
39
+
40
+ def _token_path(explicit: str | None) -> Path:
41
+ if explicit:
42
+ return Path(explicit)
43
+ for candidate in (Path("tokens.json"), Path("worksp/tokens.json"), Path.home() / "tokens.json"):
44
+ if candidate.exists():
45
+ return candidate
46
+ return Path("tokens.json")
47
+
48
+
49
+ def _main(argv: Sequence[str] | None = None) -> int:
50
+ reconfigure_stdout_utf8()
51
+ args = _build_parser().parse_args(argv)
52
+ assert args.frontend in {"cli", "tui"}, "unsupported skeletal frontend"
53
+
54
+ api = OkLine.from_tokens_file(str(_token_path(args.tokens_file)))
55
+ try:
56
+ assert api.tokens.access_token, "no access token in the session file"
57
+ if args.frontend == "tui":
58
+ return run_tui(api)
59
+ if args.command == "list":
60
+ return run_list(api, args)
61
+ if args.command == "hist":
62
+ return run_history(api, args)
63
+ raise AssertionError("unsupported skeletal command")
64
+ finally:
65
+ api.close()
66
+
67
+
68
+ def main(argv: Sequence[str] | None = None) -> int:
69
+ """Run OmniLine, treating a closed downstream pipe as successful output."""
70
+ try:
71
+ return _main(argv)
72
+ except BrokenPipeError:
73
+ sys.stdout = open(os.devnull, "w", encoding="utf-8") # noqa: SIM115
74
+ return 0
75
+
76
+
77
+ if __name__ == "__main__":
78
+ raise SystemExit(main())
@@ -0,0 +1,129 @@
1
+ """Shared OkLine-backed operations for the three OmniLine frontends."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from okline.entities import Contact, Group
8
+
9
+ from .ufl import uflChat, uflContact, uflGroup, uflMessage
10
+
11
+ MESSAGE_BOX_BATCH_SIZE = 100
12
+
13
+
14
+ def message_boxes_by_id(api: Any, ids: list[str]) -> dict[str, dict[str, Any]]:
15
+ """Fetch listing metadata in bounded batches."""
16
+ boxes: dict[str, dict[str, Any]] = {}
17
+ for start in range(0, len(ids), MESSAGE_BOX_BATCH_SIZE):
18
+ result = api.get_message_boxes_by_ids(
19
+ ids[start : start + MESSAGE_BOX_BATCH_SIZE],
20
+ with_unread_count=True,
21
+ last_messages_count=1,
22
+ )
23
+ assert isinstance(result, dict)
24
+ batch = result.get("messageBoxesByIds", result.get("messageBoxes", {})) or {}
25
+ if isinstance(batch, dict):
26
+ boxes.update({str(mid): box for mid, box in batch.items() if isinstance(box, dict)})
27
+ else:
28
+ boxes.update(
29
+ {
30
+ str(box["id"]): box
31
+ for box in batch
32
+ if isinstance(box, dict) and box.get("id")
33
+ }
34
+ )
35
+ return boxes
36
+
37
+
38
+ def list_chats(api: Any) -> list[uflChat]:
39
+ """Return all contacts and groups as one polymorphic list."""
40
+ contact_ids = api.get_all_contact_ids() or []
41
+ contacts_result = api.get_contacts(contact_ids) if contact_ids else {"contacts": {}}
42
+ assert isinstance(contacts_result, dict)
43
+ contact_data = contacts_result.get("contacts", {})
44
+ assert isinstance(contact_data, dict)
45
+ contact_ids = list(contact_data)
46
+
47
+ all_chats = api.get_all_chat_mids() or {}
48
+ group_ids = list(
49
+ dict.fromkeys(
50
+ (all_chats.get("memberChatMids", []) or [])
51
+ + (all_chats.get("invitedChatMids", []) or [])
52
+ )
53
+ )
54
+ group_result = api.get_chats(group_ids) if group_ids else {"chats": []}
55
+ assert isinstance(group_result, dict)
56
+ group_data = group_result.get("chats", [])
57
+ assert isinstance(group_data, list)
58
+
59
+ boxes = message_boxes_by_id(api, contact_ids + group_ids)
60
+ chats: list[uflChat] = []
61
+ for mid, data in contact_data.items():
62
+ assert isinstance(data, dict)
63
+ chats.append(uflContact.from_okline(Contact.from_dict(data), boxes.get(mid, {})))
64
+ for data in group_data:
65
+ assert isinstance(data, dict)
66
+ group = Group.from_dict(data)
67
+ chats.append(uflGroup.from_okline(group, boxes.get(group.chat_mid, {})))
68
+ return chats
69
+
70
+
71
+ def find_chats(chats: list[uflChat], needle: str) -> list[uflChat]:
72
+ """Match a substring against the exact MID or display name."""
73
+ return [chat for chat in chats if needle in chat.id or needle in chat.name]
74
+
75
+
76
+ def resolve_contact_names(api: Any, mids: list[str]) -> dict[str, str]:
77
+ """Resolve sender MIDs through ``getContactsV2`` display-name fields."""
78
+ if not mids:
79
+ return {}
80
+ result = api.get_contacts(mids)
81
+ assert isinstance(result, dict)
82
+ contacts = result.get("contacts", {})
83
+ assert isinstance(contacts, dict)
84
+ names: dict[str, str] = {}
85
+ for mid, data in contacts.items():
86
+ assert isinstance(data, dict)
87
+ name = Contact.from_dict(data).name
88
+ if name:
89
+ names[str(mid)] = name
90
+ return names
91
+
92
+
93
+ def refresh_unread_counts(api: Any, chats: list[uflChat]) -> None:
94
+ """Refresh unread counts and latest timestamps without rebuilding chats."""
95
+ boxes = message_boxes_by_id(api, [chat.id for chat in chats])
96
+ for chat in chats:
97
+ box = boxes.get(chat.id, {})
98
+ chat.unread_count = chat.unread_from_box(box)
99
+ chat.last_message_time = chat.last_time_from_box(box)
100
+
101
+
102
+ def mark_chat_read(api: Any, chat: uflChat, messages: list[uflMessage]) -> None:
103
+ """Mark the selected chat read through its newest retrieved message."""
104
+ readable = [message for message in messages if message.id]
105
+ if not readable:
106
+ return
107
+ latest = max(readable, key=lambda message: message.created_time or -1)
108
+ api.send_chat_checked(chat.id, last_message_id=latest.id)
109
+ chat.unread_count = 0
110
+
111
+
112
+ def recent_messages(api: Any, chat: uflChat, count: int) -> list[uflMessage]:
113
+ """Fetch one recent page and decrypt sealed messages when possible."""
114
+ raw_messages = api.get_recent_messages(chat.id, count=count) or []
115
+ messages: list[uflMessage] = []
116
+ for raw in raw_messages:
117
+ assert isinstance(raw, dict)
118
+ decoded = raw
119
+ if raw.get("chunks"):
120
+ try:
121
+ decoded = api.decrypt_message(raw)
122
+ except Exception:
123
+ decoded = dict(raw)
124
+ decoded["text"] = "[encrypted]"
125
+ message = uflMessage.from_okline(decoded)
126
+ if decoded is not raw and decoded.get("text") != "[encrypted]":
127
+ message.raw.pop("chunks", None)
128
+ messages.append(message)
129
+ return messages
@@ -0,0 +1,69 @@
1
+ """Command-line rendering and command handlers shared by future frontends."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import csv
6
+ import json
7
+ import sys
8
+ from argparse import Namespace
9
+ from typing import Any
10
+
11
+ from .chat_service import find_chats, list_chats, recent_messages
12
+ from .ufl import sort_chats, uflChat
13
+
14
+
15
+ def write_csv(chats: list[uflChat], stream: Any = sys.stdout) -> None:
16
+ """Write the compact conversation listing."""
17
+ out = csv.writer(stream, lineterminator="\n")
18
+ out.writerow(["id", "name", "kind", "last_message_time", "unread_count"])
19
+ for chat in chats:
20
+ out.writerow([
21
+ chat.id,
22
+ chat.name,
23
+ chat.kind,
24
+ chat.last_message_time,
25
+ "" if chat.unread_count is None else chat.unread_count,
26
+ ])
27
+
28
+
29
+ def write_json(chats: list[uflChat], stream: Any = sys.stdout) -> None:
30
+ json.dump([chat.to_dict(full=True) for chat in chats], stream, ensure_ascii=False)
31
+ stream.write("\n")
32
+
33
+
34
+ def write_matching_chats(chats: list[uflChat], stream: Any = sys.stdout) -> None:
35
+ """Write ambiguous matches without retrieving their histories."""
36
+ out = csv.writer(stream, lineterminator="\n")
37
+ for chat in chats:
38
+ out.writerow([chat.id, chat.name])
39
+
40
+
41
+ def write_history(messages: list[Any], stream: Any = sys.stdout) -> None:
42
+ for message in messages:
43
+ json.dump(message.to_dict(), stream, ensure_ascii=False)
44
+ stream.write("\n")
45
+
46
+
47
+ def run_list(api: Any, args: Namespace, stream: Any = sys.stdout) -> int:
48
+ assert not ((args.json or args.full) and args.csv), "--json/--full and --csv conflict"
49
+ chats = sort_chats(list_chats(api))
50
+ if args.sort == "name":
51
+ chats = sorted(chats, key=lambda chat: (chat.name.casefold(), chat.id))
52
+ if args.json or args.full:
53
+ write_json(chats, stream)
54
+ else:
55
+ write_csv(chats, stream)
56
+ return 0
57
+
58
+
59
+ def run_history(api: Any, args: Namespace, stream: Any = sys.stdout, error: Any = sys.stderr) -> int:
60
+ assert args.n >= 1, "-n must be positive"
61
+ matches = find_chats(list_chats(api), args.needle)
62
+ if not matches:
63
+ print(f'no chat matches "{args.needle}"', file=error)
64
+ return 1
65
+ if len(matches) > 1:
66
+ write_matching_chats(matches, stream)
67
+ return 0
68
+ write_history(recent_messages(api, matches[0], args.n), stream)
69
+ return 0