├── Python Version ├── requirements-windows.txt ├── __pycache__ │ └── keypresser.cpython-35.pyc └── main.py ├── gamestate_integration_CSGOMusic.cfg ├── Node Version ├── package.json └── main.js ├── LICENSE └── README.md /Python Version/requirements-windows.txt: -------------------------------------------------------------------------------- 1 | Pillow==3.1.0 2 | Flask==0.10.1 3 | PyAutoGUI==0.9.33 -------------------------------------------------------------------------------- /Python Version/__pycache__/keypresser.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rowan-walshe/CSGOMusicPlayer/HEAD/Python Version/__pycache__/keypresser.cpython-35.pyc -------------------------------------------------------------------------------- /gamestate_integration_CSGOMusic.cfg: -------------------------------------------------------------------------------- 1 | "CSGOMusicPlayer" 2 | { 3 | "uri" "http://127.0.0.1:3000" 4 | "timeout" "5.0" 5 | "buffer" "0.1" 6 | "throttle" "0.5" 7 | "heartbeat" "60.0" 8 | "data" 9 | { 10 | "player_id" "1" 11 | "player_state" "1" 12 | "round" "1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Node Version/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csgo-music-player", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "robotjs": "^0.4.5" 6 | }, 7 | "description": "Plays/pauses your musics when you die/respawn in csgo", 8 | "main": "main.js", 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "author": "Rowan Walshe", 13 | "license": "MIT" 14 | } 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Rauwomos 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 | -------------------------------------------------------------------------------- /Python Version/main.py: -------------------------------------------------------------------------------- 1 | import pyautogui 2 | import logging 3 | import json 4 | from time import sleep 5 | from flask import Flask, request 6 | 7 | 8 | 9 | log = logging.getLogger('werkzeug') 10 | log.setLevel(logging.INFO) 11 | 12 | state = 'PlayMusic' 13 | lastCheck = 'PlayMusic' 14 | #Insert SteamID Here 15 | mySteamID = '34432432' 16 | #Change deathDelay if you want to hear footsteps etc... 17 | deathDelay = 3 18 | app = Flask(__name__) 19 | 20 | @app.route("/", methods=["POST"]) 21 | def main(): 22 | 23 | global state 24 | global lastCheck 25 | global deathDelay 26 | 27 | player = request.json.get('player', {}) 28 | round = request.json.get('round', {}) 29 | 30 | if player['steamid'] != mySteamID or player['state']['health'] == 0 or round['phase'] in ('freezetime','warmup','over'): 31 | lastCheck = 'PlayMusic' 32 | else: 33 | lastCheck = 'StopPlaying' 34 | 35 | if lastCheck == 'PlayMusic' and state == 'StopPlaying': 36 | print(lastCheck) 37 | sleep(deathDelay) 38 | pyautogui.press('playpause') 39 | state = lastCheck 40 | elif lastCheck != state: 41 | print(lastCheck) 42 | pyautogui.press('playpause') 43 | state = lastCheck 44 | 45 | 46 | if __name__ == "__main__": 47 | print('Running') 48 | app.run(port=3000) 49 | -------------------------------------------------------------------------------- /Node Version/main.js: -------------------------------------------------------------------------------- 1 | http = require('http') 2 | robot = require('robotjs') 3 | 4 | port = 3000 5 | host = '127.0.0.1' 6 | previous_health = 0 7 | 8 | server = http.createServer( function(req, res) { 9 | 10 | if (req.method == 'POST') { 11 | 12 | res.writeHead(200, {'Content-Type': 'text/html'}) 13 | 14 | var body='' 15 | req.on('error', function(err) { 16 | console.error(err) 17 | }).on('data', function (data) { 18 | body += data 19 | }).on('end', function () { 20 | res.end( '' ) 21 | parsePlayerUpdate(JSON.parse(body)) 22 | }) 23 | } 24 | 25 | }).listen(port, host) 26 | 27 | // Takes the parsed json and plays/pauses the music when it should 28 | function parsePlayerUpdate(update) { 29 | 30 | steamid = update.player.steamid 31 | activity = update.player.activity 32 | 33 | if(steamid == '76561198058071054' && activity !== 'menu') { 34 | try { 35 | health = update.player.state.health 36 | if((health > 0 && previous_health == 0) || (health == 0 && previous_health > 0)) { 37 | robot.keyTap('audio_pause') 38 | console.log('play/pause') 39 | } 40 | 41 | previous_health = update.player.state.health 42 | } catch(err) { 43 | console.error(err) 44 | } 45 | } 46 | } 47 | 48 | console.log('Listening at http://' + host + ':' + port) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSGOMusicPlayer 2 | 3 | Uses CSGO's game state integration to play when you are dead, and pause it when you are alive. It should work with any application where you are able to control music with the play/pause button on your keyboard 4 | 5 | 6 | ### Installation 7 | 8 | Firstly make sure you have python 3 installed. This can be found here https://www.python.org/downloads/ 9 | 10 | #### Windows 11 | 12 | Place the gamestate integration file in the following folder. You don't need to change anything in this file. 13 | 14 | \Steam\steamapps\common\Counter-Strike Global Offensive\csgo\cfg\ 15 | 16 | In command prompt navigate to the CSGO you downloaded the project to. This will most likely be in downloads. You can navigate to the folder using the cd command. Below will what you have to type if you saved the file to Downloads. 17 | 18 | cd Downloads 19 | 20 | cd CSGOMusicPlayer 21 | 22 | Next run the following command 23 | 24 | pip install -r requirements-windows.txt 25 | 26 | If it gives an error like pip is not recognised, make sure you have python 3 installed, or trying using pip3 instead of pip 27 | 28 | Next open main.py in a text editor. On line 5 where it says the line below, and change the number to your steamid. If you need to find out what yours is go to https://steamcommunity.com, login and click on your profile picture in the top right. You steamid will be the number that it shows in the address bar. 29 | 30 | mySteamID = '76561198058071054' 31 | 32 | Save the file, and then in the command promt window again, run 33 | 34 | python main.py 35 | 36 | If it doesn't work try 37 | 38 | python3 main.py 39 | 40 | #### OSX 41 | 42 | The only differences from the windows intructions are that PyAutoGUI has more dependences. 43 | 44 | #### Linux 45 | 46 | The only differences from the windows intructions are that PyAutoGUI has more dependences. 47 | 48 | #### Known issues 49 | 50 | 1. If you are using spotify and an advert is playing when your state changes then sometimes it won't play/pause the music when it stops. Fixes: 51 | * Play/pause the music when the advert has finished 52 | * Pay for spotify premium so there are no adds 53 | 54 | Any input is greatly appreciated. It is very basic, as I just through it together, while learning python at the same time. 55 | 56 | I will continue to update it as I learn more and think of features to add 57 | --------------------------------------------------------------------------------