spothomelight 1.0.2__py3-none-any.whl → 1.0.4__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.
spothomelight/auth.py CHANGED
@@ -44,4 +44,4 @@ def get_spotify_client(config):
44
44
  print(f"登录失败: {e}")
45
45
  return None
46
46
 
47
- return spotipy.Spotify(auth=token_info['access_token'], oauth_manager=sp_oauth)
47
+ return spotipy.Spotify(oauth_manager=sp_oauth)
spothomelight/core.py CHANGED
@@ -16,13 +16,13 @@ def run_loop(config):
16
16
  interval = int(config['GENERAL']['interval'])
17
17
 
18
18
  if not webhook_id:
19
- print("错误: 配置文件中 webhook_id 为空,无法发送数据。")
19
+ print("Error: webhook_id is empty.")
20
20
  return
21
21
 
22
22
  webhook_full_url = f"{ha_url}/api/webhook/{webhook_id}"
23
23
 
24
- print(f"服务已启动。监控频率: {interval}")
25
- print(f"Home Assistant 地址: {webhook_full_url}")
24
+ print(f"Service started. interval: {interval}")
25
+ print(f"Home Assistant: {webhook_full_url}")
26
26
 
27
27
  last_track_id = None
28
28
  last_is_playing = False
@@ -40,7 +40,7 @@ def run_loop(config):
40
40
  track_id = item['id']
41
41
 
42
42
  if track_id != last_track_id or not last_is_playing:
43
- print(f"检测到正在播放: {item['name']} - {item['artists'][0]['name']}")
43
+ print(f"Now playing: {item['name']} - {item['artists'][0]['name']}")
44
44
 
45
45
  images = item['album']['images']
46
46
  image_url = images[0]['url'] if images else None
@@ -59,9 +59,9 @@ def run_loop(config):
59
59
 
60
60
  try:
61
61
  requests.post(webhook_full_url, json=payload, timeout=5)
62
- print(f"已发送颜色 {payload['hex']} HA")
62
+ print(f"Push {payload['hex']} to HA")
63
63
  except Exception as e:
64
- print(f"发送 Webhook 失败: {e}")
64
+ print(f"Webhook Error: {e}")
65
65
 
66
66
  last_track_id = track_id
67
67
 
@@ -69,7 +69,7 @@ def run_loop(config):
69
69
 
70
70
  else:
71
71
  if last_is_playing:
72
- print("播放已暂停/停止")
72
+ print("stop/pause playing")
73
73
  # try:
74
74
  # requests.post(webhook_full_url, json={"state": "paused"}, timeout=5)
75
75
  # except:
@@ -77,7 +77,7 @@ def run_loop(config):
77
77
  last_is_playing = False
78
78
 
79
79
  except Exception as e:
80
- print(f"运行循环发生错误: {e}")
80
+ print(f"Error: {e}")
81
81
  time.sleep(10)
82
82
 
83
83
  time.sleep(interval)
spothomelight/main.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import argparse
2
2
  import sys
3
3
  from .config import load_config, open_config_editor
4
- from .service import setup_autostart
4
+ from .service import setup_autostart, start_managed_service
5
5
  from .utils import check_running, stop_process
6
6
  from .core import run_loop
7
7
 
