Skip to content

Instantly share code, notes, and snippets.

@fmarani
Last active May 16, 2017 22:45
Show Gist options
  • Save fmarani/325f0c4a33c1484c42751497e82e22a8 to your computer and use it in GitHub Desktop.
Save fmarani/325f0c4a33c1484c42751497e82e22a8 to your computer and use it in GitHub Desktop.
control netflix
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<h2 ic-poll="2s" ic-src="/get/title/">netflix</h2>
<div style="font-size: 30px">
<a style='text-decoration: none;' ic-post-to='/volume/up/'>&#x25B2;</a><br>
<div ic-poll="2s" ic-src="/get/volume/">-</div>
<a style='text-decoration: none;' ic-post-to='/volume/down/'>&#x25BC;</a><br>
<a style='text-decoration: none;' ic-post-to='/pause/'>pause</a><br>
<a style='text-decoration: none;' ic-post-to='/fullscreen/'>fullscreen</a><br>
<a style='text-decoration: none;' ic-post-to='/esc/'>exit fullscreen</a><br>
<a style='text-decoration: none;' ic-post-to='/suspend/'>suspend</a><br>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://intercoolerreleases-leaddynocom.netdna-ssl.com/intercooler-1.1.1.min.js"></script>
</body>
</html>
from flask import Flask
from flask import redirect
import subprocess
app = Flask(__name__)
def volume_move(percent):
cmd = "pactl -- set-sink-volume 0 {}".format(percent)
subprocess.run(cmd.split(" "))
def keystroke(key):
cmd = "xdotool key {}".format(key)
subprocess.run(cmd.split(" "))
@app.route('/volume/up/', methods=["GET", "POST"])
def volume_up():
volume_move("+10%")
return "&#x25B2;"
@app.route('/volume/down/', methods=["GET", "POST"])
def volume_down():
volume_move("-10%")
return "&#x25BC;"
@app.route('/pause/', methods=["GET", "POST"])
def pause():
keystroke("space")
return "pause"
@app.route('/fullscreen/', methods=["GET", "POST"])
def fullscreen():
keystroke("f")
return "fullscreen"
@app.route('/esc/', methods=["GET", "POST"])
def escape():
keystroke("Escape")
return "exit fullscreen"
@app.route('/suspend/', methods=["GET", "POST"])
def suspend():
cmd = "systemctl suspend -i"
subprocess.run(cmd.split(" "))
return "suspend"
@app.route('/get/title/', methods=["GET", "POST"])
def title():
out = subprocess.check_output("/usr/bin/xdotool getactivewindow getwindowname", shell=True)
return out
@app.route('/get/volume/', methods=["GET", "POST"])
def volume():
out = subprocess.check_output("pactl list sinks | grep '^[[:space:]]Volume:' | sed -e 's,.* \\([0-9][0-9]*\\)%.*,\\1,'", shell=True).decode("utf8").strip()
return out
@app.route("/")
def hello():
return open("app.html", 'r').read()
if __name__ == "__main__":
app.run(host="0.0.0.0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment