Skip to content

Commit c2d880a

Browse files
committed
Switch ascii media player to custom treminal graphics
Add option to draw media with box characters Reduce RAM usage in full version Optimize media player Fix failing slow uploads Fix crash when loading dms Fix crash when canceling upload Set user ownership to profiles.json Add new screenshot Prevent sending message while attachments are still uploading Cleanup mess with paths Remove record audio message binding
1 parent 37fa444 commit c2d880a

File tree

20 files changed

+721
-447
lines changed

20 files changed

+721
-447
lines changed

.github/screenshots.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<b>Viewing user profile:<b><br>
2525
<img src="./screenshots/05.png" alt="Viewing user profile" width="800">
2626
<br><br>
27-
<b>Video in built-in ASCII art media player:<b><br>
27+
<b>Video in built-in media player using "block" characters:<b><br>
2828
<img src="./screenshots/06.png" alt="Media with ASCII art" width="800">
29+
<br><br>
30+
<b>Video in built-in media player using ASCII art:<b><br>
31+
<img src="./screenshots/07.png" alt="Media with ASCII art" width="800">
2932
</div>

.github/screenshots/06.png

-129 KB
Loading

.github/screenshots/07.png

143 KB
Loading

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Scroll back to bottom - `Ctrl+H`
157157
Expand selected categories and servers - `Ctrl+Space` *
158158
Enter selected channel - `Ctrl+Space`
159159
Reply to selected message - `Ctrl+R`
160+
Add reaction to selected message - `Alt+R`
160161
Edit selected message - `Ctrl+E`
161162
Delete selected message - `Ctrl+D`
162163
Toggle reply ping when replying - `Ctrl+P`
@@ -583,6 +584,6 @@ Go to [TODO](todo.txt).
583584

584585
### Features that will not be added
585586
Following features have significant risk of triggering discords spam filter, and may cause account to be limited or even banned:
586-
Sending friend request, opening new DM, creating new thread, scriptable command macros, anything payment related.
587+
Sending friend request, opening new DM, creating new thread, anything payment related.
587588

588589
Therefore, they will NOT be implemented in endcord.

configuration.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,15 @@ Note: always put string in `""`. To use `"` inside the string escape it like thi
268268
Characters used to draw corners in bordered mode.
269269
- `username_role_colors = True`
270270
Allow `%username` and `%global_name` to have color of primary role.
271+
- `media_use_blocks = False`
272+
Wether to use "block" characters (``) for drawing media instead traditional characters from media_ascii_palette.
273+
This will result in clearer picture with pixel-like characters, vertical resolution will be doubled.
274+
media_ascii_palette and media_saturation have no effect when this is ON.
271275
- `media_ascii_palette = " ..',;:c*loexk#O0XNW"`
272276
Characters used to draw in terminal. From darkest to brightest. Same character can be repeated. Number of characters is not fixed.
273277
- `media_saturation = 1.2`
274278
Saturation correction applied to image in order to make colors more visible. Adjust if changing `ascii_palette` or media_color_bg.
275-
- `media_font_scale = 2.25`
279+
- `media_font_aspect_ratio = 2.25`
276280
Font height/width ratio. Change only if picture dimensions ratio is wrong in terminal.
277281

278282
### Colors and attributes

endcord/app.py

Lines changed: 108 additions & 118 deletions
Large diffs are not rendered by default.

endcord/defaults.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@
151151
"color_chat_url": [153, -1, "u"],
152152
"color_chat_spoiler": [245, -1],
153153
"color_chat_code": [250, 233],
154+
"media_use_blocks": True,
154155
"media_ascii_palette": " ..',;:c*loexk#O0XNW",
155156
"media_saturation": 1.2,
156-
"media_font_scale": 2.25,
157+
"media_font_aspect_ratio": 2.25,
157158
"media_color_bg": 16,
158159
"media_bar_ch": "━",
159160
}
@@ -199,9 +200,8 @@
199200
"show_summaries": "ALT+115", # Alt+S
200201
"copy_message_link": "ALT+117", # Alt+U
201202
"go_channel": "ALT+103", # Alt+G
202-
"add_reaction": 12, # Ctrl+L
203+
"add_reaction": "ALT+114", # Alt+R
203204
"search_gif": "ALT+102", # Alt+F
204-
"record_audio": "ALT+114", # Alt+R
205205
"show_reactions": "ALT+119", # Alt+W
206206
"show_pinned": "ALT+110", # Alt+N
207207
# extra line

