Commit Graph

60 Commits

Author SHA1 Message Date
Scott McGrath 5b4c720e10
fix(playout): improve the way hashlib is called in libretime_playout/player (#3135)
### Description

Improves the way hashlib is called in libretime_playout/player so that
is isn't broken on systems with python < 3.9

The way it is currently called in
site-packages/libretime_playout/player/file.py, in the section where
scheduled files are copied to the cache dir for playout, specifies the
usedforsecurity=False flag as follows:
`hasher = hashlib.md5(usedforsecurity=False)`

hashlib.md5 did not support this flag until Python 3.9. Attempting to
specify the flag directly as an argument to hashlib.md5(), in an older
python environment (such as that in Ubuntu Focal 20.04), is unsafe, and
can cause hashlib.md5() to balk/throw an exception, which results in
file copy operations failing. This then precipitates into playout
problems, as scheduled media is missing from the cache folder.


This PR instead calls using hashlib.new(), and passes the argument to
that, as follows:
`hasher = hashlib.new('md5', usedforsecurity=False)`

This method of calling with the flag argument is safer, because the
constructor will take it or leave it gracefully, regardless of whether
the system has a version of hashlib that supports the `usedforsecurity`
flag. AFAICT, it improves (fixes) function on older systems without
negatively impacting others.

### Testing Notes

**What I did:**
Before applying this patch, we were experiencing occasional but fairly
regular periods of silence when the system was supposed to be playing a
song or track. This behavior was consistent with errors such as the
following being present in the playout log:
```
2025-01-15 14:01:28,331 | INFO     | libretime_playout.player.file:copy_file:47 - copying file 19834 to cache /var/lib/libretime/playout/scheduler/19834.mp3
2025-01-15 14:01:28,466 | ERROR    | libretime_playout.player.file:copy_file:77 - could not copy file 19834 to /var/lib/libretime/playout/scheduler/19834.mp3: 'usedforsecurity' is an invalid keyword argument for openssl_md5()
Traceback (most recent call last):
  File "/opt/libretime/lib/python3.8/site-packages/libretime_playout/player/file.py", line 70, in copy_file
    file_event.filesize = self.report_file_size_and_md5_to_api(
  File "/opt/libretime/lib/python3.8/site-packages/libretime_playout/player/file.py", line 89, in report_file_size_and_md5_to_api
    hasher = hashlib.md5(usedforsecurity=False)
TypeError: 'usedforsecurity' is an invalid keyword argument for openssl_md5()
```
_For more information about the characterization and results of this
problem, see issue #3134_

**Testing on running systems**
After the patch was applied, these errors were no longer seen. I first
tested this on a dev server, and then on a live server, with
approximately 100 distinct tracks of playout occurring over about 24
hours. There were no file copy failures, and no related playout
problems, which was a major and immediate improvement.

**Testing installer, fresh installs**
***Ubuntu 20.04***
I deployed a patch to the installer and installed it on a blank system
running Ubuntu 20.04 and tested it to make sure the fix was applied and
worked.

***Debian 11***
I deployed patch to the installer and installed it on a blank system
running Debian Bullseye (which runs python = 3.9) , and tested it there
to make sure it did not break anything or introduce a regression.


### **Links**

Closes: #3134
2025-01-17 23:11:02 +00:00
Kyle Robbertze 81e8fa90ed
chore: fix linting ignore comments (#3084)
### Description

There is now a too-many-positional-arguments check
2024-09-30 16:08:23 +01:00
Jonas L 40b4fc7f66
feat: build schedule events exclusively in playout (#2946)
### Description

Build and use the schedule events only in playout, the events generated
by legacy are not used anymore.

This ensure that we don't have to maintain 2 different implementation in
2 different languages. We still need the php function to run to make
sure the side effects of this function are executed (filling the
schedule in the DB).
2024-04-27 20:09:16 +02:00
Jonas L 35d0dec4a8
fix: apply replay gain preferences on scheduled files (#2945)
### Description

The replay gain preferences are applied in the legacy code, but the
playout code was missing this feature. The replay gain was not applied
when playout fetched the schedules.


37d1a7685e/legacy/application/models/Schedule.php (L881-L886)
2024-02-08 20:29:10 +01:00
Jonas L 2facbfaff2
fix(playout): remove empty file when the download request failed (#2864) 2024-01-01 13:16:13 +01:00
Jonas L 7ed1be1816
fix(playout): increase file download chunk size to 8192 bytes (#2863) 2024-01-01 13:07:27 +01:00
Jonas L 9d6061e42e
refactor(playout): fix deprecation warnings (#2847)
### Description
Fix pydantic deprecation warnings after upgrade to v2.
2023-12-28 14:19:29 +01:00
jo 43cc2bc4f0 chore: fix comment wording 2023-04-03 15:29:36 +01:00
jo ce27615a24 refactor(playout): rename PypoLiquidsoap to Liquidsoap 2023-04-03 15:29:36 +01:00
jo f68bc2da88 refactor(playout): remove irrelevant try/except 2023-04-03 15:29:36 +01:00
jo 964ee7e07c refactor(playout): add ended check to event class 2023-04-03 15:29:36 +01:00
jo 161f2ccdcb refactor(playout): merge liquidsoap modules 2023-04-03 15:29:36 +01:00
jo 4c63ef71fc feat(playout): replace thread timeout with socket timeout
Prefer the lower level socket timeout feature, to the hand made threaded
timeout. The thread timeout does not raise or log the errors that may occur
during the communication with liquidsoap, and we should handle them
instead.
2023-04-03 15:29:36 +01:00
jo 6412b17996 fix(playout): catch oserror in liquidsoap client
Prevent playout crash when liquidsoap is not yet reachable.
2023-03-30 20:49:07 +01:00
jo a1db2a157a feat(playout): replace schedule event dicts with objects 2023-03-22 13:05:57 +00:00
jo 684e7a6f24 chore: move mime type utils 2023-03-22 13:05:57 +00:00
jo 74af2112a6 fix(playout): quote incompatible <py3.9 type hints 2023-03-22 09:11:56 +00:00
jo 719464a272 refactor(playout): add more typings 2023-03-04 17:06:16 +02:00
jo 1bdfeb570d fix(playout): use int for liquidsoap queues map 2023-03-04 17:06:16 +02:00
jo b17ff4afad test(playout): silence existing broad-exception-caught errors 2023-03-04 17:06:16 +02:00
jo a77321190f refactor(playout): fix linting errors 2023-03-04 17:06:16 +02:00
jo 0a9848efdd refactor(playout): init mimetypes only once 2023-03-04 17:06:16 +02:00
jo c7c3dba712 fix(playout): prevent unbound variables 2023-03-04 17:06:16 +02:00
jo 5042704d42 feat(playout): don't serialize message twice 2023-03-04 17:06:16 +02:00
jo e88e843b65 refactor(playout): add typings and fix linting errors
move EVENT_KEY_FORMAT to events module
properly type fetch queue
event start/end can be str or datetime
2023-02-26 20:05:12 +01:00
jo 3fba7c73d3 refactor(playout): remove unecesary cache dir creation 2023-02-26 20:05:12 +01:00
jo 00648b8f94 refactor(playout): unwrap schedule.media dict 2023-02-26 20:05:12 +01:00
jo 0d4e2823e2 refactor(playout): add event dict typings 2023-02-26 20:05:12 +01:00
jo cd0d9b6f4a refactor(playout): rename event kinds enums 2023-02-26 20:05:12 +01:00
jo 861698987c refactor: don't use f-string on logging statements
The strings are now be formatted if the logging level is enabled.
2023-02-26 19:09:51 +02:00
jo c6940db289 feat: replace loguru with logging 2023-02-26 19:09:51 +02:00
jo 719d7cff36 fix(playout): use the same number of schedule queues 2023-02-25 21:43:37 +02:00
jo a0f232ba66 feat(playout): remove unused liquidsoap outputs connection status 2023-02-25 21:43:37 +02:00
jo f8f6fda794 chore: raise from specific exceptions 2023-02-03 07:36:58 +02:00
jo bd76971312 style: format code using black 2023-02-01 11:17:49 +01:00
jo 4ada25a3ff fix(playout): add types
This reverts commit d6348d5575.
2022-10-11 09:28:52 +02:00
jo d29d837d01 feat: drop Python 3.6 support 2022-10-10 20:11:33 +02:00
jo b1c2e34ceb fix(playout): remove shutdown_handler 2022-09-16 13:16:06 +02:00
jo 64b3d164c9 refactor(playout): move daemon flag to thread class 2022-09-16 12:33:44 +02:00
Jonas L 03902f6aef
fix(playout): also shutdown on SIGTERM (#2104) 2022-09-08 12:41:56 +02:00
Jonas L ef1de34111
fix(playout): missing live show events (#2087) 2022-09-06 14:09:04 +02:00
jo c8cb100645 feat(playout): liquidsoap boostrap using new api endpoints 2022-09-06 13:21:54 +02:00
jo 2fa045a8ef feat(playout): remove stream_setting update handler 2022-09-06 13:21:54 +02:00
jo f5a83dbabb feat(playout): allow updating message_offline value 2022-09-06 13:21:54 +02:00
Jonas L 510d55c7c1
feat(playout): improve generate_*_events (#2088) 2022-09-05 18:41:04 +02:00
jo d6348d5575 fix(playout): py36 compatibility broken typings
This partially reverts commit 5505222df6.
2022-09-01 19:17:33 +02:00
jo 5505222df6 refactor(playout): rename vars and add typing 2022-08-21 16:13:34 +02:00
jo a9cd1fb3df refactor(playout): move liq io to liq_client 2022-08-18 08:36:41 +02:00
jo da6458caea feat(playout): integrate new liquisoap client 2022-08-17 13:18:13 +02:00
Jonas L bddbdf716c
chore(playout): remove unused code (#2058) 2022-08-14 19:56:48 +02:00