@@ -14,9 +14,12 @@ def main():
14
14
  """
15
15
  )
16
16
 
17
- parser.add_argument("-c", "--config", action="store_true", help="打开配置文件")
18
- parser.add_argument("-a", "--autostart", action="store_true", help="配置开机自动运行")
19
- parser.add_argument("-s", "--stop", action="store_true", help="停止正在运行的服务")
17
+ config_group = parser.add_argument_group('配置选项')
18
+ config_group.add_argument("-c", "--config", action="store_true", help="打开配置文件")
19
+ service_group = parser.add_argument_group('服务管理')
20
+ service_group.add_argument("-a", "--autostart", action="store_true", help="配置开机自动运行")
21
+ service_group.add_argument("--start", action="store_true", help="启动已配置的后台服务")
22
+ service_group.add_argument("-s", "--stop", action="store_true", help="停止正在运行的服务")
20
23
 
21
24
  args = parser.parse_args()
22
25
 
@@ -32,9 +35,18 @@ def main():
32
35
  setup_autostart()
33
36
  sys.exit(0)
34
37
 
38
+ if args.start:
39
+ pid = check_running()
40
+ if pid:
41
+ print(f"提示: 服务已经在运行中 (PID: {pid}),无需重复启动。")
42
+ else:
43
+ start_managed_service()
44
+ sys.exit(0)
45
+
35
46
  pid = check_running()
36
47
  if pid:
37
- print(f"错误: 服务已在运行中 (PID: {pid})。请先停止或直接使用。")
48
+ print(f"错误: 服务已在后台运行中 (PID: {pid})")
49
+ print("如果要查看实时日志或调试,请先停止服务: spothomelight -s")
38
50
  sys.exit(1)
39
51
 
40
52
  config = load_config()
spothomelight/service.py CHANGED
@@ -85,4 +85,40 @@ WantedBy=default.target
85
85
  print(f"已创建 Windows 计划任务: {task_name}")
86
86
  print("下次登录时将自动运行。")
87
87
  except subprocess.CalledProcessError as e:
88
- print(f"创建计划任务失败: {e}")
88
+ print(f"创建计划任务失败: {e}")
89
+
90
+ def start_managed_service():
91
+ system = platform.system()
92
+
93
+ if system == "Linux":
94
+ is_root = (os.geteuid() == 0)
95
+
96
+ if is_root:
97
+ print("正在启动系统级后台服务...")
98
+ ret = os.system("systemctl start spothomelight")
99
+ if ret == 0:
100
+ print("服务已启动。请使用 'systemctl status spothomelight' 查看详情。")
101
+ else:
102
+ print("启动失败。请检查服务是否已安装 (spothomelight -a)。")
103
+ else:
104
+ print("正在启动用户级后台服务...")
105
+ ret = os.system("systemctl --user start spothomelight")
106
+ if ret == 0:
107
+ print("服务已启动。请使用 'systemctl --user status spothomelight' 查看详情。")
108
+ else:
109
+ print("启动失败。请检查服务是否已安装 (spothomelight -a),或尝试手动运行 'systemctl --user start spothomelight'。")
110
+
111
+ elif system == "Windows":
112
+ task_name = "SpotHomeLightAutoStart"
113
+ print(f"正在启动 Windows 计划任务: {task_name} ...")
114
+ cmd = ["schtasks", "/Run", "/TN", task_name]
115
+
116
+ try:
117
+ result = subprocess.run(cmd, check=True, capture_output=True, text=True)
118
+ print("服务已启动。")
119
+ except subprocess.CalledProcessError as e:
120
+ err_msg = e.stderr.strip() if e.stderr else str(e)
121
+ if "系统找不到指定的文件" in err_msg or "does not exist" in err_msg:
122
+ print("错误: 未找到计划任务。请先运行 'spothomelight -a' 进行配置。")
123
+ else:
124
+ print(f"启动失败: {err_msg}")
spothomelight/utils.py CHANGED
@@ -30,7 +30,7 @@ def get_image_color(image_url):
30
30
  return (rgb.r, rgb.g, rgb.b)
31
31
 
32
32
  except Exception as e:
33
- print(f"取色失败: {e}")
33
+ print(f"get_image_color Error: {e}")
34
34
  return None
35
35
 
36
36
  def write_pid():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spothomelight
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: Sync Spotify cover color to Home Assistant via Webhook
5
5
  Author-email: "ZGQ Inc." <zgqinc@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/ZGQ-inc/SpotHomeLight
@@ -28,7 +28,7 @@ Dynamic: license-file
28
28
  * **跨平台支持**:完美支持 Linux (Systemd) 和 Windows (计划任务)。
29
29
  * **无头模式设计**:专为无显示器的家用服务器设计,支持终端内完成 OAuth 认证。
30
30
  * **智能取色**:使用 K-Means 聚类算法提取最主要颜色,并进行缩略图预处理以降低 CPU 占用。
31
- * **开机自启**:内置一键配置开机自动运行 (`-a`)。
31
+ * **开机自启**:内置一键配置开机自动运行。
32
32
  * **低资源占用**:去重机制,仅在切歌时进行下载和计算。
33
33
 
34
34
  ## 🛠️ 前置要求
@@ -97,7 +97,7 @@ mode: restart
97
97
  trigger:
98
98
  - platform: webhook
99
99
  webhook_id: ""
100
- local_only: true
100
+ local_only: false
101
101
  condition: []
102
102
  action:
103
103
  - service: light.turn_on
@@ -138,10 +138,16 @@ spothomelight -a
138
138
  * **Linux**: 会自动创建并启用 Systemd User Service。
139
139
  * **Windows**: 会自动创建 Windows 计划任务(登录时运行)。
140
140
 
141
+ 手动启动服务:
142
+
143
+ ```bash
144
+ spothomelight --start
145
+ ```
146
+
141
147
  停止服务:
142
148
 
143
149
  ```bash
144
- spothomelight -s
150
+ spothomelight --stop
145
151
  ```
146
152
 
147
153
  ## 🐛 已知问题
@@ -0,0 +1,14 @@
1
+ spothomelight/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ spothomelight/auth.py,sha256=xWmHqmhA3cLgVLzDyOvvS1AdanwG4_zkZQYuYnTvf5M,1673
3
+ spothomelight/config.py,sha256=URC1WwzZN2gRIfwNlMRwHNVtoviayYzmf6F0w3lMhLA,2274
4
+ spothomelight/core.py,sha256=Il7iuX2tKmJlqVUSUVLM_H7UvneufwAnWq6YpYRKRik,2896
5
+ spothomelight/main.py,sha256=N-o-Wh4VhTDRX45mgxZMobSNNfOv5qnuY4wsu4JV78k,1954
6
+ spothomelight/service.py,sha256=nB77JRqNoOFchWT5k_Tmpln--aT69Bu1DWQ8yNgzdlo,4654
7
+ spothomelight/utils.py,sha256=VdJEms2mNMI7-8QYNnH-g4irnZh1pcQiFg_nwefxXss,1823
8
+ spothomelight/utils_median_cut.py,sha256=9sqUBk0ZpHWwfoPl4YPRcljE_K05w8trZFQo8bVCMds,1991
9
+ spothomelight-1.0.4.dist-info/licenses/LICENSE,sha256=_r815CZLcqdQJmXH7FeFNoBT8gmiGtsdqo4aynUS-DM,1065
10
+ spothomelight-1.0.4.dist-info/METADATA,sha256=UaDF7gn9g-4g0jgbenIW1ATt-tW4f4n_OhOL4715L9A,4601
11
+ spothomelight-1.0.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
+ spothomelight-1.0.4.dist-info/entry_points.txt,sha256=f9haGAoi-aXDTCkoxuSkdN78sHbvfbrr9gwaOIewuvw,58
13
+ spothomelight-1.0.4.dist-info/top_level.txt,sha256=70ecLHIP1BNR5ZLYC-IfQ6ceydH0AZaDGIoH_wGrQZY,14
14
+ spothomelight-1.0.4.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- spothomelight/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- spothomelight/auth.py,sha256=TGmR28lIBZnEVkMv7jIDBToZT3rcFUaqv4ZineIO-Do,1706
3
- spothomelight/config.py,sha256=URC1WwzZN2gRIfwNlMRwHNVtoviayYzmf6F0w3lMhLA,2274
4
- spothomelight/core.py,sha256=u87Q3BTdwbpjQIT4sZAK9-g79Rr-KHOepSLs2jDufPo,3002
5
- spothomelight/main.py,sha256=jX8esko2yj8c09HKBb1qmQloWE0mUQEc0F_CL27l5t8,1377
6
- spothomelight/service.py,sha256=hoVW79VDUG4P3upS3gPD79j1CqfrDnLJRlxk-lnOUkI,2943
7
- spothomelight/utils.py,sha256=TnGji05MKMTsoqWUq5wFPx6jLthqA-KWVH-dCu5VbIc,1814
8
- spothomelight/utils_median_cut.py,sha256=9sqUBk0ZpHWwfoPl4YPRcljE_K05w8trZFQo8bVCMds,1991
9
- spothomelight-1.0.2.dist-info/licenses/LICENSE,sha256=_r815CZLcqdQJmXH7FeFNoBT8gmiGtsdqo4aynUS-DM,1065
10
- spothomelight-1.0.2.dist-info/METADATA,sha256=x7w9aIeozpXKvF1-glT_KcO6s4RvUgXEKNue79TlkBc,4545
11
- spothomelight-1.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
- spothomelight-1.0.2.dist-info/entry_points.txt,sha256=f9haGAoi-aXDTCkoxuSkdN78sHbvfbrr9gwaOIewuvw,58
13
- spothomelight-1.0.2.dist-info/top_level.txt,sha256=70ecLHIP1BNR5ZLYC-IfQ6ceydH0AZaDGIoH_wGrQZY,14
14
- spothomelight-1.0.2.dist-info/RECORD,,