Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nms-viewcount-tool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Hartig
nms-viewcount-tool
Commits
50a943be
Commit
50a943be
authored
1 year ago
by
Jan Hartig
Browse files
Options
Downloads
Patches
Plain Diff
Support multiple streaming servers
parent
afcfa107
No related branches found
No related tags found
No related merge requests found
Pipeline
#58455
passed
21 hours ago
Stage: build
Changes
1
Pipelines
591
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.py
+41
-10
41 additions, 10 deletions
server.py
with
41 additions
and
10 deletions
server.py
+
41
−
10
View file @
50a943be
...
...
@@ -2,32 +2,63 @@ from flask import Flask, jsonify
import
requests
from
requests.auth
import
HTTPBasicAuth
'''
Config ###
"""
Config ###
Set via environment variable
FLASK_NMS_URL: Node Media Server API endpoint (e.g. https://tube.ptb.de/api)
FLASK_NMS_URL: Node Media Server API endpoint (e.g. https://tv.ptb.de/api)
FLASK_NMS_URLS: Node Media Server API endpoints as list (e.g.
'
[
"
https://server1.tv.ptb.de/api
"
,
"
https://server0.tv.ptb.de/api
"
]
'
)
FLASK_NMS_USER: Node Media Server API user
FLASK_NMS_PASSWORD: Node Media Server API password
'''
"""
app
=
Flask
(
__name__
)
app
.
config
.
from_prefixed_env
()
basic_auth
=
HTTPBasicAuth
(
app
.
config
[
"
NMS_USER
"
],
app
.
config
[
"
NMS_PASSWORD
"
])
try
:
nms_urls
=
app
.
config
[
"
NMS_URLS
"
]
except
KeyError
:
nms_urls
=
None
@app.get
(
"
/<stream_name>
"
)
def
hello_world
(
stream_name
:
str
):
def
get_viewcount
(
stream_name
:
str
):
viewers
=
0
r
=
requests
.
get
(
f
"
{
app
.
config
[
"
NMS_URL
"
]
}
/streams
"
,
auth
=
basic_auth
,
proxies
=
{
"
http
"
:
""
,
"
https
"
:
""
})
if
nms_urls
:
responses
=
[]
for
nms_url
in
nms_urls
:
r
=
requests
.
get
(
f
"
{
nms_url
}
/streams
"
,
auth
=
basic_auth
,
proxies
=
{
"
http
"
:
""
,
"
https
"
:
""
},
)
responses
.
append
(
r
)
for
r
in
responses
:
if
r
.
ok
:
data
=
r
.
json
()
stream_data
=
data
[
"
live
"
].
get
(
stream_name
)
if
stream_data
:
viewers
+=
len
(
stream_data
.
get
(
"
subscribers
"
))
else
:
r
=
requests
.
get
(
f
'
{
app
.
config
[
"
NMS_URL
"
]
}
/streams
'
,
auth
=
basic_auth
,
proxies
=
{
"
http
"
:
""
,
"
https
"
:
""
},
)
if
r
.
ok
:
data
=
r
.
json
()
if
r
.
ok
:
data
=
r
.
json
()
stream_data
=
data
[
"
live
"
].
get
(
stream_name
)
stream_data
=
data
[
"
live
"
].
get
(
stream_name
)
if
stream_data
:
viewers
=
len
(
stream_data
.
get
(
"
subscribers
"
))
if
stream_data
:
viewers
=
len
(
stream_data
.
get
(
"
subscribers
"
))
return
jsonify
(
viewers
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment