yoto-api 1.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ =======
2
+ Credits
3
+ =======
4
+
5
+ Development Lead
6
+ ----------------
7
+
8
+ *
9
+
10
+ Contributors
11
+ ------------
12
+
13
+ None yet. Why not be the first?
@@ -0,0 +1,128 @@
1
+ .. highlight:: shell
2
+
3
+ ============
4
+ Contributing
5
+ ============
6
+
7
+ Contributions are welcome, and they are greatly appreciated! Every little bit
8
+ helps, and credit will always be given.
9
+
10
+ You can contribute in many ways:
11
+
12
+ Types of Contributions
13
+ ----------------------
14
+
15
+ Report Bugs
16
+ ~~~~~~~~~~~
17
+
18
+ Report bugs at https://github.com/cdnninja/yoto_api/issues.
19
+
20
+ If you are reporting a bug, please include:
21
+
22
+ * Your operating system name and version.
23
+ * Any details about your local setup that might be helpful in troubleshooting.
24
+ * Detailed steps to reproduce the bug.
25
+
26
+ Fix Bugs
27
+ ~~~~~~~~
28
+
29
+ Look through the GitHub issues for bugs. Anything tagged with "bug" and "help
30
+ wanted" is open to whoever wants to implement it.
31
+
32
+ Implement Features
33
+ ~~~~~~~~~~~~~~~~~~
34
+
35
+ Look through the GitHub issues for features. Anything tagged with "enhancement"
36
+ and "help wanted" is open to whoever wants to implement it.
37
+
38
+ Write Documentation
39
+ ~~~~~~~~~~~~~~~~~~~
40
+
41
+ Hyundai / Kia Connect could always use more documentation, whether as part of the
42
+ official Hyundai / Kia Connect docs, in docstrings, or even on the web in blog posts,
43
+ articles, and such.
44
+
45
+ Submit Feedback
46
+ ~~~~~~~~~~~~~~~
47
+
48
+ The best way to send feedback is to file an issue at https://github.com/cdnninja/yoto_api/issues.
49
+
50
+ If you are proposing a feature:
51
+
52
+ * Explain in detail how it would work.
53
+ * Keep the scope as narrow as possible, to make it easier to implement.
54
+ * Remember that this is a volunteer-driven project, and that contributions
55
+ are welcome :)
56
+
57
+ Get Started!
58
+ ------------
59
+
60
+ Ready to contribute? Here's how to set up `yoto_api` for local development.
61
+
62
+ 1. Fork the `yoto_api` repo on GitHub.
63
+ 2. Clone your fork locally::
64
+
65
+ $ git clone git@github.com:your_name_here/yoto_api.git
66
+
67
+ 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::
68
+
69
+ $ mkvirtualenv yoto_api
70
+ $ cd yoto_api/
71
+ $ python setup.py develop
72
+
73
+ 4. Create a branch for local development::
74
+
75
+ $ git checkout -b name-of-your-bugfix-or-feature
76
+
77
+ Now you can make your changes locally.
78
+
79
+ 5. When you're done making changes, check that your changes pass flake8 and the
80
+ tests, including testing other Python versions with tox::
81
+
82
+ $ flake8 yoto_api tests
83
+ $ python setup.py test or pytest
84
+ $ tox
85
+
86
+ To get flake8 and tox, just pip install them into your virtualenv.
87
+
88
+ 6. Commit your changes and push your branch to GitHub::
89
+
90
+ $ git add .
91
+ $ git commit -m "Your detailed description of your changes."
92
+ $ git push origin name-of-your-bugfix-or-feature
93
+
94
+ 7. Submit a pull request through the GitHub website.
95
+
96
+ Pull Request Guidelines
97
+ -----------------------
98
+
99
+ Before you submit a pull request, check that it meets these guidelines:
100
+
101
+ 1. The pull request should include tests.
102
+ 2. If the pull request adds functionality, the docs should be updated. Put
103
+ your new functionality into a function with a docstring, and add the
104
+ feature to the list in README.rst.
105
+ 3. The pull request should work for Python 3.5, 3.6, 3.7 and 3.8, and for PyPy. Check
106
+ https://travis-ci.com/cdnninja/yoto_api/pull_requests
107
+ and make sure that the tests pass for all supported Python versions.
108
+
109
+ Tips
110
+ ----
111
+
112
+ To run a subset of tests::
113
+
114
+ $ pytest tests.test_hyundai_kia_connect_api
115
+
116
+
117
+ Deploying
118
+ ---------
119
+
120
+ A reminder for the maintainers on how to deploy.
121
+ Make sure all your changes are committed (including an entry in HISTORY.rst).
122
+ Then run::
123
+
124
+ $ bump2version patch # possible: major / minor / patch
125
+ $ git push
126
+ $ git push --tags
127
+
128
+ Travis will then deploy to PyPI if tests pass.
@@ -0,0 +1 @@
1
+ no history
yoto_api-1.0.7/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,12 @@
1
+ include AUTHORS.rst
2
+ include CONTRIBUTING.rst
3
+ include HISTORY.rst
4
+ include LICENSE
5
+ include README.rst
6
+ include requirements.txt
7
+
8
+ recursive-include tests *
9
+ recursive-exclude * __pycache__
10
+ recursive-exclude * *.py[co]
11
+
12
+ recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.1
2
+ Name: yoto_api
3
+ Version: 1.0.7
4
+ Summary: Python Boilerplate contains all the boilerplate you need to create a Python package.
5
+ Home-page: https://github.com/cdnninja/yoto_api
6
+ Author: cdnninja
7
+ Author-email:
8
+ License: MIT license
9
+ Keywords: yoto_api
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Natural Language :: English
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Requires-Python: >=3.9
16
+ License-File: LICENSE
17
+ License-File: AUTHORS.rst
18
+ Requires-Dist: auth0-python>=4.7.1
19
+ Requires-Dist: paho-mqtt>=2.0.0
20
+
21
+ Introduction
22
+ ============
23
+
24
+ Early days of this API. Plan is to use this for home assistant. Basics are only item build for auth so far.
25
+
26
+ To run this code for test I am doing::
27
+
28
+ from pathlib import Path
29
+ import logging
30
+ import sys
31
+ import os
32
+
33
+ path_root = r"C:path to files GitHub\main\yoto_api"
34
+ sys.path.append(str(path_root))
35
+ from yoto_api import \*
36
+
37
+ logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s:%(message)s')
38
+ logger = logging.getLogger(**name**)
39
+
40
+ ym = YotoManager(username="username", password="password")
41
+ print (ym.players)
@@ -0,0 +1,21 @@
1
+ Introduction
2
+ ============
3
+
4
+ Early days of this API. Plan is to use this for home assistant. Basics are only item build for auth so far.
5
+
6
+ To run this code for test I am doing::
7
+
8
+ from pathlib import Path
9
+ import logging
10
+ import sys
11
+ import os
12
+
13
+ path_root = r"C:path to files GitHub\main\yoto_api"
14
+ sys.path.append(str(path_root))
15
+ from yoto_api import \*
16
+
17
+ logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s:%(message)s')
18
+ logger = logging.getLogger(**name**)
19
+
20
+ ym = YotoManager(username="username", password="password")
21
+ print (ym.players)
@@ -0,0 +1,2 @@
1
+ auth0-python>=4.7.1
2
+ paho-mqtt>=2.0.0
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env python
2
+
3
+ """The setup script."""
4
+
5
+ from setuptools import setup, find_packages
6
+
7
+ with open("README.rst") as readme_file:
8
+ readme = readme_file.read()
9
+
10
+ with open("HISTORY.rst") as history_file:
11
+ history = history_file.read()
12
+
13
+ with open("requirements.txt") as f:
14
+ requirements = f.read().splitlines()
15
+
16
+ long_description = readme + "\n\n" + history
17
+ long_description = readme
18
+
19
+ test_requirements = [
20
+ "pytest>=3",
21
+ ]
22
+
23
+ setup(
24
+ author="cdnninja",
25
+ author_email="",
26
+ python_requires=">=3.9",
27
+ classifiers=[
28
+ "Development Status :: 2 - Pre-Alpha",
29
+ "Intended Audience :: Developers",
30
+ "License :: OSI Approved :: MIT License",
31
+ "Natural Language :: English",
32
+ "Programming Language :: Python :: 3.9",
33
+ ],
34
+ description="Python Boilerplate contains all the boilerplate you need to create a Python package.",
35
+ install_requires=requirements,
36
+ license="MIT license",
37
+ long_description=long_description,
38
+ include_package_data=True,
39
+ keywords="yoto_api",
40
+ name="yoto_api",
41
+ packages=find_packages(include=["yoto_api", "yoto_api.*"]),
42
+ test_suite="tests",
43
+ tests_require=test_requirements,
44
+ url="https://github.com/cdnninja/yoto_api",
45
+ version="1.0.7",
46
+ zip_safe=False,
47
+ )
File without changes
@@ -0,0 +1,12 @@
1
+ """"""
2
+
3
+ import os
4
+
5
+ from yoto_api.YotoManager import YotoManager
6
+
7
+
8
+ def login():
9
+ username = os.environ["CDNINJA_USERNAME"]
10
+ password = os.environ["CDNINJA_PASSWORD"]
11
+ yotomanager = YotoManager(username=username, password=password)
12
+ assert yotomanager
@@ -0,0 +1,39 @@
1
+ """Card class"""
2
+
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass
7
+ class Track:
8
+ icon: str = None # $.card.content.chapters[0].tracks[0].display.icon16x16 e.g. "https://card-content.yotoplay.com/yoto/SwcetJ..."
9
+ title: str = None # $.card.content.chapters[0].tracks[0].title e.g. "Introduction"
10
+ duration: int = None # $.card.content.chapters[0].tracks[0].duration e.g. 349
11
+ key: str = None # $.card.content.chapters[0].tracks[0].key e.g. "01-INT"
12
+ format: str = None # $.card.content.chapters[0].tracks[0].format e.g. "aac"
13
+ channels: str = None # $.card.content.chapters[0].tracks[0].channels e.g. "mono"
14
+ trackUrl: str = None # $.card.content.chapters[0].tracks[0].trackUrl e.g. "https://secure-media.yotoplay.com/yoto/mYZ6T..."
15
+ type: str = None # $.card.content.chapters[0].tracks[0].type e.g. "audio"
16
+
17
+
18
+ @dataclass
19
+ class Chapter:
20
+ icon: str = None # $.card.content.chapters[0].display.icon16x16 e.g. "https://card-content.yotoplay.com/yoto/SwcetJ..."
21
+ title: str = None # $.card.content.chapters[0].title e.g. "Introduction"
22
+ duration: int = None # $.card.content.chapters[0].duration e.g. 349
23
+ key: str = None # $.card.content.chapters[0].key e.g. "01-INT"
24
+ tracks: list[Track] = None # $.card.content.chapters[0].tracks
25
+
26
+
27
+ @dataclass
28
+ class Card:
29
+ id: str = None # $.card.cardId e.g. "iYIMF"
30
+ title: str = None # $.card.title e.g. "Ladybird Audio Adventures - Outer Space"
31
+ description: str = None # $.card.metadata.description e.g. "The sky’s the limit for imaginations when it comes to..."
32
+ category: str = None # $.card.metadata.category e.g. "stories"
33
+ author: str = None # $.card.metadata.author e.g. "Ladybird Audio Adventures"
34
+ coverImageL: str = None # $.card.metadata.cover.imageL e.g. "https://card-content.yotoplay.com/yoto/pub/WgoJMZ..."
35
+ seriestitle: str = (
36
+ None # $.card.metadata.seriestitle e.g. "Ladybird Audio Adventures Volume 1"
37
+ )
38
+ seriesorder: int = None # $.card.metadata.seriesorder e.g. 4
39
+ chapters: list[Chapter] = None # $.card.content.chapters
@@ -0,0 +1,18 @@
1
+ """Token.py"""
2
+
3
+ from dataclasses import dataclass
4
+ import datetime as dt
5
+
6
+
7
+ @dataclass
8
+ class Token:
9
+ """Token"""
10
+
11
+ username: str = None
12
+ password: str = None
13
+ access_token: str = None
14
+ refresh_token: str = None
15
+ id_token: str = None
16
+ scope: str = None
17
+ valid_until: dt.datetime = dt.datetime.min
18
+ token_type: str = None
@@ -0,0 +1,395 @@
1
+ """API Methods"""
2
+
3
+ import requests
4
+ import logging
5
+ from .const import DOMAIN
6
+ from .Token import Token
7
+ from .Card import Card
8
+ from .YotoPlayer import YotoPlayer
9
+
10
+ _LOGGER = logging.getLogger(__name__)
11
+
12
+
13
+ class YotoAPI:
14
+ def __init__(self) -> None:
15
+ self.BASE_URL: str = "https://api.yotoplay.com"
16
+ self.CLIENT_ID: str = "4P2do5RhHDXvCDZDZ6oti27Ft2XdRrzr"
17
+ self.LOGIN_URL: str = "login.yotoplay.com"
18
+ self.TOKEN_URL: str = "https://api.yotoplay.com/auth/token"
19
+ self.SCOPE: str = "YOUR_SCOPE"
20
+ # self.MQTT_AUTH_NAME: str = "JwtAuthorizer_mGDDmvLsocFY"
21
+ # self.MQTT_URL: str = "wss://aqrphjqbp3u2z-ats.iot.eu-west-2.amazonaws.com"
22
+
23
+ def login(self, username: str, password: str) -> Token:
24
+ url = self.TOKEN_URL
25
+ payload = {}
26
+ # all the values here should be URL encoded - not sure if this is done automatically by requests
27
+ payload["audience"] = self.BASE_URL
28
+ payload["client_id"] = self.CLIENT_ID
29
+ payload["grant_type"] = "password"
30
+ payload["password"] = password
31
+ payload["scope"] = "openid email profile offline_access"
32
+ payload["username"] = username
33
+ headers = {"Content-Type": "application/x-www-form-urlencoded"}
34
+ response = requests.post(url, data=payload, headers=headers).json()
35
+ _LOGGER.debug(f"{DOMAIN} - Sign In Response {response}")
36
+
37
+ return Token(
38
+ username=username,
39
+ password=password,
40
+ access_token=response["access_token"],
41
+ refresh_token=response["refresh_token"],
42
+ token_type=response["token_type"],
43
+ scope=response["scope"],
44
+ valid_until=response["expires_in"], # Needs to be adjusted to DT
45
+ )
46
+
47
+ # pass='audience=https%3A//api.yotoplay.com&client_id=FILL_THIS_IN&grant_type=password&password=FILL_THIS_IN&scope=openid%20email%20profile%20offline_access&username=FILL_THIS_IN%40gmail.com'
48
+ # curl -d "$pass" https://api.yotoplay.com/auth/token | jq '.access_token'
49
+
50
+ def update_devices(self, token) -> list[YotoPlayer]:
51
+ response = self._get_devices(token)
52
+ result = []
53
+ for device in response["devices"]:
54
+ player: YotoPlayer = YotoPlayer(
55
+ id=device["deviceId"],
56
+ name=device["name"],
57
+ deviceType=device["deviceType"],
58
+ online=device["online"],
59
+ )
60
+ result.append(player)
61
+
62
+ return result
63
+ # TODO: parse the data and return a list of yoto devices.
64
+
65
+ def update_library(self, token) -> list[Card]:
66
+ cards = self._get_cards(token)
67
+ return cards
68
+ # TODO: parse the data and return a list of cards.
69
+
70
+ def refresh_token(self, token: Token) -> Token:
71
+ # to do: add command to refresh token
72
+ # audience=https%3A//api.yotoplay.com&client_id=FILL_THIS_IN&grant_type=refresh_token&refresh_token=FILL_THIS_IN&scope=openid%20email%20profile%20offline_access
73
+
74
+ return token
75
+
76
+ def _get_devices(self, token) -> None:
77
+ url = self.BASE_URL + "/device-v2/devices/mine"
78
+
79
+ headers = self._get_authenticated_headers(token)
80
+
81
+ response = requests.get(url, headers=headers).json()
82
+ _LOGGER.debug(f"{DOMAIN} - Get Devices Response: {response}")
83
+ return response
84
+
85
+ def _get_cards(self, token) -> dict:
86
+ ############## Details below from snooping JSON requests of the app ######################
87
+
88
+ ############## ${BASE_URL}/auth/token #############
89
+ # Request POST contents:
90
+ # audience=https%3A//api.yotoplay.com&client_id=i42noid4b2oiboi4bo&grant_type=password&password=sndoinoinscoif&scope=openid%20email%20profile%20offline_access&username=anonymous%40gmail.com
91
+ #
92
+ # Response to above:
93
+ # {
94
+ # "access_token": "kalfkbalsbljagsl",
95
+ # "refresh_token":"akklabflkablksf",
96
+ # "id_token":"klasblgkablksgb",
97
+ # "scope":"openid email profile user-cards users offline_access",
98
+ # "expires_in":86400,
99
+ # "token_type":"Bearer"
100
+ # }
101
+ # Requests to endpoints below use contents of "access_token" in the header ->
102
+ # Authorization: Bearer access_token
103
+ # User-Agent: Yoto/2.73 (com.yotoplay.Yoto; build:10405; iOS 17.4.0) Alamofire/5.6.4
104
+
105
+ ############## ${BASE_URL}/card/family/library #############
106
+ url = self.BASE_URL + "/card/family/library"
107
+
108
+ headers = self._get_authenticated_headers(token)
109
+
110
+ response = requests.get(url, headers=headers).json()
111
+ _LOGGER.debug(f"{DOMAIN} - Get Card Library: {response}")
112
+ return response
113
+
114
+ # {
115
+ # "cards": [
116
+ # {
117
+ # "cardId": "g5tcK",
118
+ # "reason": "physical-add",
119
+ # "shareType": "yoto",
120
+ # "familyId": "ksdlbksbdgklb",
121
+ # "card": {
122
+ # "cardId": "g5tcK",
123
+ # "content": {
124
+ # "activity": "yoto_Player",
125
+ # "editSettings": {
126
+ # "editKeys": false,
127
+ # "autoOverlayLabels": "disabled"
128
+ # },
129
+ # "config": {
130
+ # "disableAutoOverlayLabels": false
131
+ # },
132
+ # "availability": "",
133
+ # "cover": {
134
+ # "imageL": "https://card-content.yotoplay.com/yoto/pub/jbfaljsblajsfblj-wcAgqZMvA"
135
+ # },
136
+ # "version": "1"
137
+ # },
138
+ # "slug": "ladybird-audio-adventures-the-frozen-world",
139
+ # "userId": "yoto",
140
+ # "sortkey": "ladybird-audio-adventures-the-frozen-world",
141
+ # "title": "Ladybird Audio Adventures: The Frozen World",
142
+ # "updatedAt": "2022-07-21T14:30:22.231Z",
143
+ # "createdAt": "2020-09-03T17:30:17.911Z",
144
+ # "metadata": {
145
+ # "category": "stories",
146
+ # "author": "Ladybird",
147
+ # "previewAudio": "shopify-slug",
148
+ # "status": {
149
+ # "name": "live",
150
+ # "updatedAt": "2020-11-24T17:08:54.839Z"
151
+ # },
152
+ # "seriestitle": "Ladybird Audio Adventures - Volume 2",
153
+ # "media": {
154
+ # "fileSize": 35189015,
155
+ # "duration": 2883,
156
+ # "hasStreams": false
157
+ # },
158
+ # "description": "Join our intrepid adventurers Otto and Cassandra (and Missy, the smartest bird in the Universe) as they embark on a brand new Ladybird Audio Adventure!\n\nIn this adventure, Otto and Missy are off to explore the Frozen World. Setting course for the Arctic and Antarctica they discover penguins, orcas and seals, and a whole lot of snow! Now if they can just figure out how to get the heating going in Otto's teleporter they'll be able to get back home! \n\nThese audiobooks help children learn about their environment on journey of discovery with the narrators Ben Bailey Smith (aka Doc Brown, rapper, comedian and writer) and Sophie Aldred (best known for her role as Ace in Doctor Who).",
159
+ # "cover": {
160
+ # "imageL": "https://card-content.yotoplay.com/yoto/pub/lajsbfljabsfljabsfljbasfljbalsjf-wcAgqZMvA?width=250"
161
+ # },
162
+ # "seriesorder": "2",
163
+ # "languages": [
164
+ # "en"
165
+ # ]
166
+ # }
167
+ # },
168
+ # "provenanceId": "kasfblasbflbaslkfl",
169
+ # "inFamilyLibrary": true,
170
+ # "updatedAt": "2024-04-10T03:58:16.732Z",
171
+ # "createdAt": "2022-12-26T07:04:18.977Z",
172
+ # "lastPlayedAt": "2024-04-11T04:30:49.402Z",
173
+ # "masterUid": "asbkflbasflkblaksf"
174
+ # },
175
+ # {
176
+ # "cardId": "iYIMF",
177
+ # "reason": "physical-add",
178
+ # "shareType": "yoto",
179
+ # "familyId": "ksdlbksbdgklb",
180
+ # "card": {
181
+ # "cardId": "iYIMF",
182
+ # "content": {
183
+ # "activity": "yoto_Player",
184
+ # "editSettings": {
185
+ # "editKeys": false,
186
+ # "autoOverlayLabels": "chapters-offset-1"
187
+ # },
188
+ # "config": {
189
+ # "trackNumberOverlayTimeout": 0,
190
+ # "disableAutoOverlayLabels": false
191
+ # },
192
+ # "availability": "",
193
+ # "cover": {
194
+ # "imageL": "https://card-content.yotoplay.com/yoto/pub/kdsgblkjsbgjlslbj"
195
+ # },
196
+ # "version": "1"
197
+ # },
198
+ # "slug": "ladybird-audio-adventures-outer-space",
199
+ # "userId": "yoto",
200
+ # "sortkey": "ladybird-audio-adventures-outer-space",
201
+ # "title": "Ladybird Audio Adventures - Outer Space",
202
+ # "updatedAt": "2022-07-21T14:25:14.090Z",
203
+ # "createdAt": "2019-12-04T00:14:57.438Z",
204
+ # "metadata": {
205
+ # "category": "stories",
206
+ # "author": "Ladybird Audio Adventures",
207
+ # "previewAudio": "shopify-slug",
208
+ # "status": {
209
+ # "name": "live",
210
+ # "updatedAt": "2020-11-16T11:13:50.060Z"
211
+ # },
212
+ # "seriestitle": "Ladybird Audio Adventures Volume 1",
213
+ # "media": {
214
+ # "fileSize": 27225336,
215
+ # "duration": 3335,
216
+ # "hasStreams": false
217
+ # },
218
+ # "description": "The sky’s the limit for imaginations when it comes to this audio adventure! Wave goodbye to Earth and blast off into the skies above to explore 'nearby' planets, stars and galaxies, alongside inventor Otto and Missy – the cleverest raven in the universe. So, hop aboard Otto’s spacecraft and get ready for a story that’s nothing short of out of this world!\n\nLadybird Audio Adventures is an original series for 4-to 7-year-olds; a new, entertaining and engaging way for children to learn about the world around them. These are special stories written exclusively for audio with fun sound and musical effects, perfect for listening at home, before bed and on long journeys. ",
219
+ # "cover": {
220
+ # "imageL": "https://card-content.yotoplay.com/yoto/pub/ksdlfbksdbgklsbdlgk?width=250"
221
+ # },
222
+ # "seriesorder": "4",
223
+ # "languages": [
224
+ # "en"
225
+ # ]
226
+ # }
227
+ # },
228
+ # "provenanceId": "641352b283571a15872a37ca",
229
+ # "inFamilyLibrary": true,
230
+ # "updatedAt": "2024-04-05T04:03:55.198Z",
231
+ # "createdAt": "2023-03-16T17:32:34.249Z",
232
+ # "lastPlayedAt": "2024-04-05T06:15:11.308Z",
233
+ # "masterUid": "04dedd46720000"
234
+ # }
235
+ # }
236
+
237
+ def _get_card_detail(self, token, cardid) -> dict:
238
+ ############## Details below from snooping JSON requests of the app ######################
239
+
240
+ url = self.BASE_URL + "/card/details/" + cardid
241
+ headers = self._get_authenticated_headers(token)
242
+
243
+ response = requests.post(url, headers=headers).json()
244
+ _LOGGER.debug(f"{DOMAIN} - Get Card Detail: {response}")
245
+ return response
246
+
247
+ ############# ${BASE_URL}/card/details/abcABC #############
248
+ # {
249
+ # "card": {
250
+ # "cardId": "abcABC", #string
251
+ # "content": {
252
+ # "activity": "yoto_Player",
253
+ # "version": "1",
254
+ # "availability": "",
255
+ # "editSettings": {
256
+ # "autoOverlayLabels": "chapters-offset-1",
257
+ # "editKeys": false
258
+ # },
259
+ # "config": {
260
+ # "trackNumberOverlayTimeout": 0,
261
+ # "disableAutoOverlayLabels": false
262
+ # },
263
+ # "cover": {
264
+ # "imageL": "https://card-content.yotoplay.com/yoto/pub/WgoJMZiFdH35UbDAR_4z2k1vL0MufKLHfR4ULd6I"
265
+ # },
266
+ # "chapters": [
267
+ # {
268
+ # "overlayLabel": "",
269
+ # "title": "Introduction",
270
+ # "key": "01-INT",
271
+ # "overlayLabelOverride": null,
272
+ # "ambient": null,
273
+ # "defaultTrackDisplay": null,
274
+ # "defaultTrackAmbient": null,
275
+ # "duration": 349, #int
276
+ # "fileSize": 2915405,
277
+ # "hasStreams": false,
278
+ # "display": {
279
+ # "icon16x16": "https://card-content.yotoplay.com/yoto/SwcetJ_c1xt9yN5jn2wdwMk4xupHLWONik-rzcBh"
280
+ # },
281
+ # "tracks": [
282
+ # {
283
+ # "overlayLabel": "",
284
+ # "format": "aac",
285
+ # "title": "Introduction",
286
+ # "type": "audio",
287
+ # "key": "01-INT",
288
+ # "overlayLabelOverride": null,
289
+ # "ambient": null,
290
+ # "fileSize": 2915405,
291
+ # "channels": "mono",
292
+ # "duration": 349,
293
+ # "transitions": {},
294
+ # "display": {
295
+ # "icon16x16": "https://card-content.yotoplay.com/yoto/SwcetJ_c1xt9yN5jn2wdwMk4xupHLWONik-rzcBhkd4"
296
+ # },
297
+ # "trackUrl": "https://secure-media.yotoplay.com/yoto/mYZ6TgL7VRAViZ_RQL5daYEdCBCCXjes?Expires=1712889341&Policy=eyJTdGF0ZnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9zZWN1cmUtbWVkaWEueW90b3BsYXkulvdG8vbVlaNlRnTDdWSTBxUkFWaVpfUlFMNWRhdtWS1aVElsWGplcyIsIkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoSI6MTcxMjg4OTM0fV19&Signature=EiZwaoCrCG7y-LgEECIxwrkGNZYzUeMOubfcDL1uuqamskan3wG8WYTe8CGOlsG9kvanhUFojuR-bnG~YqT0wPUkn6UUtR8KY9EOVUp~Gr8X9~yGE1I-klUGgykSRIXu1za6sGsF4KwQH2QUNPyS9yS8T50d09zEgAZlGYSDqcz1u1Rb7GZRm69bwtWr1PjLZLrWkV1C9~yV~4wwR17xdgT2JU20ZJ99kBWaTG1efjH9qBaQTkL1EvewHfJkYXFQs~o3mi1bp6d4LYzXa59yzb-f3-cRK~IWgMIRiKNY~0Mgx8S-VA__&Key-Pair-Id=K11LSW6MJ7KP#sha256=mYZ6TgL7VI0qRAViZ_RQL5daYEdCBCCWmY-ZTIlX"
298
+ # }
299
+ # ]
300
+ # },
301
+ # {
302
+ # "overlayLabel": "1",
303
+ # "title": "Not the Moon",
304
+ # "key": "02-1",
305
+ # "overlayLabelOverride": null,
306
+ # "ambient": null,
307
+ # "defaultTrackDisplay": null,
308
+ # "defaultTrackAmbient": null,
309
+ # "duration": 140,
310
+ # "fileSize": 1111649,
311
+ # "hasStreams": false,
312
+ # "display": {
313
+ # "icon16x16": "https://card-content.yotoplay.com/yoto/XZOm4YE9ssAm_x2ykzasHyResnOWJzYIVe_hfc"
314
+ # },
315
+ # "tracks": [
316
+ # {
317
+ # "overlayLabel": "1",
318
+ # "format": "aac",
319
+ # "title": "Not the Moon",
320
+ # "type": "audio",
321
+ # "key": "02-1",
322
+ # "overlayLabelOverride": null,
323
+ # "ambient": null,
324
+ # "fileSize": 1111649,
325
+ # "channels": "mono",
326
+ # "duration": 140,
327
+ # "transitions": {},
328
+ # "display": {
329
+ # "icon16x16": "https://card-content.yotoplay.com/yoto/XZOm4YE9ssAm_x2ykzasHyWJhf5RYzYIVe_hfc"
330
+ # },
331
+ # "trackUrl": "long url"
332
+ # }
333
+ # ]
334
+ # }
335
+ # ]
336
+ # },
337
+ # "createdAt": "2019-12-04T00:14:57.438Z",
338
+ # "metadata": {
339
+ # "description": "The sky’s the limit for imaginations when it comes to this audio adventure! Wave goodbye to Earth and blast off into the skies above to explore 'nearby' planets, stars and galaxies, alongside inventor Otto and Missy – the cleverest raven in the universe. So, hop aboard Otto’s spacecraft and get ready for a story that’s nothing short of out of this world!\n\nLadybird Audio Adventures is an original series for 4-to 7-year-olds; a new, entertaining and engaging way for children to learn about the world around them. These are special stories written exclusively for audio with fun sound and musical effects, perfect for listening at home, before bed and on long journeys. ",
340
+ # "category": "stories",
341
+ # "author": "Ladybird Audio Adventures",
342
+ # "previewAudio": "shopify-slug",
343
+ # "seriestitle": "Ladybird Audio Adventures Volume 1",
344
+ # "seriesorder": "4",
345
+ # "cover": {
346
+ # "imageL": "https://card-content.yotoplay.com/yoto/pub/WgoJMZiFdH35UbDAR_4z2k1vKLHfR4ULd6ItN4"
347
+ # },
348
+ # "languages": [
349
+ # "en"
350
+ # ],
351
+ # "status": {
352
+ # "name": "live",
353
+ # "updatedAt": "2020-11-16T11:13:50.060Z"
354
+ # },
355
+ # "media": {
356
+ # "duration": 3335,
357
+ # "fileSize": 27225336,
358
+ # "hasStreams": false
359
+ # }
360
+ # },
361
+ # "slug": "ladybird-audio-adventures-outer-space",
362
+ # "title": "Ladybird Audio Adventures - Outer Space",
363
+ # "updatedAt": "2022-07-21T14:25:14.090Z",
364
+ # "userId": "yoto",
365
+ # "sortkey": "ladybird-audio-adventures-outer-space"
366
+ # },
367
+ # "ownership": {
368
+ # "canAccess": true,
369
+ # "userHasRole": false,
370
+ # "cardIsFree": false,
371
+ # "cardIsMadeByUser": false,
372
+ # "cardIsInFamilyLibrary": true,
373
+ # "cardIsCreatedByFamily": false,
374
+ # "isAccessibleUsingSubscription": false
375
+ # }
376
+ # }
377
+
378
+ def _get_authenticated_headers(self, token: Token) -> dict:
379
+ return {
380
+ "User-Agent": "Yoto/2.73 (com.yotoplay.Yoto; build:10405; iOS 17.4.0) Alamofire/5.6.4",
381
+ "Content-Type": "application/json",
382
+ "Authorization": token.token_type + " " + token.access_token, # maybe?
383
+ }
384
+
385
+ def get_child_value(data, key):
386
+ value = data
387
+ for x in key.split("."):
388
+ try:
389
+ value = value[x]
390
+ except Exception:
391
+ try:
392
+ value = value[int(x)]
393
+ except Exception:
394
+ value = None
395
+ return value
@@ -0,0 +1,45 @@
1
+ """YotoManager.py"""
2
+
3
+ import logging
4
+ import datetime as dt
5
+ import pytz
6
+ from .YotoAPI import YotoAPI
7
+ from .Token import Token
8
+ from .const import DOMAIN
9
+
10
+ _LOGGER = logging.getLogger(__name__)
11
+
12
+
13
+ class YotoManager:
14
+ def __init__(self, username: str, password: str) -> None:
15
+ self.username: str = username
16
+ self.password: str = password
17
+ self.api: YotoAPI = YotoAPI()
18
+ self.players: dict = {}
19
+ self.token: Token = None
20
+
21
+ self.token: Token = self.api.login(self.username, self.password)
22
+ self.players: list = None
23
+ self.library: list = None
24
+ self.initialize()
25
+
26
+ def initialize(self) -> None:
27
+ self.update_player_status(self.token)
28
+ self.update_cards(self.token)
29
+
30
+ def update_player_status(self, token) -> None:
31
+ # TODO: Should update the self.players object with a current dict of players. Below isn't complete
32
+ self.players = self.api.update_devices(self.token)
33
+
34
+ def update_cards(self, token) -> None:
35
+ # TODO: Should update the self.library object with a current dict of players. Should it do details for all cards too or separate?
36
+ self.library = self.api.update_library(self.token)
37
+
38
+ def check_and_refresh_token(self) -> bool:
39
+ if self.token is None:
40
+ self.initialize()
41
+ if self.token.valid_until <= dt.datetime.now(pytz.utc):
42
+ _LOGGER.debug(f"{DOMAIN} - Refresh token expired")
43
+ self.token: Token = self.api.refresh_token(self.token)
44
+ return True
45
+ return False
@@ -0,0 +1,14 @@
1
+ """YotoPlayers class"""
2
+
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass
7
+ class YotoPlayer:
8
+ id: str = None
9
+ name: str = None
10
+ deviceType: str = None
11
+ online: bool = None
12
+
13
+
14
+ # {'devices': [{'deviceId': 'y23IBS76kCaOSrGlz29XhIFO', 'name': 'Yoto Player', 'description': 'nameless.limit', 'online': False, 'releaseChannel': 'general', 'deviceType': 'v3', 'deviceFamily': 'v3', 'deviceGroup': '', 'hasUserGivenName': False}]}
@@ -0,0 +1,7 @@
1
+ """Top-level package for Yoto API"""
2
+ # flake8: noqa
3
+
4
+ from .YotoPlayer import YotoPlayer
5
+ from .YotoManager import YotoManager
6
+ from .YotoAPI import YotoAPI
7
+ from .Token import Token
@@ -0,0 +1,3 @@
1
+ """const.py"""
2
+
3
+ DOMAIN: str = "yoto_api"
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.1
2
+ Name: yoto_api
3
+ Version: 1.0.7
4
+ Summary: Python Boilerplate contains all the boilerplate you need to create a Python package.
5
+ Home-page: https://github.com/cdnninja/yoto_api
6
+ Author: cdnninja
7
+ Author-email:
8
+ License: MIT license
9
+ Keywords: yoto_api
10
+ Classifier: Development Status :: 2 - Pre-Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Natural Language :: English
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Requires-Python: >=3.9
16
+ License-File: LICENSE
17
+ License-File: AUTHORS.rst
18
+ Requires-Dist: auth0-python>=4.7.1
19
+ Requires-Dist: paho-mqtt>=2.0.0
20
+
21
+ Introduction
22
+ ============
23
+
24
+ Early days of this API. Plan is to use this for home assistant. Basics are only item build for auth so far.
25
+
26
+ To run this code for test I am doing::
27
+
28
+ from pathlib import Path
29
+ import logging
30
+ import sys
31
+ import os
32
+
33
+ path_root = r"C:path to files GitHub\main\yoto_api"
34
+ sys.path.append(str(path_root))
35
+ from yoto_api import \*
36
+
37
+ logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s:%(message)s')
38
+ logger = logging.getLogger(**name**)
39
+
40
+ ym = YotoManager(username="username", password="password")
41
+ print (ym.players)
@@ -0,0 +1,23 @@
1
+ AUTHORS.rst
2
+ CONTRIBUTING.rst
3
+ HISTORY.rst
4
+ LICENSE
5
+ MANIFEST.in
6
+ README.rst
7
+ requirements.txt
8
+ setup.py
9
+ tests/__init__.py
10
+ tests/login_test.py
11
+ yoto_api/Card.py
12
+ yoto_api/Token.py
13
+ yoto_api/YotoAPI.py
14
+ yoto_api/YotoManager.py
15
+ yoto_api/YotoPlayer.py
16
+ yoto_api/__init__.py
17
+ yoto_api/const.py
18
+ yoto_api.egg-info/PKG-INFO
19
+ yoto_api.egg-info/SOURCES.txt
20
+ yoto_api.egg-info/dependency_links.txt
21
+ yoto_api.egg-info/not-zip-safe
22
+ yoto_api.egg-info/requires.txt
23
+ yoto_api.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ auth0-python>=4.7.1
2
+ paho-mqtt>=2.0.0
@@ -0,0 +1 @@
1
+ yoto_api