endcord/discord.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def get_file_id(self, url):
149149
return None
150150

151151

152-
def get_connection(self, host, port):
152+
def get_connection(self, host, port, timeout=10):
153153
"""Get connection object and handle proxying"""
154154
if self.proxy.scheme:
155155
if self.proxy.scheme.lower() == "http":
@@ -164,12 +164,12 @@ def get_connection(self, host, port):
164164
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
165165
proxy_sock = ssl_context.wrap_socket(proxy_sock, server_hostname=host)
166166
# proxy_sock.do_handshake() # seems like its not needed
167-
connection = http.client.HTTPSConnection(host, port, timeout=10)
167+
connection = http.client.HTTPSConnection(host, port, timeout=timeout + 5)
168168
connection.sock = proxy_sock
169169
else:
170170
connection = http.client.HTTPSConnection(host, port)
171171
else:
172-
connection = http.client.HTTPSConnection(host, port, timeout=5)
172+
connection = http.client.HTTPSConnection(host, port, timeout=timeout)
173173
return connection
174174

175175

@@ -1646,13 +1646,16 @@ def upload_attachment(self, upload_url, path):
16461646
upload_url_path = f"{url.path}?{url.query}"
16471647
with open(path, "rb") as f:
16481648
try:
1649-
connection = self.get_connection(url.netloc, 443)
1649+
connection = self.get_connection(url.netloc, 443, timeout=120)
16501650
self.uploading.append((upload_url, connection))
16511651
connection.request("PUT", upload_url_path, f, header)
16521652
response = connection.getresponse()
1653-
self.uploading.remove((upload_url, connection))
1653+
if (upload_url, connection) in self.uploading:
1654+
self.uploading.remove((upload_url, connection))
16541655
except (socket.gaierror, TimeoutError):
16551656
connection.close()
1657+
return False
1658+
except OSError: # canceled upload
16561659
return None
16571660
if response.status == 200:
16581661
connection.close()
@@ -1674,7 +1677,7 @@ def cancel_uploading(self, url=None):
16741677
for upload in self.uploading:
16751678
upload_url, connection = upload
16761679
try:
1677-
connection.sock.shutdown()
1680+
connection.sock.shutdown(socket.SHUT_RDWR)
16781681
connection.sock.close()
16791682
except Exception:
16801683
logger.debug("Cancel upload: upload socket already closed.")

endcord/downloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, proxy=None):
3737
def download(self, url, file_id=None):
3838
"""Thread that downloads file and stores it in temp folder"""
3939
if not os.path.exists(os.path.expanduser(peripherals.temp_path)):
40-
os.makedirs(os.path.expanduser(os.path.dirname(os.path.expanduser(peripherals.temp_path))), exist_ok=True)
40+
os.makedirs(os.path.dirname(os.path.expanduser(peripherals.temp_path)), exist_ok=True)
4141
url_object = urllib.parse.urlsplit(url)
4242
filename = os.path.basename(url_object.path)
4343
proxy = urllib.parse.urlsplit(self.proxy)

endcord/game_detection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def get_user_processes_diff_darwin():
219219

220220
def find_detectable_apps_file(directory):
221221
"""Find detectable_apps_[etag].ndjson path and extract etag"""
222-
pattern = os.path.join(directory, "detectable_apps_*.ndjson")
222+
pattern = os.path.expanduser(os.path.join(directory, "detectable_apps_*.ndjson"))
223223
matches = glob.glob(pattern)
224224
if not matches:
225225
return None, None
@@ -296,7 +296,7 @@ def main(self):
296296
return
297297

298298
# download new detectable apps list if resource changed on the server
299-
old_path, old_etag = find_detectable_apps_file(os.path.expanduser(peripherals.config_path))
299+
old_path, old_etag = find_detectable_apps_file(peripherals.config_path)
300300
path, etag = self.discord.get_detectable_apps(peripherals.config_path, old_etag)
301301
if not path:
302302
logger.info("Could not start game detection service: failed to download detectable applications list")

0 commit comments

Comments
 (0)