Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
steering
Commits
b126918a
Commit
b126918a
authored
3 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Move get_audio_url into utils and update the uses
parent
c7421952
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
program/models.py
+0
-29
0 additions, 29 deletions
program/models.py
program/serializers.py
+3
-2
3 additions, 2 deletions
program/serializers.py
program/utils.py
+26
-0
26 additions, 0 deletions
program/utils.py
with
29 additions
and
31 deletions
program/models.py
+
0
−
29
View file @
b126918a
...
...
@@ -1072,32 +1072,3 @@ class Note(models.Model):
note
=
Note
.
objects
.
get
(
pk
=
note_id
)
return
int
(
note
.
show_id
)
in
note_view_set
.
request
.
user
.
shows
.
all
().
values_list
(
'
id
'
,
flat
=
True
)
# FIXME: this does not belong here
@staticmethod
def
get_audio_url
(
cba_id
):
"""
Retrieve the direct URL to the mp3 in CBA
In order to retrieve the URL, stations need
- to be whitelisted by CBA
- an API Key
Therefore contact cba@fro.at
"""
from
steering.settings
import
CBA_AJAX_URL
,
CBA_API_KEY
audio_url
=
''
if
cba_id
is
not
None
and
cba_id
!=
''
and
CBA_API_KEY
!=
''
:
url
=
CBA_AJAX_URL
+
'
?action=cba_ajax_get_filename&post_id=
'
+
str
(
cba_id
)
+
'
&api_key=
'
+
CBA_API_KEY
# For momentary testing without being whitelisted - TODO: delete the line
url
=
'
https://cba.fro.at/wp-content/plugins/cba/ajax/cba-get-filename.php?post_id=
'
+
str
(
cba_id
)
+
'
&c=Ml3fASkfwR8
'
with
urlopen
(
url
)
as
conn
:
audio_url_json
=
conn
.
read
().
decode
(
'
utf-8-sig
'
)
audio_url
=
json
.
loads
(
audio_url_json
)
return
audio_url
This diff is collapsed.
Click to expand it.
program/serializers.py
+
3
−
2
View file @
b126918a
...
...
@@ -28,6 +28,7 @@ from profile.serializers import ProfileSerializer
from
program.models
import
Show
,
Schedule
,
TimeSlot
,
Category
,
FundingCategory
,
Host
,
Topic
,
MusicFocus
,
Note
,
Type
,
Language
,
\
RRule
,
Link
from
steering.settings
import
THUMBNAIL_SIZES
from
utils
import
get_audio_url
class
UserSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -363,7 +364,7 @@ class NoteSerializer(serializers.ModelSerializer):
validated_data
[
'
user_id
'
]
=
self
.
context
[
'
user_id
'
]
# Try to retrieve audio URL from CBA
validated_data
[
'
audio_url
'
]
=
Note
.
get_audio_url
(
validated_data
[
'
cba_id
'
])
validated_data
[
'
audio_url
'
]
=
get_audio_url
(
validated_data
[
'
cba_id
'
])
note
=
Note
.
objects
.
create
(
**
validated_data
)
...
...
@@ -392,7 +393,7 @@ class NoteSerializer(serializers.ModelSerializer):
instance
.
status
=
validated_data
.
get
(
'
status
'
,
instance
.
status
)
instance
.
host
=
validated_data
.
get
(
'
host
'
,
instance
.
host
)
instance
.
cba_id
=
validated_data
.
get
(
'
cba_id
'
,
instance
.
cba_id
)
instance
.
audio_url
=
Note
.
get_audio_url
(
instance
.
cba_id
)
instance
.
audio_url
=
get_audio_url
(
instance
.
cba_id
)
instance
.
save
()
...
...
This diff is collapsed.
Click to expand it.
program/utils.py
+
26
−
0
View file @
b126918a
...
...
@@ -20,8 +20,11 @@
from
datetime
import
datetime
import
requests
from
django.utils
import
timezone
from
steering.settings
import
CBA_AJAX_URL
,
CBA_API_KEY
,
DEBUG
def
parse_datetime
(
date_string
:
str
)
->
datetime
:
"""
...
...
@@ -33,3 +36,26 @@ def parse_datetime(date_string: str) -> datetime:
parsed_datetime
=
datetime
.
strptime
(
date_string
,
"
%Y-%m-%d %H:%M:%S%z
"
)
return
timezone
.
make_aware
(
parsed_datetime
)
def
get_audio_url
(
cba_id
):
"""
Retrieve the direct URL to the mp3 in CBA
In order to retrieve the URL, stations need
- to be whitelisted by CBA
- an API Key
For these contact cba@fro.at
"""
if
cba_id
is
None
or
cba_id
==
''
or
CBA_API_KEY
==
''
:
return
None
else
:
if
DEBUG
:
url
=
'
https://cba.fro.at/wp-content/plugins/cba/ajax/cba-get-filename.php?post_id=
'
+
str
(
cba_id
)
+
'
&c=Ml3fASkfwR8
'
else
:
url
=
CBA_AJAX_URL
+
'
?action=cba_ajax_get_filename&post_id=
'
+
str
(
cba_id
)
+
'
&api_key=
'
+
CBA_API_KEY
audio_url
=
requests
.
get
(
url
).
json
()
return
audio_url
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