Browse Source

Liquidsoap webhook integration (in progress)

jeremiewcz 1 year ago
parent
commit
3d4990f53a
4 changed files with 96 additions and 2 deletions
  1. 12
    1
      app/main/views.py
  2. 2
    1
      config.py
  3. 14
    0
      liquidsoap/README.md
  4. 68
    0
      liquidsoap/rhino.liq

+ 12
- 1
app/main/views.py View File

@@ -10,7 +10,7 @@ from flask import (Flask,
10 10
 from werkzeug.utils import secure_filename
11 11
 from functools import wraps
12 12
 from glob import glob
13
-from config import config
13
+from config import config, LIQUIDSOAP_TOKEN
14 14
 import json
15 15
 from uuid import uuid4
16 16
 from datetime import date
@@ -190,6 +190,17 @@ def collective(coll):
190 190
 #  Static stuff         #
191 191
 #########################
192 192
 
193
+@main.route('/on_air', methods=['POST'])
194
+def on_air():
195
+    error = None
196
+    if request.args.get('token') != LIQUIDSOAP_TOKEN:
197
+        error = 'Invalid token !'
198
+    else:
199
+        return live(stream = request.args.get('stream'))
200
+
201
+def live(stream):
202
+    pass
203
+
193 204
 def getStyles():
194 205
      return [ url_for('static',
195 206
                       filename=file.replace('app/static/', ''),

+ 2
- 1
config.py View File

@@ -2,6 +2,7 @@ import os
2 2
 basedir = os.path.abspath(os.path.dirname(__file__))
3 3
 
4 4
 __APP_NAME__ = "Rhino Radio CMS"
5
+LIQUIDSOAP_TOKEN = os.environ.get('LIQUIDSOAP_TOKEN') or 'hijackmyradio'
5 6
 
6 7
 class Config:
7 8
     SECRET_KEY = os.environ.get('SECRET_KEY') or 'hackme'
@@ -20,7 +21,7 @@ class DevelopmentConfig(Config):
20 21
     # SQLite :
21 22
     #SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or 'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')
22 23
     # PostgreSQL :
23
-    SQLALCHEMY_DATABASE_URI = os. environ.get('DEV_DATABASE_URL') or 'postgresql://localhost/rhino'
24
+    SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or 'postgresql://localhost/rhino'
24 25
 
25 26
 class TestingConfig(Config):
26 27
     TESTING = True

+ 14
- 0
liquidsoap/README.md View File

@@ -0,0 +1,14 @@
1
+# Liquidsoap environment
2
+
3
+## Install
4
+
5
+First, we need to install Liquidsoap v.1.3.3 (or more recent), which unfortunately is not packaged for Debian/Ubuntu anymore.
6
+Download it from Liquidsoap's (Github releases page)[https://github.com/savonet/liquidsoap/releases].
7
+
8
+Make sure you have installed all the dependencies, then :
9
+```bash
10
+cp PACKAGES.default PACKAGES
11
+./configure
12
+./make
13
+./make install
14
+```

+ 68
- 0
liquidsoap/rhino.liq View File

@@ -0,0 +1,68 @@
1
+#!/usr/bin/liquidsoap
2
+# Log dir
3
+set("log.file.path","/tmp/basic-radio.log")
4
+
5
+# Setup stream environment:
6
+hostname = "localhost"
7
+input_mountpoint = "/master.ogg"
8
+mountpoint = "/stream.ogg"
9
+filename = "%Y-%m-%d-%H-%M.ogg"
10
+stream_uri = "http://" ^ hostname ^ mountpoint
11
+file_uri = "http://" ^ hostname ^ filename
12
+
13
+# Setup "on-air" and "off-air" webhooks:
14
+webhook_hostname = "radiorhino.eu"
15
+webhook_route = "/on-air-status"
16
+webhook_uri = "https://" ^ webhook_hostname ^ webhook_route
17
+
18
+# Check if ON_AIR_TOKEN environment variable is set and store it or set it to default
19
+on_air_token = getenv("ON_AIR_TOKEN")
20
+
21
+################
22
+#  Inputs      #
23
+################
24
+
25
+def on_air ()
26
+    resp = http.post(
27
+        data="Token=" ^ on_air_token ^
28
+            "&Stream=" ^ stream_uri ^
29
+            "&Filename=" ^ file_uri ^
30
+            "&State=ON_AIR",
31
+        webhook_uri)
32
+    print(resp)
33
+end
34
+
35
+def off_air ()
36
+    resp = http.post(
37
+        data="Token=" ^ on_air_token ^
38
+            "&State=OFF_AIR")
39
+    print(resp)
40
+end
41
+
42
+base = synth.all.sine()
43
+source =
44
+    input.http("http://" ^ hostname ^ input_mountpoint,
45
+        on_connect={on_air}, on_disconnect={off_air})
46
+radio = fallback([base, source])
47
+
48
+#################
49
+#  Outputs      #
50
+#################
51
+
52
+# Possible options and values are bitrate=64, samplerate=11025, ...
53
+output.icecast(%vorbis,
54
+    host=hostname,
55
+    port=8000,
56
+    mount="live.ogg",
57
+    password="yolo",
58
+    source)
59
+
60
+print(filename)
61
+print(on_air_token)
62
+
63
+output.file(
64
+    %vorbis,
65
+    filename,
66
+    on_start=on_air,
67
+    on_stop=off_air,
68
+    source)

Loading…
Cancel
Save