Skip to content

Instantly share code, notes, and snippets.

@roflsunriz
Created April 3, 2025 18:08
Show Gist options
  • Save roflsunriz/457d52cff03eff56d097f2c51fbfda05 to your computer and use it in GitHub Desktop.
Save roflsunriz/457d52cff03eff56d097f2c51fbfda05 to your computer and use it in GitHub Desktop.
install_spicetify : ダブルクリックと"y"入力で簡単Spicetify&マーケットプレイスインストール
import os
import subprocess
import time
import psutil
import sys
def kill_spotify():
for proc in psutil.process_iter(['pid', 'name']):
try:
if 'Spotify.exe' in proc.info['name']:
proc.kill()
print("Spotifyを終了したのじゃ!")
time.sleep(2) # プロセスが完全に終了するのを待つのじゃ
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
def run_powershell_command(command):
try:
print("新しいPowerShellウィンドウでコマンドを実行するのじゃ...")
# 新しいウィンドウでPowerShellを起動して、コマンドを実行するのじゃ
process = subprocess.Popen(
['powershell', '-Command', command],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
bufsize=1,
universal_newlines=True
)
print("PowerShellウィンドウで[Y]を選択してほしいのじゃ!")
# リアルタイムでログを出力するのじゃ
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print(output.strip())
# エラー出力があれば表示するのじゃ
stderr = process.stderr.read()
if stderr:
print(f"エラー出力: {stderr}")
return process.returncode == 0
except Exception as e:
print(f"エラーが発生したのじゃ: {str(e)}")
return False
def main():
print("Spicetifyのインストールを開始するのじゃ!")
# Spotifyを終了するのじゃ
kill_spotify()
print("新しいPowerShellウィンドウが開くので、そちらで[Y]を選択してほしいのじゃ!")
# Spicetifyのインストールを実行するのじゃ
spicetify_command = "iwr -useb https://raw.githubusercontent.com/spicetify/cli/main/install.ps1 | iex"
success = run_powershell_command(spicetify_command)
if not success:
print("Spicetifyのインストールに失敗したのじゃ...")
print("Marketplaceのインストールを試みるのじゃ!")
# Marketplaceのインストールを実行するのじゃ
marketplace_command = "iwr -useb https://raw.githubusercontent.com/spicetify/marketplace/main/resources/install.ps1 | iex"
if run_powershell_command(marketplace_command):
print("Marketplaceのインストールに成功したのじゃ!")
else:
print("Marketplaceのインストールにも失敗したのじゃ...")
else:
print("Spicetifyのインストールが完了したのじゃ!")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment