GameSentenceMiner 2.12.1__py3-none-any.whl → 2.12.3__py3-none-any.whl

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.
@@ -139,6 +139,16 @@ class ConfigApp:
139
139
  self.ai_tab = None
140
140
  self.advanced_tab = None
141
141
  self.wip_tab = None
142
+ self.monitors = []
143
+
144
+ try:
145
+ import mss as mss
146
+ self.monitors = [f"Monitor {i}: width: {monitor['width']}, height: {monitor['height']}" for i, monitor in enumerate(mss.mss().monitors[1:], start=1)]
147
+ print(self.monitors)
148
+ if len(self.monitors) == 0:
149
+ self.monitors = [1]
150
+ except ImportError:
151
+ self.monitors = []
142
152
 
143
153
  self.create_tabs()
144
154
 
@@ -375,7 +385,8 @@ class ConfigApp:
375
385
  ),
376
386
  wip=WIP(
377
387
  overlay_websocket_port=int(self.overlay_websocket_port.get()),
378
- overlay_websocket_send=self.overlay_websocket_send.get()
388
+ overlay_websocket_send=self.overlay_websocket_send.get(),
389
+ monitor_to_capture=self.monitor_to_capture.current()
379
390
  )
380
391
  )
381
392
 
@@ -1743,6 +1754,19 @@ class ConfigApp:
1743
1754
  row=self.current_row, column=1, sticky='W', pady=2)
1744
1755
  self.current_row += 1
1745
1756
 
1757
+ HoverInfoLabelWidget(wip_frame, text="Monitor to Capture:",
1758
+ tooltip="Select the monitor to capture (1-based index).",
1759
+ row=self.current_row, column=0)
1760
+ self.monitor_to_capture = ttk.Combobox(wip_frame, values=self.monitors, state="readonly")
1761
+
1762
+ # set index of monitor to capture, not the string
1763
+ if self.monitors:
1764
+ self.monitor_to_capture.current(self.settings.wip.monitor_to_capture)
1765
+ else:
1766
+ self.monitor_to_capture.set("OwOCR Not Detected")
1767
+ self.monitor_to_capture.grid(row=self.current_row, column=1, sticky='EW', pady=2)
1768
+ self.current_row += 1
1769
+
1746
1770
  self.add_reset_button(wip_frame, "wip", self.current_row, 0, self.create_wip_tab)
1747
1771
 
1748
1772
  for col in range(2):
@@ -10,7 +10,9 @@ from GameSentenceMiner.util.gsm_utils import do_text_replacements, TEXT_REPLACEM
10
10
  from GameSentenceMiner.util.configuration import *
11
11
  from GameSentenceMiner.util.text_log import *
12
12
  from GameSentenceMiner.web.texthooking_page import add_event_to_texthooker, send_word_coordinates_to_overlay, overlay_server_thread
13
- from GameSentenceMiner.wip import get_overlay_coords
13
+
14
+ if get_config().wip.overlay_websocket_send:
15
+ import GameSentenceMiner.wip.get_overlay_coords as get_overlay_coords
14
16
 
15
17
  current_line = ''
16
18
  current_line_after_regex = ''
@@ -135,7 +137,7 @@ async def find_box_for_sentence(sentence):
135
137
  boxes = []
136
138
  logger.info(f"Finding Box for Sentence: {sentence}")
137
139
  boxes, font_size = await get_overlay_coords.find_box_for_sentence(sentence)
138
- logger.info(f"Found Boxes: {boxes}, Font Size: {font_size}")
140
+ # logger.info(f"Found Boxes: {boxes}, Font Size: {font_size}")
139
141
  # if boxes:
140
142
  # x1, y1, x2, y2 = box
141
143
  # boxes.append({'sentence': sentence, 'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2, 'fontSize': font_size})
GameSentenceMiner/obs.py CHANGED
@@ -383,7 +383,33 @@ def get_screenshot_base64(compression=75, width=None, height=None):
383
383
  except Exception as e:
384
384
  logger.error(f"Error getting screenshot: {e}")
385
385
  return None
386
+
386
387
 
388
+ def get_screenshot_PIL(compression=75, img_format='png', width=None, height=None, retry=3):
389
+ import io
390
+ import base64
391
+ from PIL import Image
392
+ while True:
393
+ response = client.get_source_screenshot(name=get_current_game(), img_format=img_format, quality=compression, width=width, height=height)
394
+ try:
395
+ response.image_data = response.image_data.split(',', 1)[-1] # Remove data:image/png;base64, prefix if present
396
+ except AttributeError:
397
+ retry -= 1
398
+ if retry <= 0:
399
+ logger.error(f"Error getting screenshot: {response}")
400
+ return None
401
+ continue
402
+ if response and response.image_data:
403
+ image_data = response.image_data.split(',', 1)[-1] # Remove data:image/png;base64, prefix if present
404
+ image_data = base64.b64decode(image_data)
405
+ img = Image.open(io.BytesIO(image_data)).convert("RGBA")
406
+ # if width and height:
407
+ # img = img.resize((width, height), Image.Resampling.LANCZOS)
408
+ return img
409
+ return None
410
+
411
+
412
+
387
413
 
