Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Citronalco
FM4-7Tage-Download
Commits
c200fbe9
Commit
c200fbe9
authored
Sep 19, 2020
by
Bernhard Geier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
02cd0179
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
fm4-7tage-download.py
fm4-7tage-download.py
+22
-19
No files found.
fm4-7tage-download.py
View file @
c200fbe9
...
...
@@ -156,8 +156,8 @@ for hit in result['hits']:
for
streamPartNr
in
range
(
0
,
len
(
streamParts
)):
partInfo
=
{
'url'
:
broadcastJson
[
'streams'
][
streamPartNr
][
'loopStreamId'
],
'start_
at_m
s'
:
broadcastJson
[
'streams'
][
streamPartNr
][
'start'
],
'end_
at_m
s'
:
broadcastJson
[
'streams'
][
streamPartNr
][
'end'
],
'start_
t
s'
:
broadcastJson
[
'streams'
][
streamPartNr
][
'start'
],
'end_
t
s'
:
broadcastJson
[
'streams'
][
streamPartNr
][
'end'
],
'duration_ms'
:
broadcastJson
[
'streams'
][
streamPartNr
][
'end'
]
-
broadcastJson
[
'streams'
][
streamPartNr
][
'start'
],
'title'
:
None
,
'filename'
:
None
,
...
...
@@ -201,9 +201,9 @@ for hit in result['hits']:
for
item
in
sorted
(
broadcastJson
[
'items'
],
key
=
lambda
x
:
x
[
'start'
]):
if
item
[
'entity'
]
==
"BroadcastItem"
:
# skip items that end too early or start too soon for the current stream part
if
item
[
'end'
]
<=
partInfo
[
'start_
at_m
s'
]:
if
item
[
'end'
]
<=
partInfo
[
'start_
t
s'
]:
continue
if
item
[
'start'
]
>=
partInfo
[
'end_
at_m
s'
]:
if
item
[
'start'
]
>=
partInfo
[
'end_
t
s'
]:
break
chapterNr
+=
1
...
...
@@ -225,11 +225,11 @@ for hit in result['hits']:
# for multipart shows sometimes chapters start in the previous part, so the start time is negative
# In ID3 chapter start times must be >=0, so we set chapter start to 0 in that case
chapterInfo
[
'start_ms'
]
=
item
[
'start'
]
-
partInfo
[
'start_
at_m
s'
]
chapterInfo
[
'start_ms'
]
=
item
[
'start'
]
-
partInfo
[
'start_
t
s'
]
if
chapterInfo
[
'start_ms'
]
<
0
:
chapterInfo
[
'start_ms'
]
=
0
chapterInfo
[
'end_ms'
]
=
item
[
'end'
]
-
partInfo
[
'start_
at_m
s'
]
# FIXME: chapters (and shows?) seem to be 1s too long
chapterInfo
[
'end_ms'
]
=
item
[
'end'
]
-
partInfo
[
'start_
t
s'
]
# FIXME: chapters (and shows?) seem to be 1s too long
if
chapterInfo
[
'end_ms'
]
>
partInfo
[
'duration_ms'
]:
chapterInfo
[
'end_ms'
]
=
partInfo
[
'duration_ms'
]
...
...
@@ -237,8 +237,10 @@ for hit in result['hits']:
showInfo
[
'parts'
].
append
(
partInfo
)
print
(
showInfo
[
'parts'
])
if
not
createSingleFile
==
True
and
not
len
(
showInfo
[
'parts'
])
<=
1
:
# set ID3 tags
try
:
tags
=
ID3
(
partInfo
[
'filepath'
]
+
".part"
)
...
...
@@ -276,6 +278,7 @@ for hit in result['hits']:
sub_frames
=
[
TIT2
(
text
=
[
"Table Of Contents"
])]
))
if
showInfo
[
'image_mime'
]
is
not
None
and
showInfo
[
'image_data'
]
is
not
None
:
tags
.
add
(
APIC
(
mime
=
showInfo
[
'image_mime'
],
desc
=
"Front Cover"
,
data
=
showInfo
[
'image_data'
]))
...
...
@@ -291,14 +294,14 @@ for hit in result['hits']:
print
(
"done."
,
flush
=
True
)
if
createSingleFile
==
True
and
len
(
showInfo
[
'parts'
]
>
1
)
:
else
:
singleFile
=
{
'title'
:
None
,
'filename'
:
None
,
'filepath'
:
None
,
'start_ts'
:
broadcastJson
[
'streams'
][
0
][
'start'
],
'end_ts'
:
broadcastJson
[
'streams'
][
len
(
streamParts
)
-
1
][
'end'
],
'duration_ms'
:
sum
(
list
(
part
[
'end_ts'
]
-
part
[
'start_ts'
]
for
part
s
in
showInfo
)),
'duration_ms'
:
sum
(
list
(
part
[
'end_ts'
]
-
part
[
'start_ts'
]
for
part
in
showInfo
[
'parts'
]
)),
'title'
:
showInfo
[
'start_dt'
].
strftime
(
"%Y-%m-%d %H:%M"
),
'chapters'
:
[],
}
...
...
@@ -307,7 +310,7 @@ for hit in result['hits']:
singleFile
[
'title'
]
=
showInfo
[
'start_dt'
].
strftime
(
"%Y-%m-%d %H:%M"
)
# filename
singleFile
[
'filename'
]
=
re
.
sub
(
'[^\w\s\-\.\[\]]'
,
'_'
,
showInfo
[
'name'
]
+
" "
+
title
)
singleFile
[
'filename'
]
=
re
.
sub
(
'[^\w\s\-\.\[\]]'
,
'_'
,
showInfo
[
'name'
]
+
" "
+
singleFile
[
'
title
'
]
)
# prepend station name to filename
match
=
re
.
search
(
'^'
+
stationInfo
[
'name'
]
+
' '
,
singleFile
[
'filename'
])
if
not
match
:
...
...
@@ -318,30 +321,30 @@ for hit in result['hits']:
singleFile
[
'filepath'
]
=
os
.
path
.
join
(
DESTDIR
,
singleFile
[
'filename'
])
# concat parts (pydub creates a wav file and re-encodes it afterwards...)
showAudio
=
sum
(
(
AudioSegment
.
from_mp3
(
part
[
'filepath'
])
for
part
in
showInfo
[
'parts'
])
)
showAudio
=
sum
(
(
AudioSegment
.
from_mp3
(
part
[
'filepath'
]
+
".part"
)
for
part
in
showInfo
[
'parts'
])
)
showAudio
.
export
(
singleFile
[
'filepath'
]
+
'.part'
,
format
=
"mp3"
)
# remove part files
for
part
in
showInfo
[
'parts'
]:
os
.
remove
(
part
[
'filepath'
])
os
.
remove
(
part
[
'filepath'
]
+
".part"
)
# recalculate chapter marks under consideration of gaps
prevPartEnd_ts
=
showInfo
[
'parts'
][
0
][
'start_
d
t'
]
prevPartEnd_ts
=
showInfo
[
'parts'
][
0
][
'start_t
s
'
]
gap_ms
=
0
chapterNr
=
0
for
part
s
in
s
howInfo
:
gap_ms
+=
p
revPartEnd
_ts
-
p
art
[
'start
_ts
'
]
for
chapter
in
chapters
:
for
part
in
s
orted
(
showInfo
[
'parts'
],
key
=
lambda
x
:
x
[
'start_ts'
])
:
gap_ms
+=
p
art
[
'start
_ts
'
]
-
p
revPartEnd
_ts
for
chapter
in
part
[
'
chapters
'
]
:
chapterNr
+=
1
newChapterInfo
=
{
"id"
:
"ch"
+
str
(
chapterNr
),
"title"
:
chapter
[
'title'
],
"start_ms"
:
chapter
[
'start_ms'
]
+
gap_ms
,
"title"
:
chapter
[
'title'
],
"start_ms"
:
chapter
[
'start_ms'
]
+
gap_ms
,
"end_ms"
:
chapter
[
'end_ms'
]
+
gap_ms
,
}
singleFile
[
'chapters'
].
append
(
newChapterInfo
)
prevPartEnd_ts
=
part
[
'end_ts'
]
singleFile
[
'chapters'
].
append
(
newChapterInfo
)
# set ID3 tags
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment