登录 注册

使用手机远程控制网易云音乐

嘛,出于一些奇怪的需求搞了这个程序.....

使用python2.7写的,需要安装两个依赖,flask与autopy

# coding: utf-8
import os
from flask import Flask,request,jsonify
from autopy.key import toggle,tap,Code,Modifier


app=Flask(__name__)
project_root=os.path.abspath(".")
template=open(os.path.join(project_root,"templates/index.html"),"r").read()


class MusicBox(object):
    @classmethod
    def _press_keys(cls, keys):
        tap(keys,[Modifier.CONTROL])

    @classmethod
    def next_song(cls):
        cls._press_keys(Code.RIGHT_ARROW)

    @classmethod
    def prev_song(cls):
        cls._press_keys(Code.LEFT_ARROW)

    @classmethod
    def pause_play(cls):
        cls._press_keys(Code.F1)

    @classmethod
    def volume_up(cls):
        cls._press_keys(Code.UP_ARROW)

    @classmethod
    def volume_down(cls):
        cls._press_keys(Code.DOWN_ARROW)

    @classmethod
    def shutdown(cls):
        os.system("shutdown -s -t 5")


@app.route('/')
def hello_world():
    key_word = request.args.get("action")
    if key_word:
        getattr(MusicBox, key_word)()

    return template

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=10010)

同时在templates文件夹下有一个index.html

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>网易云音乐切换</title>
	<style>
		body,html{
			-webkit-touch-callout:none;
			-webkit-user-select:none;
			-khtml-user-select:none;
			-moz-user-select:none;
			-ms-user-select:none;
			user-select:none;
			-o-user-select:none;
		}
		h3{
			text-align:center;
		}
		.btn{
			margin:0 10px;
			padding:20px 0;
			text-align:center;
			width:100px;
			background:#0055dc;
			border-radius:10px;
			display:inline-block;
			text-decoration:none;
			color:#fff;
		}
		.red{
			background:#ec2c2c;
		}
		.row{
			text-align:center;
		}
		#mid{
			margin:0 0 20px;
		}
	</style>
</head>
<body>
	<div class="title">
		<h3>网易云音乐遥控器</h3>
	</div>
	<div class="row" id="mid">
		<a class="btn" href="?action=prev_song">前一首</a>
		<a class="btn" href="?action=pause_play">暂停/播放</a>
		<a class="btn" href="?action=next_song">下一首</a>
	</div>
	<div class="row">
		<a class="btn" href="?action=volume_down">音量-</a>
		<a class="btn red" href="?action=shutdown">关机</a>
		<a class="btn" href="?action=volume_up">音量+</a>
	</div>
</body>
</html>

说明:

根据网易云的快捷键不同,需要对python程序中使用的键位进行修改

2018
07 22
上一篇
Older
下一篇
Newer
评论
0
点击
247
发布
我是标题
我是文字
我是标题
我是文字
用户名
密码
用户名
密码
重复密码
努力的加载中.....