initial
This commit is contained in:
commit
5c24306cfc
6 changed files with 664 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/.vscode/
|
||||
stubs/
|
0
README.md
Normal file
0
README.md
Normal file
265
poetry.lock
generated
Normal file
265
poetry.lock
generated
Normal file
|
@ -0,0 +1,265 @@
|
|||
# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2023.5.7"
|
||||
description = "Python package for providing Mozilla's CA Bundle."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
files = [
|
||||
{file = "certifi-2023.5.7-py3-none-any.whl", hash = "sha256:c6c2e98f5c7869efca1f8916fed228dd91539f9f1b444c314c06eef02980c716"},
|
||||
{file = "certifi-2023.5.7.tar.gz", hash = "sha256:0f0d56dc5a6ad56fd4ba36484d6cc34451e1c6548c61daad8c320169f91eddc7"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "charset-normalizer"
|
||||
version = "3.1.0"
|
||||
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7.0"
|
||||
files = [
|
||||
{file = "charset-normalizer-3.1.0.tar.gz", hash = "sha256:34e0a2f9c370eb95597aae63bf85eb5e96826d81e3dcf88b8886012906f509b5"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:e0ac8959c929593fee38da1c2b64ee9778733cdf03c482c9ff1d508b6b593b2b"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d7fc3fca01da18fbabe4625d64bb612b533533ed10045a2ac3dd194bfa656b60"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:04eefcee095f58eaabe6dc3cc2262f3bcd776d2c67005880894f447b3f2cb9c1"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:20064ead0717cf9a73a6d1e779b23d149b53daf971169289ed2ed43a71e8d3b0"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1435ae15108b1cb6fffbcea2af3d468683b7afed0169ad718451f8db5d1aff6f"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c84132a54c750fda57729d1e2599bb598f5fa0344085dbde5003ba429a4798c0"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:75f2568b4189dda1c567339b48cba4ac7384accb9c2a7ed655cd86b04055c795"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:11d3bcb7be35e7b1bba2c23beedac81ee893ac9871d0ba79effc7fc01167db6c"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:891cf9b48776b5c61c700b55a598621fdb7b1e301a550365571e9624f270c203"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:5f008525e02908b20e04707a4f704cd286d94718f48bb33edddc7d7b584dddc1"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:b06f0d3bf045158d2fb8837c5785fe9ff9b8c93358be64461a1089f5da983137"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_s390x.whl", hash = "sha256:49919f8400b5e49e961f320c735388ee686a62327e773fa5b3ce6721f7e785ce"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:22908891a380d50738e1f978667536f6c6b526a2064156203d418f4856d6e86a"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-win32.whl", hash = "sha256:12d1a39aa6b8c6f6248bb54550efcc1c38ce0d8096a146638fd4738e42284448"},
|
||||
{file = "charset_normalizer-3.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:65ed923f84a6844de5fd29726b888e58c62820e0769b76565480e1fdc3d062f8"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:9a3267620866c9d17b959a84dd0bd2d45719b817245e49371ead79ed4f710d19"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6734e606355834f13445b6adc38b53c0fd45f1a56a9ba06c2058f86893ae8017"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f8303414c7b03f794347ad062c0516cee0e15f7a612abd0ce1e25caf6ceb47df"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:aaf53a6cebad0eae578f062c7d462155eada9c172bd8c4d250b8c1d8eb7f916a"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3dc5b6a8ecfdc5748a7e429782598e4f17ef378e3e272eeb1340ea57c9109f41"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e1b25e3ad6c909f398df8921780d6a3d120d8c09466720226fc621605b6f92b1"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0ca564606d2caafb0abe6d1b5311c2649e8071eb241b2d64e75a0d0065107e62"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b82fab78e0b1329e183a65260581de4375f619167478dddab510c6c6fb04d9b6"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:bd7163182133c0c7701b25e604cf1611c0d87712e56e88e7ee5d72deab3e76b5"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:11d117e6c63e8f495412d37e7dc2e2fff09c34b2d09dbe2bee3c6229577818be"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:cf6511efa4801b9b38dc5546d7547d5b5c6ef4b081c60b23e4d941d0eba9cbeb"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_s390x.whl", hash = "sha256:abc1185d79f47c0a7aaf7e2412a0eb2c03b724581139193d2d82b3ad8cbb00ac"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:cb7b2ab0188829593b9de646545175547a70d9a6e2b63bf2cd87a0a391599324"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-win32.whl", hash = "sha256:c36bcbc0d5174a80d6cccf43a0ecaca44e81d25be4b7f90f0ed7bcfbb5a00909"},
|
||||
{file = "charset_normalizer-3.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:cca4def576f47a09a943666b8f829606bcb17e2bc2d5911a46c8f8da45f56755"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0c95f12b74681e9ae127728f7e5409cbbef9cd914d5896ef238cc779b8152373"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fca62a8301b605b954ad2e9c3666f9d97f63872aa4efcae5492baca2056b74ab"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ac0aa6cd53ab9a31d397f8303f92c42f534693528fafbdb997c82bae6e477ad9"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c3af8e0f07399d3176b179f2e2634c3ce9c1301379a6b8c9c9aeecd481da494f"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a5fc78f9e3f501a1614a98f7c54d3969f3ad9bba8ba3d9b438c3bc5d047dd28"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:628c985afb2c7d27a4800bfb609e03985aaecb42f955049957814e0491d4006d"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:74db0052d985cf37fa111828d0dd230776ac99c740e1a758ad99094be4f1803d"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:1e8fcdd8f672a1c4fc8d0bd3a2b576b152d2a349782d1eb0f6b8e52e9954731d"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:04afa6387e2b282cf78ff3dbce20f0cc071c12dc8f685bd40960cc68644cfea6"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_s390x.whl", hash = "sha256:dd5653e67b149503c68c4018bf07e42eeed6b4e956b24c00ccdf93ac79cdff84"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:d2686f91611f9e17f4548dbf050e75b079bbc2a82be565832bc8ea9047b61c8c"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-win32.whl", hash = "sha256:4155b51ae05ed47199dc5b2a4e62abccb274cee6b01da5b895099b61b1982974"},
|
||||
{file = "charset_normalizer-3.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:322102cdf1ab682ecc7d9b1c5eed4ec59657a65e1c146a0da342b78f4112db23"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:e633940f28c1e913615fd624fcdd72fdba807bf53ea6925d6a588e84e1151531"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:3a06f32c9634a8705f4ca9946d667609f52cf130d5548881401f1eb2c39b1e2c"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7381c66e0561c5757ffe616af869b916c8b4e42b367ab29fedc98481d1e74e14"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3573d376454d956553c356df45bb824262c397c6e26ce43e8203c4c540ee0acb"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e89df2958e5159b811af9ff0f92614dabf4ff617c03a4c1c6ff53bf1c399e0e1"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:78cacd03e79d009d95635e7d6ff12c21eb89b894c354bd2b2ed0b4763373693b"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:de5695a6f1d8340b12a5d6d4484290ee74d61e467c39ff03b39e30df62cf83a0"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1c60b9c202d00052183c9be85e5eaf18a4ada0a47d188a83c8f5c5b23252f649"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:f645caaf0008bacf349875a974220f1f1da349c5dbe7c4ec93048cdc785a3326"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:ea9f9c6034ea2d93d9147818f17c2a0860d41b71c38b9ce4d55f21b6f9165a11"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:80d1543d58bd3d6c271b66abf454d437a438dff01c3e62fdbcd68f2a11310d4b"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_s390x.whl", hash = "sha256:73dc03a6a7e30b7edc5b01b601e53e7fc924b04e1835e8e407c12c037e81adbd"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:6f5c2e7bc8a4bf7c426599765b1bd33217ec84023033672c1e9a8b35eaeaaaf8"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-win32.whl", hash = "sha256:12a2b561af122e3d94cdb97fe6fb2bb2b82cef0cdca131646fdb940a1eda04f0"},
|
||||
{file = "charset_normalizer-3.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:3160a0fd9754aab7d47f95a6b63ab355388d890163eb03b2d2b87ab0a30cfa59"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:38e812a197bf8e71a59fe55b757a84c1f946d0ac114acafaafaf21667a7e169e"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6baf0baf0d5d265fa7944feb9f7451cc316bfe30e8df1a61b1bb08577c554f31"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8f25e17ab3039b05f762b0a55ae0b3632b2e073d9c8fc88e89aca31a6198e88f"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3747443b6a904001473370d7810aa19c3a180ccd52a7157aacc264a5ac79265e"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b116502087ce8a6b7a5f1814568ccbd0e9f6cfd99948aa59b0e241dc57cf739f"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d16fd5252f883eb074ca55cb622bc0bee49b979ae4e8639fff6ca3ff44f9f854"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:21fa558996782fc226b529fdd2ed7866c2c6ec91cee82735c98a197fae39f706"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6f6c7a8a57e9405cad7485f4c9d3172ae486cfef1344b5ddd8e5239582d7355e"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:ac3775e3311661d4adace3697a52ac0bab17edd166087d493b52d4f4f553f9f0"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:10c93628d7497c81686e8e5e557aafa78f230cd9e77dd0c40032ef90c18f2230"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:6f4f4668e1831850ebcc2fd0b1cd11721947b6dc7c00bf1c6bd3c929ae14f2c7"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_s390x.whl", hash = "sha256:0be65ccf618c1e7ac9b849c315cc2e8a8751d9cfdaa43027d4f6624bd587ab7e"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:53d0a3fa5f8af98a1e261de6a3943ca631c526635eb5817a87a59d9a57ebf48f"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-win32.whl", hash = "sha256:a04f86f41a8916fe45ac5024ec477f41f886b3c435da2d4e3d2709b22ab02af1"},
|
||||
{file = "charset_normalizer-3.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:830d2948a5ec37c386d3170c483063798d7879037492540f10a475e3fd6f244b"},
|
||||
{file = "charset_normalizer-3.1.0-py3-none-any.whl", hash = "sha256:3d9098b479e78c85080c98e1e35ff40b4a31d8953102bb0fd7d1b6f8a2111a3d"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "3.4"
|
||||
description = "Internationalized Domain Names in Applications (IDNA)"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.5"
|
||||
files = [
|
||||
{file = "idna-3.4-py3-none-any.whl", hash = "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"},
|
||||
{file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mfrc522"
|
||||
version = "0.0.7"
|
||||
description = "A library to integrate the MFRC522 RFID readers with the Raspberry Pi"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "mfrc522-0.0.7-py2-none-any.whl", hash = "sha256:5f0e06d2ca4550d545478b20edb6661d5da943e75b3d4542ba9eb9eef4e541e7"},
|
||||
{file = "mfrc522-0.0.7-py3-none-any.whl", hash = "sha256:874fd0385a7e40190063b60af83d615534b1f764c6b776fed1fcc94551c1e62f"},
|
||||
{file = "mfrc522-0.0.7.tar.gz", hash = "sha256:74c7020a4fc4870f5d7022542c36143fba771055a2fae2e5929e6a1159d2bf00"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
"RPi.GPIO" = "*"
|
||||
spidev = "*"
|
||||
|
||||
[[package]]
|
||||
name = "pydantic"
|
||||
version = "1.10.7"
|
||||
description = "Data validation and settings management using python type hints"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "pydantic-1.10.7-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e79e999e539872e903767c417c897e729e015872040e56b96e67968c3b918b2d"},
|
||||
{file = "pydantic-1.10.7-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:01aea3a42c13f2602b7ecbbea484a98169fb568ebd9e247593ea05f01b884b2e"},
|
||||
{file = "pydantic-1.10.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:516f1ed9bc2406a0467dd777afc636c7091d71f214d5e413d64fef45174cfc7a"},
|
||||
{file = "pydantic-1.10.7-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ae150a63564929c675d7f2303008d88426a0add46efd76c3fc797cd71cb1b46f"},
|
||||
{file = "pydantic-1.10.7-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:ecbbc51391248116c0a055899e6c3e7ffbb11fb5e2a4cd6f2d0b93272118a209"},
|
||||
{file = "pydantic-1.10.7-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:f4a2b50e2b03d5776e7f21af73e2070e1b5c0d0df255a827e7c632962f8315af"},
|
||||
{file = "pydantic-1.10.7-cp310-cp310-win_amd64.whl", hash = "sha256:a7cd2251439988b413cb0a985c4ed82b6c6aac382dbaff53ae03c4b23a70e80a"},
|
||||
{file = "pydantic-1.10.7-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:68792151e174a4aa9e9fc1b4e653e65a354a2fa0fed169f7b3d09902ad2cb6f1"},
|
||||
{file = "pydantic-1.10.7-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:dfe2507b8ef209da71b6fb5f4e597b50c5a34b78d7e857c4f8f3115effaef5fe"},
|
||||
{file = "pydantic-1.10.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:10a86d8c8db68086f1e30a530f7d5f83eb0685e632e411dbbcf2d5c0150e8dcd"},
|
||||
{file = "pydantic-1.10.7-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d75ae19d2a3dbb146b6f324031c24f8a3f52ff5d6a9f22f0683694b3afcb16fb"},
|
||||
{file = "pydantic-1.10.7-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:464855a7ff7f2cc2cf537ecc421291b9132aa9c79aef44e917ad711b4a93163b"},
|
||||
{file = "pydantic-1.10.7-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:193924c563fae6ddcb71d3f06fa153866423ac1b793a47936656e806b64e24ca"},
|
||||
{file = "pydantic-1.10.7-cp311-cp311-win_amd64.whl", hash = "sha256:b4a849d10f211389502059c33332e91327bc154acc1845f375a99eca3afa802d"},
|
||||
{file = "pydantic-1.10.7-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:cc1dde4e50a5fc1336ee0581c1612215bc64ed6d28d2c7c6f25d2fe3e7c3e918"},
|
||||
{file = "pydantic-1.10.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e0cfe895a504c060e5d36b287ee696e2fdad02d89e0d895f83037245218a87fe"},
|
||||
{file = "pydantic-1.10.7-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:670bb4683ad1e48b0ecb06f0cfe2178dcf74ff27921cdf1606e527d2617a81ee"},
|
||||
{file = "pydantic-1.10.7-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:950ce33857841f9a337ce07ddf46bc84e1c4946d2a3bba18f8280297157a3fd1"},
|
||||
{file = "pydantic-1.10.7-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:c15582f9055fbc1bfe50266a19771bbbef33dd28c45e78afbe1996fd70966c2a"},
|
||||
{file = "pydantic-1.10.7-cp37-cp37m-win_amd64.whl", hash = "sha256:82dffb306dd20bd5268fd6379bc4bfe75242a9c2b79fec58e1041fbbdb1f7914"},
|
||||
{file = "pydantic-1.10.7-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:8c7f51861d73e8b9ddcb9916ae7ac39fb52761d9ea0df41128e81e2ba42886cd"},
|
||||
{file = "pydantic-1.10.7-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:6434b49c0b03a51021ade5c4daa7d70c98f7a79e95b551201fff682fc1661245"},
|
||||
{file = "pydantic-1.10.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:64d34ab766fa056df49013bb6e79921a0265204c071984e75a09cbceacbbdd5d"},
|
||||
{file = "pydantic-1.10.7-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:701daea9ffe9d26f97b52f1d157e0d4121644f0fcf80b443248434958fd03dc3"},
|
||||
{file = "pydantic-1.10.7-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:cf135c46099ff3f919d2150a948ce94b9ce545598ef2c6c7bf55dca98a304b52"},
|
||||
{file = "pydantic-1.10.7-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b0f85904f73161817b80781cc150f8b906d521fa11e3cdabae19a581c3606209"},
|
||||
{file = "pydantic-1.10.7-cp38-cp38-win_amd64.whl", hash = "sha256:9f6f0fd68d73257ad6685419478c5aece46432f4bdd8d32c7345f1986496171e"},
|
||||
{file = "pydantic-1.10.7-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:c230c0d8a322276d6e7b88c3f7ce885f9ed16e0910354510e0bae84d54991143"},
|
||||
{file = "pydantic-1.10.7-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:976cae77ba6a49d80f461fd8bba183ff7ba79f44aa5cfa82f1346b5626542f8e"},
|
||||
{file = "pydantic-1.10.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7d45fc99d64af9aaf7e308054a0067fdcd87ffe974f2442312372dfa66e1001d"},
|
||||
{file = "pydantic-1.10.7-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d2a5ebb48958754d386195fe9e9c5106f11275867051bf017a8059410e9abf1f"},
|
||||
{file = "pydantic-1.10.7-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:abfb7d4a7cd5cc4e1d1887c43503a7c5dd608eadf8bc615413fc498d3e4645cd"},
|
||||
{file = "pydantic-1.10.7-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:80b1fab4deb08a8292d15e43a6edccdffa5377a36a4597bb545b93e79c5ff0a5"},
|
||||
{file = "pydantic-1.10.7-cp39-cp39-win_amd64.whl", hash = "sha256:d71e69699498b020ea198468e2480a2f1e7433e32a3a99760058c6520e2bea7e"},
|
||||
{file = "pydantic-1.10.7-py3-none-any.whl", hash = "sha256:0cd181f1d0b1d00e2b705f1bf1ac7799a2d938cce3376b8007df62b29be3c2c6"},
|
||||
{file = "pydantic-1.10.7.tar.gz", hash = "sha256:cfc83c0678b6ba51b0532bea66860617c4cd4251ecf76e9846fa5a9f3454e97e"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
typing-extensions = ">=4.2.0"
|
||||
|
||||
[package.extras]
|
||||
dotenv = ["python-dotenv (>=0.10.4)"]
|
||||
email = ["email-validator (>=1.0.3)"]
|
||||
|
||||
[[package]]
|
||||
name = "requests"
|
||||
version = "2.30.0"
|
||||
description = "Python HTTP for Humans."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "requests-2.30.0-py3-none-any.whl", hash = "sha256:10e94cc4f3121ee6da529d358cdaeaff2f1c409cd377dbc72b825852f2f7e294"},
|
||||
{file = "requests-2.30.0.tar.gz", hash = "sha256:239d7d4458afcb28a692cdd298d87542235f4ca8d36d03a15bfc128a6559a2f4"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
certifi = ">=2017.4.17"
|
||||
charset-normalizer = ">=2,<4"
|
||||
idna = ">=2.5,<4"
|
||||
urllib3 = ">=1.21.1,<3"
|
||||
|
||||
[package.extras]
|
||||
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
|
||||
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
|
||||
|
||||
[[package]]
|
||||
name = "rpi-gpio"
|
||||
version = "0.7.1"
|
||||
description = "A module to control Raspberry Pi GPIO channels"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "RPi.GPIO-0.7.1-cp27-cp27mu-linux_armv6l.whl", hash = "sha256:b86b66dc02faa5461b443a1e1f0c1d209d64ab5229696f32fb3b0215e0600c8c"},
|
||||
{file = "RPi.GPIO-0.7.1-cp310-cp310-linux_armv6l.whl", hash = "sha256:57b6c044ef5375a78c8dda27cdfadf329e76aa6943cd6cffbbbd345a9adf9ca5"},
|
||||
{file = "RPi.GPIO-0.7.1-cp37-cp37m-linux_armv6l.whl", hash = "sha256:77afb817b81331ce3049a4b8f94a85e41b7c404d8e56b61ac0f1eb75c3120868"},
|
||||
{file = "RPi.GPIO-0.7.1-cp38-cp38-linux_armv6l.whl", hash = "sha256:29226823da8b5ccb9001d795a944f2e00924eeae583490f0bc7317581172c624"},
|
||||
{file = "RPi.GPIO-0.7.1-cp39-cp39-linux_armv6l.whl", hash = "sha256:15311d3b063b71dee738cd26570effc9985a952454d162937c34e08c0fc99902"},
|
||||
{file = "RPi.GPIO-0.7.1.tar.gz", hash = "sha256:cd61c4b03c37b62bba4a5acfea9862749c33c618e0295e7e90aa4713fb373b70"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spidev"
|
||||
version = "3.6"
|
||||
description = "Python bindings for Linux SPI access through spidev"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "spidev-3.6-cp39-cp39-linux_armv7l.whl", hash = "sha256:280abc00a1ef7780ef62c3f294f52a2527b6c47d8c269fea98664970bcaf6da5"},
|
||||
{file = "spidev-3.6.tar.gz", hash = "sha256:14dbc37594a4aaef85403ab617985d3c3ef464d62bc9b769ef552db53701115b"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typing-extensions"
|
||||
version = "4.5.0"
|
||||
description = "Backported and Experimental Type Hints for Python 3.7+"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "typing_extensions-4.5.0-py3-none-any.whl", hash = "sha256:fb33085c39dd998ac16d1431ebc293a8b3eedd00fd4a32de0ff79002c19511b4"},
|
||||
{file = "typing_extensions-4.5.0.tar.gz", hash = "sha256:5cb5f4a79139d699607b3ef622a1dedafa84e115ab0024e0d9c044a9479ca7cb"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "2.0.2"
|
||||
description = "HTTP library with thread-safe connection pooling, file post, and more."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "urllib3-2.0.2-py3-none-any.whl", hash = "sha256:d055c2f9d38dc53c808f6fdc8eab7360b6fdbbde02340ed25cfbcd817c62469e"},
|
||||
{file = "urllib3-2.0.2.tar.gz", hash = "sha256:61717a1095d7e155cdb737ac7bb2f4324a858a1e2e6466f6d03ff630ca68d3cc"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"]
|
||||
secure = ["certifi", "cryptography (>=1.9)", "idna (>=2.0.0)", "pyopenssl (>=17.1.0)", "urllib3-secure-extra"]
|
||||
socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"]
|
||||
zstd = ["zstandard (>=0.18.0)"]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.9"
|
||||
content-hash = "69fa4cae8fcc407d68e6d0e028e333e36308c2572bf6c2490fdfd4a1e7cae4f0"
|
18
pyproject.toml
Normal file
18
pyproject.toml
Normal file
|
@ -0,0 +1,18 @@
|
|||
[tool.poetry]
|
||||
name = "sleepywaves"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["Asaril <pub@asaril.de>"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
spidev = "^3.6"
|
||||
mfrc522 = "^0.0.7"
|
||||
pydantic = "^1.10.7"
|
||||
requests = "^2.30.0"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
379
src/sleepywaves.py
Normal file
379
src/sleepywaves.py
Normal file
|
@ -0,0 +1,379 @@
|
|||
"""SleepyWaves
|
||||
|
||||
RFID/NFC-based sleep time audio player. """
|
||||
|
||||
from typing import Literal, Optional, Dict, Any, List, Union
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import logging
|
||||
import os
|
||||
import os.path
|
||||
import requests
|
||||
import time
|
||||
import urllib.parse
|
||||
|
||||
from dataclasses import dataclass
|
||||
from mfrc522.SimpleMFRC522 import SimpleMFRC522
|
||||
from pydantic import BaseModel
|
||||
from random import randrange
|
||||
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
log = logging.getLogger(__name__ if __name__ != "__main__" else "sleepywaves")
|
||||
log_levels = (
|
||||
"CRITICAL",
|
||||
"ERROR",
|
||||
"WARNING",
|
||||
"INFO",
|
||||
"DEBUG",
|
||||
)
|
||||
|
||||
PlayMode = Literal["random", "sequence"]
|
||||
|
||||
CONFIG_FILE_NAME = "config.json"
|
||||
NEW_CONFIG_FILE_NAME = "changeme_" + CONFIG_FILE_NAME
|
||||
STATUS_FILE_NAME = "status.json"
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
default_mode: PlayMode = "sequence"
|
||||
default_timeout: int = 8 * 60
|
||||
|
||||
|
||||
class TitleConfig(BaseModel):
|
||||
mode: Optional[PlayMode] = None
|
||||
timeout: Optional[int] = None
|
||||
resume_track: Optional[bool] = True
|
||||
|
||||
|
||||
class TitleStatus(BaseModel):
|
||||
last_track: str
|
||||
last_time: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class Title:
|
||||
tag_id: int
|
||||
config: TitleConfig
|
||||
status: TitleStatus
|
||||
tracks: list[str]
|
||||
|
||||
|
||||
class Renderer(ABC):
|
||||
@abstractmethod
|
||||
def get_tracks(self, path: str) -> list[str]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def play(self, path: str, from_time: int) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_time(self) -> int:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def stop(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def is_playing(self) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
class Player:
|
||||
reader: SimpleMFRC522
|
||||
current_title: Optional[Title]
|
||||
renderer: Renderer
|
||||
start_time: float
|
||||
old_tag: Optional[int]
|
||||
|
||||
def __init__(self, media_path: str, renderer: Renderer) -> None:
|
||||
self.reader = SimpleMFRC522()
|
||||
self.media_path = os.path.abspath(media_path)
|
||||
self.renderer = renderer
|
||||
self.current_title = None
|
||||
self.start_time = 0
|
||||
self.old_tag = None
|
||||
|
||||
if not os.path.exists(self.media_path):
|
||||
log.fatal(f"media path does not exists! expected:{self.media_path}")
|
||||
|
||||
cfg_path = os.path.join(self.media_path, CONFIG_FILE_NAME)
|
||||
if not os.path.exists(cfg_path):
|
||||
new_config = Config()
|
||||
with open(cfg_path, "w") as cfg_file:
|
||||
cfg_file.write(new_config.json(indent=2))
|
||||
log.debug(f"wrote new global config to:{cfg_path}")
|
||||
|
||||
log.debug(f"loading global config from: {cfg_path}")
|
||||
self.config = Config.parse_file(cfg_path)
|
||||
|
||||
def get_title_path(self, tag_id: int) -> str:
|
||||
return os.path.join(self.media_path, f"{tag_id:10x}")
|
||||
|
||||
def get_title_config(self, tag_id: int) -> Optional[TitleConfig]:
|
||||
title_path = self.get_title_path(tag_id)
|
||||
cfg_path = os.path.join(title_path, CONFIG_FILE_NAME)
|
||||
if os.path.exists(cfg_path):
|
||||
return TitleConfig.parse_file(cfg_path)
|
||||
return None
|
||||
|
||||
def get_title_status(self, tag_id: int) -> TitleStatus:
|
||||
title_path = self.get_title_path(tag_id)
|
||||
status_path = os.path.join(title_path, STATUS_FILE_NAME)
|
||||
if os.path.exists(status_path):
|
||||
log.debug(f"loading title status from {status_path}")
|
||||
return TitleStatus.parse_file(status_path)
|
||||
log.debug("created new title status")
|
||||
return TitleStatus(last_track="", last_time=0)
|
||||
|
||||
def create_title(self, tag_id: int) -> None:
|
||||
title_path = self.get_title_path(tag_id)
|
||||
if not os.path.exists(title_path):
|
||||
log.info(f"new title created: {title_path}")
|
||||
os.makedirs(title_path)
|
||||
new_cfg_path = os.path.join(title_path, NEW_CONFIG_FILE_NAME)
|
||||
new_config = TitleConfig(
|
||||
mode=self.config.default_mode, timeout=self.config.default_timeout
|
||||
)
|
||||
with open(new_cfg_path, "w") as cfg_file:
|
||||
cfg_file.write(new_config.json(indent=2))
|
||||
|
||||
def read_burst(self) -> Optional[int]:
|
||||
tag_id: Optional[int] = None
|
||||
for _ in range(10):
|
||||
tag_id = self.reader.read_id_no_block() # type:ignore
|
||||
if tag_id is not None:
|
||||
return tag_id
|
||||
return None
|
||||
|
||||
def advance(self) -> None:
|
||||
assert self.current_title is not None
|
||||
track_id = (
|
||||
self.current_title.tracks.index(self.current_title.status.last_track)
|
||||
if self.current_title.status.last_track
|
||||
else -1
|
||||
)
|
||||
log.debug(f"advance from #{track_id}: {self.current_title.status.last_track}")
|
||||
if self.current_title.config.mode == "sequence":
|
||||
track_id = (track_id + 1) % len(self.current_title.tracks)
|
||||
elif self.current_title.config.mode == "random":
|
||||
track_id = randrange(0, len(self.current_title.tracks), 1)
|
||||
self.current_title.status.last_track = self.current_title.tracks[track_id]
|
||||
self.current_title.status.last_time = 0
|
||||
log.debug(f"advance to #{track_id}: {self.current_title.status.last_track}")
|
||||
|
||||
def start_playing(self) -> None:
|
||||
if self.current_title is not None:
|
||||
track_path = os.path.join(
|
||||
self.get_title_path(self.current_title.tag_id),
|
||||
self.current_title.status.last_track,
|
||||
)
|
||||
log.debug(
|
||||
f"start_playing(): {track_path} @ {self.current_title.status.last_time}"
|
||||
)
|
||||
self.renderer.play(
|
||||
track_path,
|
||||
self.current_title.status.last_time,
|
||||
)
|
||||
|
||||
def stop_playing(self) -> None:
|
||||
if self.current_title is not None:
|
||||
log.debug("stop_playing()")
|
||||
if self.renderer.is_playing():
|
||||
self.current_title.status.last_time = self.renderer.get_time()
|
||||
log.debug(
|
||||
f"stop_playing(): renderer was playing @{self.current_title.status.last_time}"
|
||||
)
|
||||
self.renderer.stop()
|
||||
|
||||
status_path = os.path.join(
|
||||
self.get_title_path(self.current_title.tag_id), STATUS_FILE_NAME
|
||||
)
|
||||
with open(status_path, "w") as status_file:
|
||||
status_file.write(self.current_title.status.json(indent=2))
|
||||
self.current_title = None
|
||||
|
||||
def process(self):
|
||||
tag_id: Optional[int] = self.read_burst()
|
||||
|
||||
# current_tag = self.current_title.tag_id if self.current_title else None
|
||||
if tag_id != self.old_tag:
|
||||
log.debug(f"self.old_tag: {self.old_tag or 0:10x} tag_id:{tag_id or 0:10x}")
|
||||
if self.old_tag is not None:
|
||||
self.tag_removed()
|
||||
self.old_tag = None
|
||||
if tag_id is not None:
|
||||
self.tag_detected(tag_id)
|
||||
self.old_tag = tag_id
|
||||
|
||||
if self.current_title is not None:
|
||||
timeout = self.current_title.config.timeout or 0.0
|
||||
if timeout > 0 and time.time() - self.start_time >= timeout:
|
||||
log.debug("timeout reached")
|
||||
self.stop_playing()
|
||||
|
||||
if self.current_title is not None:
|
||||
if not self.renderer.is_playing():
|
||||
log.debug("process playing, next track needed")
|
||||
self.advance()
|
||||
self.start_playing()
|
||||
|
||||
def tag_detected(self, tag_id: int):
|
||||
log.info(f"tag detected: {tag_id:x}")
|
||||
cfg = self.get_title_config(tag_id)
|
||||
if not cfg:
|
||||
self.create_title(tag_id)
|
||||
else:
|
||||
self.current_title = Title(
|
||||
tag_id=tag_id,
|
||||
config=cfg,
|
||||
status=self.get_title_status(tag_id),
|
||||
tracks=self.renderer.get_tracks(self.get_title_path(tag_id)),
|
||||
)
|
||||
if (
|
||||
self.current_title.status.last_track == ""
|
||||
or self.current_title.config.resume_track is False
|
||||
):
|
||||
self.advance()
|
||||
self.start_playing()
|
||||
if (
|
||||
self.current_title.config.timeout is not None
|
||||
and self.current_title.config.timeout > 0
|
||||
):
|
||||
self.start_time = time.time()
|
||||
|
||||
def tag_removed(self):
|
||||
if self.current_title is not None:
|
||||
log.info(f"tag removed: {self.current_title.tag_id:x}")
|
||||
self.stop_playing()
|
||||
|
||||
|
||||
class DebugRenderer(Renderer):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.start: int = 0
|
||||
self.offset: int = 0
|
||||
|
||||
def get_tracks(self, path: str) -> list[str]:
|
||||
all_files = os.listdir(path)
|
||||
return sorted([f for f in all_files if f.endswith(".mp3")])
|
||||
|
||||
def play(self, path: str, from_time: int) -> None:
|
||||
log.info(f"DebugRenderer: play({path}, {from_time})")
|
||||
self.start = int(time.time())
|
||||
self.offset = from_time
|
||||
|
||||
def get_time(self) -> int:
|
||||
return int(time.time()) - self.start + self.offset
|
||||
|
||||
def stop(self) -> None:
|
||||
log.info("DebugRenderer: stop()")
|
||||
self.start = 0
|
||||
self.offset = 0
|
||||
|
||||
def is_playing(self) -> bool:
|
||||
return (self.start != 0) and (self.get_time() - self.offset < 10)
|
||||
|
||||
|
||||
class MopidyRenderer(Renderer):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self._id = 1
|
||||
self._post("core.tracklist.clear")
|
||||
self._post("core.tracklist.set_consume", [True])
|
||||
self._post("core.tracklist.set_single", [True])
|
||||
|
||||
def get_tracks(self, path: str) -> list[str]:
|
||||
all_files = os.listdir(path)
|
||||
return sorted([f for f in all_files if f.endswith(".mp3")])
|
||||
|
||||
def play(self, path: str, from_time: int) -> None:
|
||||
log.info(f"MopidyRenderer: play({path}, {from_time})")
|
||||
quoted_path = urllib.parse.quote(path)
|
||||
uri = f"file://{quoted_path}"
|
||||
added_tracks = self._post("core.tracklist.add", {"uris": [uri]})
|
||||
tlid = added_tracks[0]["tlid"]
|
||||
self._post("core.playback.play", {"tlid": tlid})
|
||||
if from_time > 0:
|
||||
playing = self.is_playing()
|
||||
while not playing:
|
||||
time.sleep(0.1)
|
||||
playing = self.is_playing()
|
||||
seeked = False
|
||||
while not seeked:
|
||||
time.sleep(0.1)
|
||||
seeked = self._post(
|
||||
"core.playback.seek", {"time_position": from_time * 1000}
|
||||
)
|
||||
|
||||
def get_time(self) -> int:
|
||||
res = self._post("core.playback.get_time_position")
|
||||
return int(res / 1000)
|
||||
|
||||
def stop(self) -> None:
|
||||
log.info("MopidyRenderer: stop()")
|
||||
self._post("core.playback.stop")
|
||||
self._post("core.tracklist.clear")
|
||||
|
||||
def is_playing(self) -> bool:
|
||||
res = self._post("core.playback.get_state")
|
||||
return res == "playing"
|
||||
|
||||
def _post(
|
||||
self, method: str, data: Union[Dict[str, Any], List[Any], None] = None
|
||||
) -> Any:
|
||||
msg: Dict[str, Any] = {"jsonrpc": "2.0", "id": self._id, "method": method}
|
||||
if data is not None:
|
||||
msg["params"] = data
|
||||
log.debug(f"MopidyRenderer POST: {msg}")
|
||||
response = requests.post("http://localhost:6680/mopidy/rpc", json=msg).json()
|
||||
log.debug(f"MopidyRenderer POST response: {response}")
|
||||
self._id += 1
|
||||
return response["result"]
|
||||
|
||||
|
||||
def main(media_path: str, renderer_type: str) -> None:
|
||||
if renderer_type == "dummy":
|
||||
renderer = DebugRenderer()
|
||||
elif renderer_type == "mopidy":
|
||||
renderer = MopidyRenderer()
|
||||
else:
|
||||
renderer = DebugRenderer()
|
||||
player = Player(media_path=media_path, renderer=renderer)
|
||||
while True:
|
||||
player.process()
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from argparse import ArgumentParser
|
||||
|
||||
parser = ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
"-m",
|
||||
"--media_path",
|
||||
required=True,
|
||||
help="path to the media directory (e.g., an USB stick)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--log", choices=log_levels, default="WARNING", help="log level"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--renderer",
|
||||
choices=("dummy", "mopidy"),
|
||||
default="mopidy",
|
||||
help="media renderer to use as backend",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
log.setLevel(args.log)
|
||||
|
||||
try:
|
||||
main(media_path=args.media_path, renderer_type=args.renderer)
|
||||
finally:
|
||||
GPIO.cleanup() # type:ignore
|
Loading…
Reference in a new issue