388
414
  def update_current_game():
389
415
  gsm_state.current_game = get_current_scene()
@@ -433,8 +459,31 @@ def main():
433
459
  disconnect_from_obs()
434
460
 
435
461
  if __name__ == '__main__':
462
+ from mss import mss
436
463
  logging.basicConfig(level=logging.INFO)
437
464
  # main()
438
465
  connect_to_obs_sync()
439
- print(get_screenshot_base64(compression=75, width=1280, height=720))
466
+ i = 100
467
+ # for i in range(1, 100):
468
+ print(f"Getting screenshot {i}")
469
+ start = time.time()
470
+ # get_screenshot(compression=95)
471
+ # get_screenshot_base64(compression=95, width=1280, height=720)
472
+ img = get_screenshot_PIL(compression=i, img_format='png')
473
+ end = time.time()
474
+ print(f"Time taken to get screenshot with compression {i}: {end - start} seconds")
475
+ img.show()
476
+
477
+
478
+ start = time.time()
479
+ with mss() as sct:
480
+ monitor = sct.monitors[1]
481
+ sct_img = sct.grab(monitor)
482
+ img = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')
483
+ img.show()
484
+ end = time.time()
485
+ print(f"Time taken to get screenshot with mss: {end - start} seconds")
486
+
487
+
488
+ # print(get_screenshot_base64(compression=75, width=1280, height=720))
440
489
 
@@ -529,6 +529,7 @@ class Ai:
529
529
  class WIP:
530
530
  overlay_websocket_port: int = 55499
531
531
  overlay_websocket_send: bool = False
532
+ monitor_to_capture: int = 0
532
533
 
533
534
 
534
535
 
@@ -108,11 +108,24 @@ async def get_full_screenshot() -> Image.Image | None:
108
108
 
109
109
  logger.info("Getting Screenshot from OBS")
110
110
  try:
111
- update_current_game()
111
+ import mss as mss
112
112
  start_time = time.time()
113
- image_data = get_screenshot_base64(compression=75, width=1280, height=720)
114
- image_data = base64.b64decode(image_data)
115
- img = Image.open(io.BytesIO(image_data)).convert("RGBA").resize((WIDTH, HEIGHT), Image.Resampling.LANCZOS)
113
+ with mss.mss() as sct:
114
+ monitors = sct.monitors
115
+ if len(monitors) > 1:
116
+ monitors = monitors[1:]
117
+ else:
118
+ monitors = [monitors[0]]
119
+ monitor = monitors[get_config().wip.monitor_to_capture]
120
+ sct_img = sct.grab(monitor)
121
+ img = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')
122
+ # img.show()
123
+ return img
124
+ # update_current_game()
125
+
126
+ # image_data = get_screenshot_base64(compression=75, width=1280, height=720)
127
+ # image_data = base64.b64decode(image_data)
128
+ # img = Image.open(io.BytesIO(image_data)).convert("RGBA").resize((WIDTH, HEIGHT), Image.Resampling.LANCZOS)
116
129
  # img.show()
117
130
  logger.info(f"Screenshot captured in {time.time() - start_time:.2f} seconds.")
118
131
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GameSentenceMiner
3
- Version: 2.12.1
3
+ Version: 2.12.3
4
4
  Summary: A tool for mining sentences from games. Update: Overlay?
5
5
  Author-email: Beangate <bpwhelan95@gmail.com>
6
6
  License: MIT License
@@ -1,9 +1,9 @@
1
1
  GameSentenceMiner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  GameSentenceMiner/anki.py,sha256=FUwcWO0-arzfQjejQmDKP7pNNakhboo8InQ4s_jv6AY,19099
3
- GameSentenceMiner/config_gui.py,sha256=bK7mHLxDIXhghOJqL0VphgUOsEAPyI3mjl0uWtR4mPk,103249
4
- GameSentenceMiner/gametext.py,sha256=fNkz1dvvJCLQ1AD6NuAJhSiGUjG-OSNGzwQOGv8anGo,7776
3
+ GameSentenceMiner/config_gui.py,sha256=GBcPWWoki8dMigWqORcG9memBwKp-BNFbhXhjfFLV0c,104414
4
+ GameSentenceMiner/gametext.py,sha256=fIm28ZvRzKvnVHj86TmSYR2QQifo_Lk6cx4UptIltLs,7844
5
5
  GameSentenceMiner/gsm.py,sha256=GGF0owRrrYJgdfXx-INwfuKbaoY-G5gLllE-sNrwYnI,25341
