initial changes

This commit is contained in:
Mateusz Pstrucha committed 2021-09-28 11:56:17 +02:00
1 parent 06b57a9ded
commit 75cf468d85
8 files changed
+188 -83

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
__pycache__
.env
+44
View File
@@ -0,0 +1,44 @@
from dotenv import load_dotenv
import requests
import json
import os
load_dotenv()
url = os.environ['domain']
secret = os.environ['secret']
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + secret
}
def updateStatus(tid, progress=None, duration=None, paused=None):
payload = json.dumps({
"tid": tid,
"progress": progress,
"paused": paused,
"duration": duration
})
response = requests.request(
"PUT", url + "/player/set/status", headers=headers, data=payload)
return response.json()
def updateNext(tid):
payload = json.dumps({
"tid": tid
})
response = requests.request(
"PUT", url + "/player/set/next", headers=headers, data=payload)
return response.json()
def getTop():
response = requests.request(
"GET", url + "/player/get/top", headers=headers)
return response.json()
-43
View File
@@ -1,43 +0,0 @@
const dotenv = require('dotenv').config(),
express = require('express'),
path = require('path'),
// cookieParser = require('cookie-parser'),
http = require('http'),
// https = require('https'),
fs = require('fs'),
pretty = require('pretty-log'),
io = require('socket.io'),
// crypto = require('crypto'),
// SpotifyWebApi = require('spotify-web-api-node'),
// db = require('./db');
var app = express(),
www = http.createServer(app),
server = io(www);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.set('port', process.env.port);
www.listen(process.env.port);
www.on('error', function (error) {
if (error.syscall !== 'listen') {
throw error;
}
pretty.log({
data: `Error: port ${process.env.port}: ${error.code}`,
action: 'error'
})
});
www.on('listening', function () {
pretty.log(`www: listening on ${process.env.port}`)
});
server.on('connection', socket => {
} )
+53
View File
@@ -0,0 +1,53 @@
#/usr/env python3
import datetime
import threading
from timing import timing, offset
def getNow():
now = datetime.datetime.now()
midnight = now.replace(hour=0, minute=0, second=0, microsecond=0)
seconds = (now - midnight).seconds
return seconds
przerwy = []
status = False
def timeStampToSeconds(przerwa):
hours = przerwa[0]*60*60
minutes = przerwa[1]*60
return hours+minutes+offset
for przerwa in timing:
czasy = []
for odido in przerwa:
czasy.append(timeStampToSeconds(odido))
przerwy.append(czasy)
print(timing)
def isPrzerwa():
seconds = getNow()
for przerwa in przerwy:
if (seconds > przerwa[0]) and (seconds < przerwa[1]):
return True
return False
def clock():
threading.Timer(1.0, clock).start()
global status
new = isPrzerwa()
old = status
status = new
if new != old:
if new:
print("up")
else:
print("down")
clock()
-29
View File
@@ -1,29 +0,0 @@
// app.get('/login', function (req, res) {
// var scopes = ['user-read-private', 'user-read-email'],
// redirect = spotify.createAuthorizeURL(scopes, 'what')
// res.redirect(redirect)
// // res.redirect('https://accounts.spotify.com/authorize' +
// // '?response_type=code' +
// // '&client_id=' + credentials.spotify.clientId +
// // (scopes ? '&scope=' + encodeURIComponent(scopes) : '') +
// // '&redirect_uri=' + encodeURIComponent('https://radio-rolnik.mtps.pl/logedin'));
// });
// app.get('/logedin', function (req, res) {
// console.log(req.query.code)
// spotify.authorizationCodeGrant(req.query.code).then(
// function (data) {
// console.log('The token expires in ' + data.body['expires_in']);
// console.log('The access token is ' + data.body['access_token']);
// console.log('The refresh token is ' + data.body['refresh_token']);
// // Set the access token on the API object to use it in later calls
// spotify.setAccessToken(data.body['access_token']);
// spotify.setRefreshToken(data.body['refresh_token']);
// },
// function (err) {
// console.log('Something went wrong!', err);
// }
// );
// })
-11
View File
@@ -1,11 +0,0 @@
{
"name": "radio-rolnik-player",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Mateusz Pstrucha",
"license": "ISC"
}
+78
View File
@@ -0,0 +1,78 @@
from dotenv import load_dotenv
import vlc
import pafy
from calls import *
load_dotenv()
print('Settings up...')
Instance = vlc.Instance()
player = Instance.media_player_new()
top = []
def top_show(args):
print(top)
def top_get(args):
global top
top = getTop()
def play(args):
player.play()
def pause(args):
player.pause()
def volume(args=[50]):
player.audio_set_volume(args[0])
def close(args):
stop()
exit()
def change(args):
audio = pafy.new(args[0])
best = audio.getbestaudio()
playurl = best.url
Media = Instance.media_new(playurl)
# Media.get_mrl()
player.set_media(Media)
def stop(args=[]):
player.stop()
def what(comm):
options = {
"play": play,
"pause": pause,
"stop": stop,
"change": change,
"exit": close,
"top.show": top_show,
"top.get": top_get
}
args = comm.split(' ')
if len(comm) > 0:
print("-> ", comm)
if args[0] in options:
options[args[0]](args[1:])
while True:
comm = input('# ')
what(comm)
+11
View File
@@ -0,0 +1,11 @@
timing = (
((8, 45), (8, 55)),
((9, 40), (9, 50)),
((10, 35), (10, 50)),
((11, 35), (11, 45)),
((12, 30), (12, 40)),
((13, 25), (13, 30)),
((22, 46), (22, 47))
)
offset = -5