6
- GameSentenceMiner/obs.py,sha256=-5j4k1_sYYR1Lnbn9C-_yN9prqgGLICgx5l3uguv4xk,15917
6
+ GameSentenceMiner/obs.py,sha256=lRJFFOB9oHsE_uCRmxl4xwSpkqtjWVzebyqHXmynS1E,17755
7
7
  GameSentenceMiner/vad.py,sha256=zo9JpuEOCXczPXM-dq8lbr-zM-MPpfJ8aajggR3mKk4,18710
8
8
  GameSentenceMiner/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  GameSentenceMiner/ai/ai_prompting.py,sha256=iHkEx2pQJ-tEyejOgYy4G0DcZc8qvBugVL6-CQpPSME,26089
@@ -30,7 +30,7 @@ GameSentenceMiner/owocr/owocr/run.py,sha256=nkDpXICJCTKgJTS4MYRnaz-GYqAS-GskcSg1
30
30
  GameSentenceMiner/owocr/owocr/screen_coordinate_picker.py,sha256=Na6XStbQBtpQUSdbN3QhEswtKuU1JjReFk_K8t5ezQE,3395
31
31
  GameSentenceMiner/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
32
  GameSentenceMiner/util/audio_offset_selector.py,sha256=8Stk3BP-XVIuzRv9nl9Eqd2D-1yD3JrgU-CamBywJmY,8542
33
- GameSentenceMiner/util/configuration.py,sha256=XUKA4-XFCk4tEjqj9GtB-Yq9OgBRrILXlcthRkLQpP8,35959
33
+ GameSentenceMiner/util/configuration.py,sha256=QIjSN0NfrucaK0ddhGcXqIYemBzPNtpNA3PN2SSs_PM,35991
34
34
  GameSentenceMiner/util/electron_config.py,sha256=8LZwl-T_uF5z_ig-IZcm9QI-VKaD7zaHX9u6MaLYuo4,8648
35
35
  GameSentenceMiner/util/ffmpeg.py,sha256=t0tflxq170n8PZKkdw8fTZIUQfXD0p_qARa9JTdhBTc,21530
36
36
  GameSentenceMiner/util/gsm_utils.py,sha256=iRyLVcodMptRhkCzLf3hyqc6_RCktXnwApi6mLju6oQ,11565
@@ -63,10 +63,10 @@ GameSentenceMiner/web/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
63
63
  GameSentenceMiner/web/templates/index.html,sha256=Gv3CJvNnhAzIVV_QxhNq4OD-pXDt1vKCu9k6WdHSXuA,215343
64
64
  GameSentenceMiner/web/templates/text_replacements.html,sha256=tV5c8mCaWSt_vKuUpbdbLAzXZ3ATZeDvQ9PnnAfqY0M,8598
65
65
  GameSentenceMiner/web/templates/utility.html,sha256=3flZinKNqUJ7pvrZk6xu__v67z44rXnaK7UTZ303R-8,16946
66
- GameSentenceMiner/wip/get_overlay_coords.py,sha256=2y3z44b4v1sdqfOdoRD-eSE72i_fRiH6oJaYAZY2bGo,9666
67
- gamesentenceminer-2.12.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
68
- gamesentenceminer-2.12.1.dist-info/METADATA,sha256=8XwodhYZi4oQLUVsg5d-mvByYnpDOA-Q_YbAAzcDuIY,6999
69
- gamesentenceminer-2.12.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
70
- gamesentenceminer-2.12.1.dist-info/entry_points.txt,sha256=2APEP25DbfjSxGeHtwBstMH8mulVhLkqF_b9bqzU6vQ,65
71
- gamesentenceminer-2.12.1.dist-info/top_level.txt,sha256=V1hUY6xVSyUEohb0uDoN4UIE6rUZ_JYx8yMyPGX4PgQ,18
72
- gamesentenceminer-2.12.1.dist-info/RECORD,,
66
+ GameSentenceMiner/wip/get_overlay_coords.py,sha256=hE-XxbhzvHDZoU9hLLyIFtfpHDO_QXHU0DbR-aJGPuI,10153
67
+ gamesentenceminer-2.12.3.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
68
+ gamesentenceminer-2.12.3.dist-info/METADATA,sha256=vy4RJLP3o-9ojyVqkSw6KD8XMUNIPclIoZp4c4mR1b0,6999
69
+ gamesentenceminer-2.12.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
70
+ gamesentenceminer-2.12.3.dist-info/entry_points.txt,sha256=2APEP25DbfjSxGeHtwBstMH8mulVhLkqF_b9bqzU6vQ,65
71
+ gamesentenceminer-2.12.3.dist-info/top_level.txt,sha256=V1hUY6xVSyUEohb0uDoN4UIE6rUZ_JYx8yMyPGX4PgQ,18
72
+ gamesentenceminer-2.12.3.dist-info/RECORD,,