├── .github └── workflows │ ├── cd.yaml │ └── ci.yaml ├── .gitignore ├── .readthedocs.yaml ├── .travis.yml ├── LICENSE ├── README.md ├── docs ├── Makefile ├── api_ref.rst ├── conf.py ├── exceptions.rst ├── index.rst └── make.bat ├── examples ├── __init__.py ├── get_listens.py ├── get_playing_now.py ├── submit_listens.py └── submit_playing_now.py ├── liblistenbrainz ├── __init__.py ├── client.py ├── errors.py ├── listen.py └── utils.py ├── pyproject.toml └── tests ├── __init__.py ├── test_client.py └── testdata ├── get_listens_happy_path_response.json ├── get_playing_now_happy_path_response.json ├── good_submit_listens_response.json ├── no_playing_now.json ├── token_validity_bad_token_response.json └── token_validity_good_token_response.json /.github/workflows/cd.yaml: -------------------------------------------------------------------------------- 1 | name: Continous Delivery 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | deploy: 9 | runs-on: ubuntu-latest 10 | environment: 11 | name: pypi 12 | url: https://pypi.org/p/liblistenbrainz 13 | permissions: 14 | id-token: write 15 | steps: 16 | - uses: actions/checkout@v4 17 | - name: Set up Python 18 | uses: actions/setup-python@v4 19 | with: 20 | python-version: '3.12' 21 | - name: Install dependencies 22 | run: pip install .[build] 23 | - name: Build package 24 | run: python -m build 25 | - name: Publish package 26 | uses: pypa/gh-action-pypi-publish@release/v1 27 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: Continous Integration 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | python-version: ["3.8", "3.9"] #, "3.10", "3.11", "3.12"] 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Set up Python ${{ matrix.python-version }} 15 | uses: actions/setup-python@v4 16 | with: 17 | python-version: ${{ matrix.python-version }} 18 | - name: Install 19 | run: pip install .[tests] 20 | - name: Run tests 21 | run: pytest --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov=liblistenbrainz --cov-report=xml:junit/coverage-${{ matrix.python-version }}.xml 22 | - name: Upload 23 | uses: actions/upload-artifact@v4 24 | with: 25 | name: junit-${{ matrix.python-version }} 26 | path: junit/* 27 | 28 | report: 29 | runs-on: ubuntu-latest 30 | needs: test 31 | steps: 32 | - uses: actions/download-artifact@v4.1.3 33 | - name: Publish Test Reports 34 | uses: EnricoMi/publish-unit-test-result-action/composite@v2 35 | if: always() 36 | with: 37 | files: junit-*/test-results-*.xml 38 | - name: Create Coverage Report 39 | uses: irongut/CodeCoverageSummary@v1.3.0 40 | with: 41 | filename: junit-*/coverage-*.xml 42 | format: markdown 43 | output: both 44 | - name: Add coverage PR comment 45 | uses: marocchino/sticky-pull-request-comment@v2 46 | with: 47 | path: code-coverage-results.md 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | bin/ 12 | lib64 13 | pyvenv.cfg 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | pip-wheel-metadata/ 27 | share/python-wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | MANIFEST 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | junit 45 | htmlcov/ 46 | .tox/ 47 | .nox/ 48 | .coverage 49 | .coverage.* 50 | .cache 51 | nosetests.xml 52 | coverage.xml 53 | *.cover 54 | *.py,cover 55 | .hypothesis/ 56 | .pytest_cache/ 57 | 58 | # Translations 59 | *.mo 60 | *.pot 61 | 62 | # Django stuff: 63 | *.log 64 | local_settings.py 65 | db.sqlite3 66 | db.sqlite3-journal 67 | 68 | # Flask stuff: 69 | instance/ 70 | .webassets-cache 71 | 72 | # Scrapy stuff: 73 | .scrapy 74 | 75 | # Sphinx documentation 76 | docs/_build/ 77 | 78 | # PyBuilder 79 | target/ 80 | 81 | # Jupyter Notebook 82 | .ipynb_checkpoints 83 | 84 | # IPython 85 | profile_default/ 86 | ipython_config.py 87 | 88 | # pyenv 89 | .python-version 90 | 91 | # pipenv 92 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 93 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 94 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 95 | # install all needed dependencies. 96 | #Pipfile.lock 97 | 98 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 99 | __pypackages__/ 100 | 101 | # Celery stuff 102 | celerybeat-schedule 103 | celerybeat.pid 104 | 105 | # SageMath parsed files 106 | *.sage.py 107 | 108 | # Environments 109 | .env 110 | .venv 111 | env/ 112 | venv/ 113 | ENV/ 114 | env.bak/ 115 | venv.bak/ 116 | 117 | # Spyder project settings 118 | .spyderproject 119 | .spyproject 120 | 121 | # Rope project settings 122 | .ropeproject 123 | 124 | # mkdocs documentation 125 | /site 126 | 127 | # mypy 128 | .mypy_cache/ 129 | .dmypy.json 130 | dmypy.json 131 | 132 | # Pyre type checker 133 | .pyre/ 134 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | build: 4 | os: ubuntu-20.04 5 | tools: 6 | python: "3.10" 7 | 8 | sphinx: 9 | configuration: docs/conf.py 10 | 11 | formats: all 12 | 13 | #python: 14 | # install: 15 | # - requirements: docs/requirements.txt 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.5" 4 | - "3.6" 5 | - "3.7" 6 | - "3.8" 7 | install: 8 | - pip install -r requirements.txt 9 | script: 10 | - py.test pylistenbrainz 11 | - cd docs && make html 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # liblistenbrainz 2 | 3 | *liblistenbrainz* is a simple Python library for the 4 | [ListenBrainz Web API](https://listenbrainz.readthedocs.io/en/production/dev/api/). 5 | 6 | liblistenbrainz will help you start getting data from and submitting data to 7 | [ListenBrainz](https://listenbrainz.org>) very quickly. 8 | 9 | Here's an example of getting the listening history of a ListenBrainz user:: 10 | 11 | ``` python 12 | import liblistenbrainz 13 | 14 | client = liblistenbrainz.ListenBrainz() 15 | listens = client.get_listens(username='iliekcomputers') 16 | for listen in listens: 17 | print("Track name:", listen.track_name) 18 | print("Artist name:", listen.artist_name) 19 | ``` 20 | 21 | Here's another quick example of how to submit a listen to ListenBrainz:: 22 | 23 | ``` python 24 | import liblistenbrainz 25 | import time 26 | 27 | auth_token = input('Please enter your auth token: ') 28 | 29 | listen = liblistenbrainz.Listen( 30 | track_name="Fade", 31 | artist_name="Kanye West", 32 | release_name="The Life of Pablo", 33 | listened_at=int(time.time()), 34 | ) 35 | 36 | client = liblistenbrainz.ListenBrainz() 37 | client.set_auth_token(auth_token) 38 | response = client.submit_single_listen(listen) 39 | ``` 40 | 41 | More detailed documentation is available 42 | at [Read The Docs](https://liblistenbrainz.readthedocs.io/en/latest/). 43 | 44 | ## Features 45 | 46 | liblistenbrainz provides easy access to all ListenBrainz endpoints, handles 47 | ratelimits automatically and supports the ListenBrainz authorization flow. 48 | 49 | For details on the API endpoints that can be used via liblistenbrainz, take 50 | a look at the [ListenBrainz API Documentation](https://listenbrainz.readthedocs.io/en/production/dev/api/). 51 | 52 | ## Installation 53 | 54 | Install or upgrade liblistenbrainz with: 55 | 56 | pip install liblistenbrainz --upgrade 57 | 58 | ## Support 59 | 60 | You can ask questions about how to use liblistenbrainz on IRC (freenode #metabrainz). 61 | You can also email me at `iliekcomputers [at] gmail [dot] com`. 62 | 63 | If you have found a bug or have a feature request, let me know by opening an issue (or a pull request). 64 | 65 | ## License 66 | 67 | ``` 68 | liblistenbrainz - A simple client library for ListenBrainz 69 | Copyright (C) 2020 Param Singh 70 | 71 | This program is free software: you can redistribute it and/or modify 72 | it under the terms of the GNU General Public License as published by 73 | the Free Software Foundation, either version 3 of the License, or 74 | (at your option) any later version. 75 | 76 | This program is distributed in the hope that it will be useful, 77 | but WITHOUT ANY WARRANTY; without even the implied warranty of 78 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 79 | GNU General Public License for more details. 80 | 81 | You should have received a copy of the GNU General Public License 82 | along with this program. If not, see . 83 | ``` 84 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/api_ref.rst: -------------------------------------------------------------------------------- 1 | 2 | API Reference 3 | ============= 4 | 5 | ListenBrainz client 6 | #################### 7 | 8 | The ``ListenBrainz`` class is the main interface provided by liblistenbrainz. It can be used 9 | to interact with the ListenBrainz API. 10 | 11 | .. automodule:: liblistenbrainz.client 12 | :members: 13 | :undoc-members: 14 | :show-inheritance: 15 | 16 | class Listen 17 | ############ 18 | 19 | The ``Listen`` class represents a Listen from ListenBrainz. 20 | 21 | .. autoclass:: liblistenbrainz.Listen 22 | :members: 23 | :special-members: __init__ 24 | :undoc-members: 25 | :show-inheritance: 26 | 27 | Statistics (beta) 28 | ################# 29 | 30 | ListenBrainz has started exposing statistics endpoints. The following classes are related to 31 | those endpoints. 32 | 33 | .. autoclass:: liblistenbrainz.user_artist_stat_response.StatsTimeRangeOptions 34 | .. autoclass:: liblistenbrainz.user_artist_stat_response.UserArtistStatResponse 35 | :members: 36 | :special-members: __init__ 37 | .. autoclass:: liblistenbrainz.user_artist_stat_response.UserArtistStatRecord 38 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | import os 9 | import sys 10 | sys.path.insert(0, os.path.abspath('..')) 11 | import liblistenbrainz 12 | 13 | # If extensions (or modules to document with autodoc) are in another directory, 14 | # add these directories to sys.path here. If the directory is relative to the 15 | # documentation root, use os.path.abspath to make it absolute, like shown here. 16 | # 17 | # import os 18 | # import sys 19 | # sys.path.insert(0, os.path.abspath('.')) 20 | 21 | 22 | # -- Project information ----------------------------------------------------- 23 | 24 | project = 'liblistenbrainz' 25 | copyright = '2020, Param Singh' 26 | author = 'Param Singh' 27 | 28 | # The full version, including alpha/beta/rc tags 29 | release = liblistenbrainz.__version__ 30 | 31 | 32 | # -- General configuration --------------------------------------------------- 33 | 34 | # Add any Sphinx extension module names here, as strings. They can be 35 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 36 | # ones. 37 | extensions = [ 38 | 'sphinx.ext.autodoc', 39 | 'sphinx.ext.intersphinx', 40 | ] 41 | 42 | # Add any paths that contain templates here, relative to this directory. 43 | templates_path = ['_templates'] 44 | 45 | # List of patterns, relative to source directory, that match files and 46 | # directories to ignore when looking for source files. 47 | # This pattern also affects html_static_path and html_extra_path. 48 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 49 | 50 | 51 | # -- Options for HTML output ------------------------------------------------- 52 | 53 | # The theme to use for HTML and HTML Help pages. See the documentation for 54 | # a list of builtin themes. 55 | # 56 | html_theme = 'alabaster' 57 | 58 | # Add any paths that contain custom static files (such as style sheets) here, 59 | # relative to this directory. They are copied after the builtin static files, 60 | # so a file named "default.css" will overwrite the builtin "default.css". 61 | html_static_path = ['_static'] 62 | -------------------------------------------------------------------------------- /docs/exceptions.rst: -------------------------------------------------------------------------------- 1 | Exceptions 2 | ========================= 3 | 4 | .. automodule:: liblistenbrainz.errors 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | liblistenbrainz Documentation 2 | ========================================== 3 | 4 | *liblistenbrainz* is a simple Python library for the 5 | `ListenBrainz Web API `_. 6 | liblistenbrainz should help you start getting data from and submitting data to 7 | `ListenBrainz `_ very quickly. 8 | 9 | Here's an example of getting the listening history of a ListenBrainz user:: 10 | 11 | import liblistenbrainz 12 | 13 | client = liblistenbrainz.ListenBrainz() 14 | listens = client.get_listens(username='iliekcomputers') 15 | for listen in listens: 16 | print("Track name:", listen.track_name) 17 | print("Artist name:", listen.artist_name) 18 | 19 | 20 | Here's another quick example of how to submit a listen to ListenBrainz:: 21 | 22 | import liblistenbrainz 23 | import time 24 | 25 | auth_token = input('Please enter your auth token: ') 26 | 27 | listen = liblistenbrainz.Listen( 28 | track_name="Fade", 29 | artist_name="Kanye West", 30 | release_name="The Life of Pablo", 31 | listened_at=int(time.time()), 32 | ) 33 | 34 | client = liblistenbrainz.ListenBrainz() 35 | client.set_auth_token(auth_token) 36 | response = client.submit_single_listen(listen) 37 | 38 | Features 39 | ######## 40 | 41 | liblistenbrainz provides easy access to all ListenBrainz endpoints, handles 42 | ratelimits automatically and supports the ListenBrainz authorization flow. 43 | 44 | For details on the API endpoints that can be used via liblistenbrainz, take 45 | a look at the `ListenBrainz API Documentation `_. 46 | 47 | Installation 48 | ############ 49 | 50 | Install or upgrade liblistenbrainz with:: 51 | 52 | pip install liblistenbrainz --upgrade 53 | 54 | Or you can get the source code from GitHub at https://github.com/paramsingh/liblistenbrainz. 55 | 56 | 57 | Getting Started 58 | ############### 59 | 60 | It is easy to get started retrieving data from ListenBrainz using liblistenbrainz. No 61 | authentication is required for getting data. 62 | 63 | To submit data for a user, liblistenbrainz requires that you have the user's ListenBrainz auth 64 | token. Each user has a unique auth token available on their profile page. 65 | 66 | You can optionally set an auth token for requests to get data as well. 67 | 68 | Here's an example of setting an auth token to a liblistenbrainz client:: 69 | 70 | import liblistenbrainz 71 | 72 | auth_token = input('Please enter your auth token: ') 73 | client = liblistenbrainz.ListenBrainz() 74 | liblistenbrainz.set_auth_token(auth_token) 75 | 76 | By default, the ``set_auth_token`` method checks for the validity of the auth token by 77 | making a request to the ListenBrainz API. You can skip this check using the ``check_validity`` 78 | param. For example:: 79 | 80 | import liblistenbrainz 81 | 82 | auth_token = input('Please enter your auth token: ') 83 | client = liblistenbrainz.ListenBrainz() 84 | liblistenbrainz.set_auth_token(auth_token, check_validity=False) 85 | 86 | Examples 87 | ######## 88 | 89 | There are more examples of how to use liblistenbrainz 90 | in the `examples directory on GitHub `_. 91 | 92 | API Reference 93 | ############# 94 | 95 | There are more details about the client interface on the :doc:`API reference page `. 96 | 97 | Exceptions 98 | ########## 99 | 100 | All exceptions raised by liblistenbrainz should inherit 101 | from the base class ``liblistenbrainz.errors.ListenBrainzException``. 102 | 103 | For a comprehensive list of exceptions that the library can raise, 104 | take a look at the :doc:`exceptions page `. 105 | 106 | Support 107 | ####### 108 | 109 | You can ask questions about how to use liblistenbrainz on IRC (freenode #metabrainz). 110 | You can also email me at ``iliekcomputers [at] gmail [dot] com``. 111 | 112 | If you have found a bug or have a feature request, 113 | let me know by opening a `GitHub Issue `_. 114 | 115 | License 116 | ####### 117 | 118 | https://github.com/paramsingh/liblistenbrainz/blob/master/LICENSE 119 | 120 | 121 | Table Of Contents 122 | ################# 123 | 124 | .. toctree:: 125 | :maxdepth: 2 126 | 127 | api_ref 128 | exceptions 129 | 130 | Indices and tables 131 | ################## 132 | 133 | * :ref:`genindex` 134 | * :ref:`modindex` 135 | * :ref:`search` 136 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/metabrainz/liblistenbrainz/1ef875fdb1399830f4e792bae4a41b5b4c7d0dd0/examples/__init__.py -------------------------------------------------------------------------------- /examples/get_listens.py: -------------------------------------------------------------------------------- 1 | import liblistenbrainz 2 | 3 | client = liblistenbrainz.ListenBrainz() 4 | listens = client.get_listens('iliekcomputers') 5 | for listen in listens: 6 | print("Track name:", listen.track_name) 7 | print("Artist name:", listen.artist_name) 8 | -------------------------------------------------------------------------------- /examples/get_playing_now.py: -------------------------------------------------------------------------------- 1 | import liblistenbrainz 2 | 3 | client = liblistenbrainz.ListenBrainz() 4 | listen = client.get_playing_now('iliekcomputers') 5 | assert listen is not None 6 | print("Track name:", listen.track_name) 7 | print("Artist name:", listen.artist_name) 8 | -------------------------------------------------------------------------------- /examples/submit_listens.py: -------------------------------------------------------------------------------- 1 | import liblistenbrainz 2 | import time 3 | 4 | auth_token = input('Please enter your auth token: ') 5 | 6 | listen = liblistenbrainz.Listen( 7 | track_name="Fade", 8 | artist_name="Kanye West", 9 | release_name="The Life of Pablo", 10 | listened_at=int(time.time()), 11 | ) 12 | 13 | client = liblistenbrainz.ListenBrainz() 14 | client.set_auth_token(auth_token) 15 | response = client.submit_single_listen(listen) 16 | assert response['status'] == 'ok' 17 | 18 | listen_2 = liblistenbrainz.Listen( 19 | track_name="Contact", 20 | artist_name="Daft Punk", 21 | release_name="Random Access Memories", 22 | listened_at=int(time.time()), 23 | ) 24 | 25 | listen_3 = liblistenbrainz.Listen( 26 | track_name="Get Lucky", 27 | artist_name="Daft Punk", 28 | release_name="Random Access Memories", 29 | listened_at=int(time.time()), 30 | ) 31 | 32 | response = client.submit_multiple_listens([listen_2, listen_3]) 33 | assert response['status'] == 'ok' 34 | -------------------------------------------------------------------------------- /examples/submit_playing_now.py: -------------------------------------------------------------------------------- 1 | import liblistenbrainz 2 | 3 | auth_token = input('Please enter your auth token: ') 4 | 5 | listen = liblistenbrainz.Listen( 6 | track_name="Fade", 7 | artist_name="Kanye West", 8 | release_name="The Life of Pablo", 9 | ) 10 | 11 | client = liblistenbrainz.ListenBrainz() 12 | client.set_auth_token(auth_token) 13 | response = client.submit_playing_now(listen) 14 | assert response['status'] == 'ok' 15 | 16 | -------------------------------------------------------------------------------- /liblistenbrainz/__init__.py: -------------------------------------------------------------------------------- 1 | # liblistenbrainz - A simple client library for ListenBrainz 2 | # Copyright (C) 2020 Param Singh 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import sys 18 | 19 | if sys.version_info >= (3, 10): 20 | from importlib.metadata import version, PackageNotFoundError 21 | else: 22 | # importlib.metadata's API changed in 3.10, so use a backport for versions less than this. 23 | from importlib_metadata import version, PackageNotFoundError 24 | 25 | try: 26 | __version__ = version(__name__) 27 | except PackageNotFoundError: 28 | # package is not installed? 29 | __version__ = "unknown" 30 | 31 | from liblistenbrainz.client import ListenBrainz 32 | from liblistenbrainz.listen import Listen 33 | from liblistenbrainz.listen import LISTEN_TYPE_IMPORT, LISTEN_TYPE_PLAYING_NOW, LISTEN_TYPE_SINGLE 34 | -------------------------------------------------------------------------------- /liblistenbrainz/client.py: -------------------------------------------------------------------------------- 1 | # liblistenbrainz - A simple client library for ListenBrainz 2 | # Copyright (C) 2020 Param Singh 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import json 18 | import requests 19 | from requests.adapters import HTTPAdapter 20 | import time 21 | from urllib3.util import Retry 22 | 23 | from datetime import datetime 24 | from enum import Enum 25 | from liblistenbrainz import errors 26 | from liblistenbrainz.listen import LISTEN_TYPE_IMPORT, LISTEN_TYPE_PLAYING_NOW, LISTEN_TYPE_SINGLE 27 | from liblistenbrainz.utils import _validate_submit_listens_payload, _convert_api_payload_to_listen 28 | from urllib.parse import urljoin 29 | 30 | retry_strategy = Retry(total=5, allowed_methods=('GET', 'POST'), status_forcelist=[429, 500, 502, 503, 504]) 31 | adapter = HTTPAdapter(max_retries=retry_strategy) 32 | 33 | STATS_SUPPORTED_TIME_RANGES = ( 34 | 'week', 35 | 'month', 36 | 'quarter', 37 | 'half_yearly', 38 | 'year', 39 | 'all_time', 40 | 'this_week', 41 | 'this_month', 42 | 'this_year' 43 | ) 44 | 45 | 46 | API_BASE_URL = 'https://api.listenbrainz.org' 47 | 48 | class ListenBrainz: 49 | 50 | def __init__(self): 51 | self._auth_token = None 52 | 53 | # initialize rate limit variables with None 54 | self._last_request_ts = None 55 | self.remaining_requests = None 56 | self.ratelimit_reset_in = None 57 | 58 | 59 | def _require_auth_token(self): 60 | if not self._auth_token: 61 | raise errors.AuthTokenRequiredException 62 | 63 | 64 | def _wait_until_rate_limit(self): 65 | # if we haven't made any request before this, return 66 | if self._last_request_ts is None: 67 | return 68 | 69 | # if we have available requests in this window, return 70 | if self.remaining_requests and self.remaining_requests > 0: 71 | return 72 | 73 | # if we don't have available requests and we know when the 74 | # window is reset, backoff until the window gets reset 75 | if self.ratelimit_reset_in is not None: 76 | reset_ts = self._last_request_ts + self.ratelimit_reset_in 77 | current_ts = int(time.time()) 78 | if current_ts < reset_ts: 79 | time.sleep(reset_ts - current_ts) 80 | 81 | 82 | def _update_rate_limit_variables(self, response): 83 | self._last_request_ts = int(time.time()) 84 | try: 85 | self.remaining_requests = int(response.headers.get('X-RateLimit-Remaining')) 86 | except (TypeError, ValueError): 87 | self.remaining_requests = None 88 | 89 | try: 90 | self.ratelimit_reset_in = int(response.headers.get('X-RateLimit-Reset-In')) 91 | except (TypeError, ValueError): 92 | self.ratelimit_reset_in = None 93 | 94 | 95 | def _get(self, endpoint, params=None, headers=None): 96 | if not params: 97 | params = {} 98 | if not headers: 99 | headers = {} 100 | if self._auth_token: 101 | headers['Authorization'] = f'Token {self._auth_token}' 102 | 103 | session = requests.Session() 104 | session.mount("http://", adapter) # http is not used, but in case someone needs to use to for dev work, its included here 105 | session.mount("https://", adapter) 106 | 107 | try: 108 | self._wait_until_rate_limit() 109 | response = session.get( 110 | urljoin(API_BASE_URL, endpoint), 111 | params=params, 112 | headers=headers, 113 | ) 114 | self._update_rate_limit_variables(response) 115 | response.raise_for_status() 116 | except requests.HTTPError as e: 117 | status_code = e.response.status_code 118 | 119 | # get message from the json in the response if possible 120 | try: 121 | message = e.response.json().get('error', '') 122 | except Exception: 123 | message = None 124 | raise errors.ListenBrainzAPIException(status_code=status_code, message=message) from e 125 | 126 | if response.status_code == 204: 127 | raise errors.ListenBrainzAPIException(status_code=204) 128 | return response.json() 129 | 130 | 131 | def _post(self, endpoint, data=None, headers=None): 132 | if not headers: 133 | headers = {} 134 | if self._auth_token: 135 | headers['Authorization'] = f'Token {self._auth_token}' 136 | 137 | session = requests.Session() 138 | session.mount("http://", adapter) # http is not used, but in case someone needs to use to for dev work, its included here 139 | session.mount("https://", adapter) 140 | 141 | try: 142 | self._wait_until_rate_limit() 143 | response = session.post( 144 | urljoin(API_BASE_URL, endpoint), 145 | data=data, 146 | headers=headers, 147 | ) 148 | self._update_rate_limit_variables(response) 149 | response.raise_for_status() 150 | except requests.HTTPError as e: 151 | status_code = e.response.status_code 152 | 153 | # get message from the json in the response if possible 154 | try: 155 | message = e.response.json().get('error', '') 156 | except Exception: 157 | message = None 158 | raise errors.ListenBrainzAPIException(status_code=status_code, message=message) from e 159 | 160 | return response.json() 161 | 162 | 163 | def _post_submit_listens(self, listens, listen_type): 164 | self._require_auth_token() 165 | _validate_submit_listens_payload(listen_type, listens) 166 | listen_payload = [listen._to_submit_payload() for listen in listens] 167 | submit_json = { 168 | 'listen_type': listen_type, 169 | 'payload': listen_payload 170 | } 171 | return self._post( 172 | '/1/submit-listens', 173 | data=json.dumps(submit_json), 174 | ) 175 | 176 | 177 | def set_auth_token(self, auth_token, check_validity=True): 178 | """ 179 | Give the client an auth_token to use for future requests. 180 | This is required if the client wishes to submit listens. Each user 181 | has a unique auth token and the auth token is used to identify the user 182 | whose data is being submitted. 183 | 184 | :param auth_token: auth token 185 | :type auth_token: str 186 | :param check_validity: specify whether we should check the validity 187 | of the auth token by making a request to ListenBrainz before setting it (defaults to True) 188 | :type check_validity: bool, optional 189 | :raises InvalidAuthTokenException: if ListenBrainz tells us that the token is invalid 190 | :raises ListenBrainzAPIException: if there is an error with the validity check API call 191 | """ 192 | if not check_validity or self.is_token_valid(auth_token): 193 | self._auth_token = auth_token 194 | else: 195 | raise errors.InvalidAuthTokenException 196 | 197 | 198 | def submit_multiple_listens(self, listens): 199 | """ Submit a list of listens to ListenBrainz. 200 | 201 | Requires that the auth token for the user whose listens are being submitted has been set. 202 | 203 | :param listens: the list of listens to be submitted 204 | :type listens: List[liblistenbrainz.Listen] 205 | :raises ListenBrainzAPIException: if the ListenBrainz API returns a non 2xx return code 206 | :raises InvalidSubmitListensPayloadException: if the listens sent are invalid, see exception message for details 207 | """ 208 | return self._post_submit_listens(listens, LISTEN_TYPE_IMPORT) 209 | 210 | 211 | def submit_single_listen(self, listen): 212 | """ Submit a single listen to ListenBrainz. 213 | 214 | Requires that the auth token for the user whose data is being submitted has been set. 215 | 216 | :param listen: the listen to be submitted 217 | :type listen: liblistenbrainz.Listen 218 | :raises ListenBrainzAPIException: if the ListenBrainz API returns a non 2xx return code 219 | :raises InvalidSubmitListensPayloadException: if the listen being sent is invalid, see exception message for details 220 | """ 221 | return self._post_submit_listens([listen], LISTEN_TYPE_SINGLE) 222 | 223 | 224 | def submit_playing_now(self, listen): 225 | """ Submit a playing now notification to ListenBrainz. 226 | 227 | Requires that the auth token for the user whose data is being submitted has been set. 228 | 229 | :param listen: the listen to be submitted, the listen should NOT have a `listened_at` attribute 230 | :type listen: liblistenbrainz.Listen 231 | :raises ListenBrainzAPIException: if the ListenBrainz API returns a non 2xx return code 232 | :raises InvalidSubmitListensPayloadException: if the listen being sent is invalid, see exception message for details 233 | """ 234 | return self._post_submit_listens([listen], LISTEN_TYPE_PLAYING_NOW) 235 | 236 | def submit_user_feedback(self, feedback, recording_mbid): 237 | """ Submit a feedback to Listenbrainz 238 | 239 | Requires that the auth token for the user whose data is being submitted has been set. 240 | 241 | :param feedback The type of feedback 1 = loved, -1 = hated, 0 = delete feedback if any 242 | :param recording_mbid The recording Musicbrainz Id of the track being anotated 243 | """ 244 | data = { 245 | 'score': feedback, 246 | 'recording_mbid': recording_mbid, 247 | } 248 | headers = { 249 | 'Content-Type': 'application/json', 250 | } 251 | return self._post( 252 | '/1/feedback/recording-feedback', 253 | data=json.dumps(data), 254 | headers=headers, 255 | ) 256 | 257 | 258 | def delete_listen(self, listen): 259 | """ Delete a particular listen from a user’s listen history. 260 | 261 | The listen is not deleted immediately, but is scheduled for deletion, which usually happens shortly after the hour. 262 | 263 | Requires that the auth token for the user whose data is being submitted has been set. 264 | 265 | :param listen: the listen to be deleted. The listen must have a `listened_at` and `recording_msid` attribute 266 | :type listen: liblistenbrainz.Listen 267 | :raises ListenBrainzAPIException: if the ListenBrainz API returns a non 2xx return code 268 | :raises InvalidSubmitListensPayloadException: if the listen being sent is invalid, see exception message for details 269 | """ 270 | data = { 271 | 'listened_at': listen.listened_at, 272 | 'recording_msid': listen.recording_msid, 273 | } 274 | headers = { 275 | 'Content-Type': 'application/json', 276 | } 277 | return self._post( 278 | '/1/delete-listen', 279 | data=json.dumps(data), 280 | headers=headers, 281 | ) 282 | 283 | 284 | def is_token_valid(self, token): 285 | """ Check if the specified ListenBrainz auth token is valid using the ``/1/validate-token`` endpoint. 286 | 287 | :param token: the auth token that needs to be checked for validity 288 | :type token: str 289 | :raises ListenBrainzAPIException: if the ListenBrainz API returns a non 2xx return code 290 | """ 291 | data = self._get( 292 | '/1/validate-token', 293 | params={'token': token}, 294 | ) 295 | return data['valid'] 296 | 297 | 298 | def get_playing_now(self, username): 299 | """ Get the listen being played right now for user `username`. 300 | 301 | :param username: the username of the user whose data is to be fetched 302 | :type username: str 303 | :return: A single listen if the user is playing something currently, else None 304 | :rtype: liblistenbrainz.Listen or None 305 | :raises ListenBrainzAPIException: if the ListenBrainz API returns a non 2xx return code 306 | """ 307 | data = self._get('/1/user/{username}/playing-now'.format(username=username)) 308 | listens = data['payload']['listens'] 309 | if len(listens) > 0: # should never be greater than 1 310 | return _convert_api_payload_to_listen(listens[0]) 311 | return None 312 | 313 | 314 | def get_listens(self, username, max_ts=None, min_ts=None, count=None): 315 | """ Get listens for user `username` 316 | 317 | If none of the optional arguments are given, this function will return the 25 most recent listens. 318 | The optional `max_ts` and `min_ts` UNIX epoch timestamps control at which point in time to start returning listens. 319 | You may specify max_ts or min_ts, but not both in one call. 320 | 321 | :param username: the username of the user whose data is to be fetched 322 | :type username: str 323 | :param max_ts: If you specify a max_ts timestamp, listens with listened_at less than (but not including) this value will be returned. 324 | :type max_ts: int, optional 325 | :param min_ts: If you specify a min_ts timestamp, listens with listened_at greater than (but not including) this value will be returned. 326 | :type min_ts: int, optional 327 | :param count: the number of listens to return. Defaults to 25, maximum is 100. 328 | :type count: int, optional 329 | :return: A list of listens for the user `username` 330 | :rtype: List[liblistenbrainz.Listen] 331 | :raises ListenBrainzAPIException: if the ListenBrainz API returns a non 2xx return code 332 | """ 333 | params = {} 334 | if max_ts is not None: 335 | params['max_ts'] = max_ts 336 | if min_ts is not None: 337 | params['min_ts'] = min_ts 338 | if count is not None: 339 | params['count'] = count 340 | 341 | data = self._get( 342 | '/1/user/{username}/listens'.format(username=username), 343 | params=params, 344 | ) 345 | listens = data['payload']['listens'] 346 | return [_convert_api_payload_to_listen(listen_data) for listen_data in listens] 347 | 348 | def _get_user_entity(self, username, entity, count=25, offset=0, time_range='all_time'): 349 | if time_range not in STATS_SUPPORTED_TIME_RANGES: 350 | raise errors.ListenBrainzException(f"Invalid time range: {time_range}") 351 | 352 | params = { 353 | 'count': count, 354 | 'offset': offset, 355 | 'range': time_range, 356 | } 357 | 358 | try: 359 | return self._get(f'/1/stats/user/{username}/{entity}', params=params) 360 | except errors.ListenBrainzAPIException as e: 361 | if e.status_code == 204: 362 | return None 363 | else: 364 | raise 365 | 366 | 367 | def get_user_artists(self, username, count=25, offset=0, time_range='all_time'): 368 | """ Get artists for user 'username', sorted in descending order of listen count. 369 | 370 | :param username: the username of the user whose artists are to be fetched. 371 | :type username: str 372 | 373 | :param count: the number of artists to fetch, defaults to 25, maximum is 100. 374 | :type count: int, optional 375 | 376 | :param offset: the number of artists to skip from the beginning, for pagination, defaults to 0. 377 | :type offset: int, optional 378 | 379 | :param time_range: the time range, can be 'all_time', 'month', 'week' or 'year' 380 | :type time_range: str 381 | 382 | :return: the artists listened to by the user in the time range with listen counts and other data in the same format as the API response 383 | :rtype: dict 384 | """ 385 | return self._get_user_entity(username, 'artists', count, offset, time_range) 386 | 387 | 388 | def get_user_recordings(self, username, count=25, offset=0, time_range='all_time'): 389 | """ Get recordings for user 'username', sorted in descending order of listen count. 390 | 391 | :param username: the username of the user whose artists are to be fetched. 392 | :type username: str 393 | 394 | :param count: the number of recordings to fetch, defaults to 25, maximum is 100. 395 | :type count: int, optional 396 | 397 | :param offset: the number of recordings to skip from the beginning, for pagination, defaults to 0. 398 | :type offset: int, optional 399 | 400 | :param time_range: the time range, can be 'all_time', 'month', 'week' or 'year' 401 | :type time_range: str 402 | 403 | :return: the recordings listened to by the user in the time range with listen counts and other data, in the same format as the API response 404 | :rtype: dict 405 | """ 406 | return self._get_user_entity(username, 'recordings', count, offset, time_range) 407 | 408 | 409 | def get_user_releases(self, username, count=25, offset=0, time_range='all_time'): 410 | """ Get releases for user 'username', sorted in descending order of listen count. 411 | 412 | :param username: the username of the user whose releases are to be fetched. 413 | :type username: str 414 | 415 | :param count: the number of releases to fetch, defaults to 25, maximum is 100. 416 | :type count: int, optional 417 | 418 | :param offset: the number of releases to skip from the beginning, for pagination, defaults to 0. 419 | :type offset: int, optional 420 | 421 | :param time_range: the time range, can be 'all_time', 'month', 'week' or 'year' 422 | :type time_range: str 423 | 424 | :return: the releases listened to by the user in the time range with listen counts and other data 425 | :rtype: dict 426 | """ 427 | return self._get_user_entity(username, 'releases', count, offset, time_range) 428 | 429 | 430 | def get_user_recommendation_recordings(self, username, artist_type='top', count=25, offset=0): 431 | """ Get recommended recordings for a user. 432 | 433 | :param username: the username of the user whose recommended tracks are to be fetched. 434 | :type username: str 435 | 436 | :param artist_type: The type of filtering applied to the recommended tracks. 437 | 'top' for filtering by top artists or 438 | 'similar' for filtering by similar artists 439 | 'raw' for no filtering 440 | :type artist_type: str 441 | 442 | :param count: the number of recordings to fetch, defaults to 25, maximum is 100. 443 | :type count: int, optional 444 | 445 | :param offset: the number of releases to skip from the beginning, for pagination, defaults to 0. 446 | :type offset: int, optional 447 | 448 | :return: the recommended recordings as other data returned by the API 449 | :rtype: dict 450 | """ 451 | 452 | if artist_type not in ('top', 'similar', 'raw'): 453 | raise ValueError("artist_type must be either top or similar or raw.") 454 | params = { 455 | 'artist_type': artist_type, 456 | 'count': count, 457 | 'offset': offset 458 | } 459 | try: 460 | return self._get(f'/1/cf/recommendation/user/{username}/recording', params=params) 461 | 462 | except errors.ListenBrainzAPIException as e: 463 | if e.status_code == 204: 464 | return None 465 | else: 466 | raise 467 | 468 | def get_user_listen_count(self, username): 469 | """ Get total number of listens for user 470 | 471 | :param username: The username of the user whose listens are to be fetched 472 | :type username: str 473 | 474 | :return: Number of listens returned by the Listenbrainz API 475 | :rtype: int 476 | """ 477 | try: 478 | return self._get(f'/1/user/{username}/listen-count')['payload']['count'] 479 | except errors.ListenBrainzAPIException as e: 480 | if e.status_code == 204: 481 | return None 482 | else: 483 | raise 484 | 485 | def get_user_feedback(self, username, score, metadata, count=100, offset=0 ): 486 | """ Get feedback given by user 487 | 488 | :param username: The user to get the feedbacks from 489 | :type username: str 490 | :param count: Optional, number of feedback items to return. Default 100. 491 | :type count: int, optional 492 | :param offset: Optional, number of feedback items to skip from the beginning, for pagination. Ex. An offset of 5 means the top 5 feedback will be skipped, defaults to 0. 493 | :type offset: int, optional 494 | :param score: Optional, If 1 then returns the loved recordings, if -1 returns hated recordings. 495 | :type score: int, optional 496 | :param metadata: Optional, boolean if this call should return the metadata for the feedback. 497 | :type metadata: bool, optional 498 | """ 499 | params = { 500 | 'count': count, 501 | 'offset': offset, 502 | 'score': score, 503 | 'metadata': metadata, 504 | } 505 | try: 506 | return self._get(f'/1/feedback/user/{username}/get-feedback', params=params) 507 | except errors.ListenBrainzAPIException as e: 508 | if e.status_code == 204: 509 | return None 510 | else: 511 | raise 512 | -------------------------------------------------------------------------------- /liblistenbrainz/errors.py: -------------------------------------------------------------------------------- 1 | # liblistenbrainz - A simple client library for ListenBrainz 2 | # Copyright (C) 2020 Param Singh 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | class ListenBrainzException(Exception): 18 | pass 19 | 20 | class ListenBrainzAPIException(ListenBrainzException): 21 | def __init__(self, status_code, message=None): 22 | super(ListenBrainzAPIException, self).__init__() 23 | self.status_code = status_code 24 | self.message = message 25 | 26 | 27 | class AuthTokenRequiredException(ListenBrainzException): 28 | pass 29 | 30 | 31 | class InvalidAuthTokenException(ListenBrainzException): 32 | pass 33 | 34 | 35 | # Exceptions that can be thrown when submitting listens 36 | class InvalidSubmitListensPayloadException(ListenBrainzException): 37 | pass 38 | 39 | 40 | class EmptyPayloadException(InvalidSubmitListensPayloadException): 41 | pass 42 | 43 | 44 | class UnknownListenTypeException(InvalidSubmitListensPayloadException): 45 | pass 46 | 47 | 48 | class TooManyListensException(InvalidSubmitListensPayloadException): 49 | pass 50 | 51 | 52 | class ListenedAtInPlayingNowException(InvalidSubmitListensPayloadException): 53 | pass 54 | -------------------------------------------------------------------------------- /liblistenbrainz/listen.py: -------------------------------------------------------------------------------- 1 | # liblistenbrainz - A simple client library for ListenBrainz 2 | # Copyright (C) 2020 Param Singh 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | LISTEN_TYPE_SINGLE = 'single' 18 | LISTEN_TYPE_IMPORT = 'import' 19 | LISTEN_TYPE_PLAYING_NOW = 'playing_now' 20 | 21 | LISTEN_TYPES = ( 22 | LISTEN_TYPE_SINGLE, 23 | LISTEN_TYPE_IMPORT, 24 | LISTEN_TYPE_PLAYING_NOW, 25 | ) 26 | 27 | class Listen: 28 | def __init__( 29 | self, 30 | track_name, 31 | artist_name, 32 | listened_at=None, 33 | release_name=None, 34 | recording_mbid=None, 35 | artist_mbids=None, 36 | release_mbid=None, 37 | tags=None, 38 | release_group_mbid=None, 39 | work_mbids=None, 40 | tracknumber=None, 41 | spotify_id=None, 42 | listening_from=None, 43 | isrc=None, 44 | additional_info=None, 45 | username=None, 46 | recording_msid=None, 47 | ): 48 | """ Creates a Listen. 49 | 50 | Needs at least a track name and an artist name. 51 | 52 | :param track_name: the name of the track 53 | :type track_name: str 54 | :param artist_name: the name of the artist 55 | :type artist_name: str 56 | :param listened_at: the unix timestamp at which the user listened to this listen 57 | :type listened_at: int, optional 58 | :param release_name: the name of the MusicBrainz release the track is a part of 59 | :type release_name: str, optional 60 | :param recording_mbid: the MusicBrainz ID of this listen's recording 61 | :type recording_mbid: str, optional 62 | :param artist_mbids: the MusicBrainz IDs of this listen's artists 63 | :type artist_mbids: List[str], optional 64 | :param release_mbid: the MusicBrainz ID of this listen's release 65 | :type release_mbid: str, optional 66 | :param tags: a list of user defined tags for this recording, each listen can only have at most 50 67 | tags and each tag must be shorter than 64 characters. 68 | :type tags: List[str], optional 69 | :param release_group_mbid: A MusicBrainz Release Group ID of the release group this 70 | recording was played from. 71 | :type release_group_mbid: str, optional 72 | :param work_mbids: A list of MusicBrainz Work IDs that may be associated with this recording. 73 | :type work_mbids: List[str], optional 74 | :param tracknumber: The tracknumber of the recording. This first recording on a release is tracknumber 1. 75 | :type tracknumber: int, optional 76 | :param spotify_id: The Spotify track URL associated with this 77 | recording. e.g.: http://open.spotify.com/track/1rrgWMXGCGHru5bIRxGFV0 78 | :type spotify_id: str, optional 79 | :param listening_from: the source of the listen, for example: 'spotify' or 'vlc', 80 | :type listening_from: str, optional 81 | :param isrc: The ISRC code associated with the recording. 82 | :type isrc: str, optional 83 | :param additional_info: a dict containing any additional fields that should be submitted with the listen. 84 | :type additional_info: dict, optional 85 | :param username: the username of the user to whom this listen belongs 86 | :type username: str, optional 87 | :param recording_msid: the MSID of this listen's recording 88 | :type recording_msid: str, optional 89 | :return: A listen object with the passed properties 90 | :rtype: Listen 91 | """ 92 | self.listened_at = listened_at 93 | self.track_name = track_name 94 | self.artist_name = artist_name 95 | self.release_name = release_name 96 | self.recording_mbid = recording_mbid 97 | self.artist_mbids = artist_mbids or [] 98 | self.release_mbid = release_mbid 99 | self.tags = tags or [] 100 | self.release_group_mbid = release_group_mbid or [] 101 | self.work_mbids = work_mbids or [] 102 | self.tracknumber = tracknumber 103 | self.spotify_id = spotify_id 104 | self.listening_from = listening_from 105 | self.isrc = isrc 106 | self.additional_info = additional_info or {} 107 | self.username = username 108 | self.recording_msid = recording_msid 109 | 110 | 111 | def _to_submit_payload(self): 112 | # create the additional_info dict first 113 | additional_info = self.additional_info 114 | if self.recording_mbid: 115 | additional_info['recording_mbid'] = self.recording_mbid 116 | if self.artist_mbids: 117 | additional_info['artist_mbids'] = self.artist_mbids 118 | if self.release_mbid: 119 | additional_info['release_mbid'] = self.release_mbid 120 | if self.tags: 121 | additional_info['tags'] = self.tags 122 | if self.release_group_mbid: 123 | additional_info['release_group_mbid'] = self.release_group_mbid 124 | if self.work_mbids: 125 | additional_info['work_mbids'] = self.work_mbids 126 | if self.tracknumber is not None: 127 | additional_info['tracknumber'] = self.tracknumber 128 | if self.spotify_id: 129 | additional_info['spotify_id'] = self.spotify_id 130 | if self.listening_from: 131 | additional_info['listening_from'] = self.listening_from 132 | if self.isrc: 133 | additional_info['isrc'] = self.isrc 134 | 135 | # create track_metadata now and put additional_info into it if it makes sense 136 | track_metadata = { 137 | 'track_name': self.track_name, 138 | 'artist_name': self.artist_name, 139 | } 140 | if self.release_name: 141 | track_metadata['release_name'] = self.release_name 142 | if additional_info: 143 | track_metadata['additional_info'] = additional_info 144 | 145 | # create final payload and put track metadata into it 146 | payload = { 147 | 'track_metadata': track_metadata, 148 | } 149 | if self.listened_at is not None: 150 | payload['listened_at'] = self.listened_at 151 | 152 | return payload 153 | -------------------------------------------------------------------------------- /liblistenbrainz/utils.py: -------------------------------------------------------------------------------- 1 | # liblistenbrainz - A simple client library for ListenBrainz 2 | # Copyright (C) 2020 Param Singh 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from liblistenbrainz import errors 18 | from liblistenbrainz.listen import Listen 19 | from liblistenbrainz.listen import LISTEN_TYPES, LISTEN_TYPE_SINGLE, LISTEN_TYPE_IMPORT, LISTEN_TYPE_PLAYING_NOW 20 | 21 | def _validate_submit_listens_payload(listen_type, listens): 22 | if not listens: 23 | raise errors.EmptyPayloadException("Can't submit empty list of listens") 24 | 25 | if listen_type not in LISTEN_TYPES: 26 | raise errors.UnknownListenTypeException(f"Invalid listen type: {str(listen_type)}") 27 | 28 | 29 | if listen_type != LISTEN_TYPE_IMPORT and len(listens) != 1: 30 | raise errors.TooManyListensException("Too many listens for listen type %s: %d" % (str(listen_type), len(listens))) 31 | 32 | if listen_type == LISTEN_TYPE_PLAYING_NOW and listens[0].listened_at is not None: 33 | raise errors.ListenedAtInPlayingNowException("There is a listened_at field in a listen meant to be sent as `playing_now`") 34 | 35 | 36 | def _convert_api_payload_to_listen(data): 37 | track_metadata = data['track_metadata'] 38 | additional_info = track_metadata.get('additional_info', {}) 39 | return Listen( 40 | track_name=track_metadata['track_name'], 41 | artist_name=track_metadata['artist_name'], 42 | listened_at=data.get('listened_at'), 43 | release_name=track_metadata.get('release_name'), 44 | recording_mbid=additional_info.get('recording_mbid'), 45 | artist_mbids=additional_info.get('artist_mbids', []), 46 | release_mbid=additional_info.get('release_mbid'), 47 | tags=additional_info.get('tags', []), 48 | release_group_mbid=additional_info.get('release_group_mbid'), 49 | work_mbids=additional_info.get('work_mbids', []), 50 | tracknumber=additional_info.get('tracknumber'), 51 | spotify_id=additional_info.get('spotify_id'), 52 | listening_from=additional_info.get('listening_from'), 53 | isrc=additional_info.get('isrc'), 54 | additional_info=additional_info, 55 | username=data.get('username'), 56 | recording_msid=data.get('recording_msid'), 57 | ) 58 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "liblistenbrainz" 3 | authors = [ 4 | { name="Param Singh", email="iliekcomputers@gmail.com"}, 5 | ] 6 | description="A simple ListenBrainz client library for Python" 7 | readme = "README.md" 8 | requires-python=">=3.8" 9 | classifiers=[ 10 | "Programming Language :: Python :: 3", 11 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", 12 | "Operating System :: OS Independent", 13 | ] 14 | dynamic = ["version"] 15 | dependencies = [ 16 | 'requests >= 2.31.0', 17 | 'importlib-metadata >= 3.10.0; python_version < "3.10"' 18 | ] 19 | 20 | [project.optional-dependencies] 21 | tests = [ 22 | 'pytest == 8.3.4', 23 | 'pytest-cov >= 5.0.0' 24 | ] 25 | build = [ 26 | 'build', 27 | 'twine' 28 | ] 29 | docs = [ 30 | 'sphinx == 3.0.1' 31 | ] 32 | 33 | [project.urls] 34 | Homepage = "https://github.com/metabrainz/liblistenbrainz" 35 | Issues = "https://github.com/metabrainz/liblistenbrainz/issues" 36 | Documentation = "https://liblistenbrainz.readthedocs.io" 37 | Releases = "https://github.com/metabrainz/liblistenbrainz/releases" 38 | 39 | [build-system] 40 | requires = ["setuptools>=64.0", "setuptools_scm>=8"] 41 | build-backend = "setuptools.build_meta" 42 | 43 | [tool.setuptools_scm] 44 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/metabrainz/liblistenbrainz/1ef875fdb1399830f4e792bae4a41b5b4c7d0dd0/tests/__init__.py -------------------------------------------------------------------------------- /tests/test_client.py: -------------------------------------------------------------------------------- 1 | # liblistenbrainz - A simple client library for ListenBrainz 2 | # Copyright (C) 2020 Param Singh 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import json 18 | import os 19 | import liblistenbrainz 20 | import requests 21 | import time 22 | import unittest 23 | import uuid 24 | 25 | from liblistenbrainz import errors 26 | from unittest import mock 27 | 28 | TEST_DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'testdata') 29 | 30 | 31 | class ListenBrainzClientTestCase(unittest.TestCase): 32 | 33 | def setUp(self): 34 | self.client = liblistenbrainz.ListenBrainz() 35 | 36 | @mock.patch('liblistenbrainz.client.requests.Session.get') 37 | def test_get_injects_auth_token_if_available(self, mock_requests_get): 38 | mock_requests_get.return_value = mock.MagicMock() 39 | self.client._get('/1/user/iliekcomputers/listens') 40 | mock_requests_get.assert_called_once_with( 41 | 'https://api.listenbrainz.org/1/user/iliekcomputers/listens', 42 | params={}, 43 | headers={}, 44 | ) 45 | 46 | mock_requests_get.reset_mock() 47 | self.client.is_token_valid = mock.MagicMock(return_value=True) 48 | auth_token = str(uuid.uuid4()) 49 | self.client.set_auth_token(auth_token) 50 | self.client._get('/1/user/iliekcomputers/listens') 51 | mock_requests_get.assert_called_once_with( 52 | 'https://api.listenbrainz.org/1/user/iliekcomputers/listens', 53 | params={}, 54 | headers={'Authorization': f'Token {auth_token}'} 55 | ) 56 | 57 | 58 | @mock.patch('liblistenbrainz.client.requests.Session.post') 59 | def test_post_injects_auth_token_if_available(self, mock_requests_post): 60 | mock_requests_post.return_value = mock.MagicMock() 61 | self.client._post('/1/user/iliekcomputers/listens') 62 | mock_requests_post.assert_called_once_with( 63 | 'https://api.listenbrainz.org/1/user/iliekcomputers/listens', 64 | data=None, 65 | headers={}, 66 | ) 67 | 68 | mock_requests_post.reset_mock() 69 | self.client.is_token_valid = mock.MagicMock(return_value=True) 70 | auth_token = str(uuid.uuid4()) 71 | self.client.set_auth_token(auth_token) 72 | self.client._post('/1/user/iliekcomputers/listens') 73 | mock_requests_post.assert_called_once_with( 74 | 'https://api.listenbrainz.org/1/user/iliekcomputers/listens', 75 | data=None, 76 | headers={'Authorization': f'Token {auth_token}'} 77 | ) 78 | 79 | 80 | def test_client_get_listens(self): 81 | self.client._get = mock.MagicMock() 82 | with open(os.path.join(TEST_DATA_DIR, 'get_listens_happy_path_response.json')) as f: 83 | response_json = json.load(f) 84 | self.client._get.return_value = response_json 85 | received_listens = self.client.get_listens('iliekcomputers') 86 | expected_listens = response_json['payload']['listens'] 87 | self.client._get.assert_called_once_with( 88 | '/1/user/iliekcomputers/listens', 89 | params={}, 90 | ) 91 | for i in range(len(expected_listens)): 92 | self.assertEqual(received_listens[i].listened_at, expected_listens[i]['listened_at']) 93 | self.assertEqual(received_listens[i].track_name, expected_listens[i]['track_metadata']['track_name']) 94 | 95 | 96 | def test_client_get_listens_with_max_ts(self): 97 | ts = int(time.time()) 98 | self.client._get = mock.MagicMock() 99 | with open(os.path.join(TEST_DATA_DIR, 'get_listens_happy_path_response.json')) as f: 100 | response_json = json.load(f) 101 | self.client._get.return_value = response_json 102 | received_listens = self.client.get_listens('iliekcomputers', max_ts=ts) 103 | self.client._get.assert_called_once_with( 104 | '/1/user/iliekcomputers/listens', 105 | params={'max_ts': ts}, 106 | ) 107 | expected_listens = response_json['payload']['listens'] 108 | for i in range(len(expected_listens)): 109 | self.assertEqual(received_listens[i].listened_at, expected_listens[i]['listened_at']) 110 | self.assertEqual(received_listens[i].track_name, expected_listens[i]['track_metadata']['track_name']) 111 | 112 | 113 | def test_client_get_listens_with_min_ts(self): 114 | ts = int(time.time()) 115 | self.client._get = mock.MagicMock() 116 | with open(os.path.join(TEST_DATA_DIR, 'get_listens_happy_path_response.json')) as f: 117 | response_json = json.load(f) 118 | self.client._get.return_value = response_json 119 | received_listens = self.client.get_listens('iliekcomputers', min_ts=ts) 120 | self.client._get.assert_called_once_with( 121 | '/1/user/iliekcomputers/listens', 122 | params={'min_ts': ts}, 123 | ) 124 | expected_listens = response_json['payload']['listens'] 125 | for i in range(len(expected_listens)): 126 | self.assertEqual(received_listens[i].listened_at, expected_listens[i]['listened_at']) 127 | self.assertEqual(received_listens[i].track_name, expected_listens[i]['track_metadata']['track_name']) 128 | 129 | 130 | def test_client_get_listens_with_count(self): 131 | self.client._get = mock.MagicMock() 132 | with open(os.path.join(TEST_DATA_DIR, 'get_listens_happy_path_response.json')) as f: 133 | response_json = json.load(f) 134 | self.client._get.return_value = response_json 135 | received_listens = self.client.get_listens('iliekcomputers', count=50) 136 | self.client._get.assert_called_once_with( 137 | '/1/user/iliekcomputers/listens', 138 | params={'count': 50}, 139 | ) 140 | expected_listens = response_json['payload']['listens'] 141 | for i in range(len(expected_listens)): 142 | self.assertEqual(received_listens[i].listened_at, expected_listens[i]['listened_at']) 143 | self.assertEqual(received_listens[i].track_name, expected_listens[i]['track_metadata']['track_name']) 144 | 145 | 146 | def test_client_get_playing_now(self): 147 | self.client._get = mock.MagicMock() 148 | with open(os.path.join(TEST_DATA_DIR, 'get_playing_now_happy_path_response.json')) as f: 149 | response_json = json.load(f) 150 | self.client._get.return_value = response_json 151 | received_listen = self.client.get_playing_now('iliekcomputers') 152 | self.client._get.assert_called_once_with( 153 | '/1/user/iliekcomputers/playing-now', 154 | ) 155 | expected_listen = response_json['payload']['listens'][0] 156 | self.assertIsNotNone(received_listen) 157 | self.assertIsNone(received_listen.listened_at) 158 | self.assertEqual(received_listen.track_name, expected_listen['track_metadata']['track_name']) 159 | 160 | 161 | def test_client_get_playing_now_no_listen(self): 162 | self.client._get = mock.MagicMock() 163 | with open(os.path.join(TEST_DATA_DIR, 'no_playing_now.json')) as f: 164 | response_json = json.load(f) 165 | self.client._get.return_value = response_json 166 | received_listen = self.client.get_playing_now('iliekcomputers') 167 | self.client._get.assert_called_once_with( 168 | '/1/user/iliekcomputers/playing-now', 169 | ) 170 | self.assertIsNone(received_listen) 171 | 172 | @mock.patch('liblistenbrainz.client.requests.Session.post') 173 | @mock.patch('liblistenbrainz.client.json.dumps') 174 | def test_submit_single_listen(self, mock_json_dumps, mock_requests_post): 175 | ts = int(time.time()) 176 | listen = liblistenbrainz.Listen( 177 | track_name="Fade", 178 | artist_name="Kanye West", 179 | release_name="The Life of Pablo", 180 | listened_at=ts, 181 | ) 182 | 183 | expected_payload = { 184 | 'listen_type': 'single', 185 | 'payload': [ 186 | { 187 | 'listened_at': ts, 188 | 'track_metadata': { 189 | 'track_name': 'Fade', 190 | 'artist_name': 'Kanye West', 191 | 'release_name': 'The Life of Pablo', 192 | } 193 | } 194 | ] 195 | } 196 | 197 | mock_json_dumps.return_value = "mock data to be sent" 198 | mock_requests_post.return_value.json.return_value = {'status': 'ok'} 199 | auth_token = str(uuid.uuid4()) 200 | self.client.is_token_valid = mock.MagicMock(return_value=True) 201 | self.client.set_auth_token(auth_token) 202 | response = self.client.submit_single_listen(listen) 203 | mock_requests_post.assert_called_once_with( 204 | 'https://api.listenbrainz.org/1/submit-listens', 205 | data="mock data to be sent", 206 | headers={'Authorization': f'Token {auth_token}'} 207 | ) 208 | mock_json_dumps.assert_called_once_with(expected_payload) 209 | self.assertEqual(response['status'], 'ok') 210 | 211 | def test_submit_payload_exceptions(self): 212 | ts = int(time.time()) 213 | listen = liblistenbrainz.Listen( 214 | track_name="Fade", 215 | artist_name="Kanye West", 216 | release_name="The Life of Pablo", 217 | listened_at=ts, 218 | ) 219 | 220 | # check that it doesn't try to submit without an auth token 221 | with self.assertRaises(errors.AuthTokenRequiredException): 222 | self.client.submit_multiple_listens([listen]) 223 | 224 | # now, we set an auth token 225 | auth_token = str(uuid.uuid4()) 226 | self.client.is_token_valid = mock.MagicMock(return_value=True) 227 | self.client.set_auth_token(auth_token) 228 | 229 | # check that we don't allow submission of zero listens 230 | with self.assertRaises(errors.EmptyPayloadException): 231 | self.client.submit_multiple_listens([]) 232 | 233 | # test that we check for validity of listen types 234 | with self.assertRaises(errors.UnknownListenTypeException): 235 | self.client._post_submit_listens([listen], 'unknown listen type') 236 | 237 | # test that we don't allow submission of multiple listens 238 | # with the "single" or "playing now" types 239 | with self.assertRaises(errors.TooManyListensException): 240 | self.client._post_submit_listens([listen, listen], 'single') 241 | 242 | with self.assertRaises(errors.TooManyListensException): 243 | self.client._post_submit_listens([listen, listen], 'playing_now') 244 | 245 | # test that we don't submit timestamps for playingnow listens 246 | with self.assertRaises(errors.ListenedAtInPlayingNowException): 247 | self.client.submit_playing_now(listen) 248 | 249 | def test_set_auth_token_invalid_token(self): 250 | self.client.is_token_valid = mock.MagicMock(return_value=False) 251 | 252 | with self.assertRaises(errors.InvalidAuthTokenException): 253 | self.client.set_auth_token(str(uuid.uuid4())) 254 | 255 | def test_set_auth_token_valid_token(self): 256 | self.client.is_token_valid = mock.MagicMock(return_value=True) 257 | auth_token = str(uuid.uuid4()) 258 | self.client.set_auth_token(auth_token) 259 | self.assertEqual(auth_token, self.client._auth_token) 260 | 261 | @mock.patch('liblistenbrainz.client.requests.post') 262 | def test_post_api_exceptions(self, mock_requests_post): 263 | response = mock.MagicMock() 264 | response.json.return_value = {'code': 401, 'error': 'Unauthorized'} 265 | response.raise_for_status.side_effect = requests.HTTPError(response=response) 266 | mock_requests_post.return_value = response 267 | 268 | # set auth token 269 | self.client.is_token_valid = mock.MagicMock(return_value=True) 270 | auth_token = str(uuid.uuid4()) 271 | self.client.set_auth_token(auth_token) 272 | 273 | # create a listen 274 | ts = int(time.time()) 275 | listen = liblistenbrainz.Listen( 276 | track_name="Fade", 277 | artist_name="Kanye West", 278 | release_name="The Life of Pablo", 279 | listened_at=ts, 280 | ) 281 | 282 | # assert that submitting it raises a ListenBrainzAPIException 283 | with self.assertRaises(errors.ListenBrainzAPIException): 284 | self.client.submit_single_listen(listen) 285 | 286 | @mock.patch('liblistenbrainz.client.requests.Session.get') 287 | def test_get_api_exceptions(self, mock_requests_get): 288 | response = mock.MagicMock() 289 | response.json.return_value = {'code': 401, 'error': 'Unauthorized'} 290 | response.raise_for_status.side_effect = requests.HTTPError(response=response) 291 | mock_requests_get.return_value = response 292 | 293 | # assert that getting listens raises a ListenBrainzAPIException 294 | with self.assertRaises(errors.ListenBrainzAPIException): 295 | self.client.get_listens('iliekcomputers') 296 | 297 | 298 | @mock.patch('liblistenbrainz.client.requests.Session.get') 299 | def test_get_user_recommendation_recordings(self, mock_requests_get): 300 | mock_requests_get.return_value = mock.MagicMock() 301 | with self.assertRaises(ValueError): 302 | self.client.get_user_recommendation_recordings("boo", "bad artist type") 303 | 304 | mock_requests_get.reset_mock() 305 | mock_requests_get.return_value = mock.MagicMock() 306 | self.client.get_user_recommendation_recordings("iliekcomputers", "top", offset=3, count=2) 307 | mock_requests_get.assert_called_once_with( 308 | 'https://api.listenbrainz.org/1/cf/recommendation/user/iliekcomputers/recording', 309 | params={ 310 | 'artist_type': 'top', 311 | 'count': 2, 312 | 'offset': 3 313 | }, 314 | headers={}, 315 | ) 316 | 317 | mock_requests_get.reset_mock() 318 | mock_requests_get.return_value = mock.MagicMock() 319 | self.client.get_user_recommendation_recordings("iliekcomputers", "similar", offset=3, count=2) 320 | mock_requests_get.assert_called_once_with( 321 | 'https://api.listenbrainz.org/1/cf/recommendation/user/iliekcomputers/recording', 322 | params={ 323 | 'artist_type': 'similar', 324 | 'count': 2, 325 | 'offset': 3 326 | }, 327 | headers={}, 328 | ) 329 | 330 | def test_get_user_listen_count(self): 331 | self.client._get = mock.MagicMock() 332 | 333 | test_response = {"payload":{"count":111487}} 334 | self.client._get.return_value = test_response 335 | returned_count = self.client.get_user_listen_count('iliekcomputers') 336 | self.client._get.assert_called_once_with('/1/user/iliekcomputers/listen-count') 337 | 338 | self.assertEqual(returned_count, test_response['payload']['count']) 339 | 340 | -------------------------------------------------------------------------------- /tests/testdata/get_listens_happy_path_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "payload": { 3 | "count": 25, 4 | "latest_listen_ts": 1587245842, 5 | "listens": [ 6 | { 7 | "listened_at": 1587245842, 8 | "recording_msid": "ae29cef0-4132-49d1-aee8-eeae67763e66", 9 | "track_metadata": { 10 | "additional_info": { 11 | "artist_mbids": [], 12 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 13 | "artist_names": [ 14 | "SOHN" 15 | ], 16 | "discnumber": 1, 17 | "duration_ms": 250407, 18 | "isrc": "GBAFL1600378", 19 | "listening_from": "spotify", 20 | "recording_mbid": "", 21 | "recording_msid": "ae29cef0-4132-49d1-aee8-eeae67763e66", 22 | "release_artist_name": "SOHN", 23 | "release_artist_names": [ 24 | "SOHN" 25 | ], 26 | "release_group_mbid": "", 27 | "release_mbid": "", 28 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 29 | "spotify_album_artist_ids": [ 30 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 31 | ], 32 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 33 | "spotify_artist_ids": [ 34 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 35 | ], 36 | "spotify_id": "https://open.spotify.com/track/3wEYsKTvfWeCTa339clXBh", 37 | "tags": [], 38 | "track_mbid": "", 39 | "tracknumber": 10, 40 | "work_mbids": [] 41 | }, 42 | "artist_name": "SOHN", 43 | "release_name": "Rennen", 44 | "track_name": "Harbour" 45 | }, 46 | "user_name": "iliekcomputers" 47 | }, 48 | { 49 | "listened_at": 1587245592, 50 | "recording_msid": "0ce16a7b-89de-4172-9ad6-2bafa180083b", 51 | "track_metadata": { 52 | "additional_info": { 53 | "artist_mbids": [], 54 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 55 | "artist_names": [ 56 | "SOHN" 57 | ], 58 | "discnumber": 1, 59 | "duration_ms": 210743, 60 | "isrc": "GBAFL1600377", 61 | "listening_from": "spotify", 62 | "recording_mbid": "", 63 | "recording_msid": "0ce16a7b-89de-4172-9ad6-2bafa180083b", 64 | "release_artist_name": "SOHN", 65 | "release_artist_names": [ 66 | "SOHN" 67 | ], 68 | "release_group_mbid": "", 69 | "release_mbid": "", 70 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 71 | "spotify_album_artist_ids": [ 72 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 73 | ], 74 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 75 | "spotify_artist_ids": [ 76 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 77 | ], 78 | "spotify_id": "https://open.spotify.com/track/2vvYXdoWuePZ4HtQuQVhPG", 79 | "tags": [], 80 | "track_mbid": "", 81 | "tracknumber": 9, 82 | "work_mbids": [] 83 | }, 84 | "artist_name": "SOHN", 85 | "release_name": "Rennen", 86 | "track_name": "Still Waters" 87 | }, 88 | "user_name": "iliekcomputers" 89 | }, 90 | { 91 | "listened_at": 1587245381, 92 | "recording_msid": "15fd603c-b6d2-4c49-9513-30f3d411ffdd", 93 | "track_metadata": { 94 | "additional_info": { 95 | "artist_mbids": [], 96 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 97 | "artist_names": [ 98 | "SOHN" 99 | ], 100 | "discnumber": 1, 101 | "duration_ms": 225109, 102 | "isrc": "GBAFL1600376", 103 | "listening_from": "spotify", 104 | "recording_mbid": "", 105 | "recording_msid": "15fd603c-b6d2-4c49-9513-30f3d411ffdd", 106 | "release_artist_name": "SOHN", 107 | "release_artist_names": [ 108 | "SOHN" 109 | ], 110 | "release_group_mbid": "", 111 | "release_mbid": "", 112 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 113 | "spotify_album_artist_ids": [ 114 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 115 | ], 116 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 117 | "spotify_artist_ids": [ 118 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 119 | ], 120 | "spotify_id": "https://open.spotify.com/track/7hxVHJLIhjBabKgukjnuix", 121 | "tags": [], 122 | "track_mbid": "", 123 | "tracknumber": 8, 124 | "work_mbids": [] 125 | }, 126 | "artist_name": "SOHN", 127 | "release_name": "Rennen", 128 | "track_name": "Proof" 129 | }, 130 | "user_name": "iliekcomputers" 131 | }, 132 | { 133 | "listened_at": 1587245156, 134 | "recording_msid": "b350dea8-eb57-455a-b546-74973eeb6bf9", 135 | "track_metadata": { 136 | "additional_info": { 137 | "artist_mbids": [], 138 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 139 | "artist_names": [ 140 | "SOHN" 141 | ], 142 | "discnumber": 1, 143 | "duration_ms": 268629, 144 | "isrc": "GBAFL1600375", 145 | "listening_from": "spotify", 146 | "recording_mbid": "", 147 | "recording_msid": "b350dea8-eb57-455a-b546-74973eeb6bf9", 148 | "release_artist_name": "SOHN", 149 | "release_artist_names": [ 150 | "SOHN" 151 | ], 152 | "release_group_mbid": "", 153 | "release_mbid": "", 154 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 155 | "spotify_album_artist_ids": [ 156 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 157 | ], 158 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 159 | "spotify_artist_ids": [ 160 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 161 | ], 162 | "spotify_id": "https://open.spotify.com/track/5svEhroDfeTt0ePvASUtZ6", 163 | "tags": [], 164 | "track_mbid": "", 165 | "tracknumber": 7, 166 | "work_mbids": [] 167 | }, 168 | "artist_name": "SOHN", 169 | "release_name": "Rennen", 170 | "track_name": "Falling" 171 | }, 172 | "user_name": "iliekcomputers" 173 | }, 174 | { 175 | "listened_at": 1587244887, 176 | "recording_msid": "b8203982-1a84-429e-a908-c09909edff04", 177 | "track_metadata": { 178 | "additional_info": { 179 | "artist_mbids": [], 180 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 181 | "artist_names": [ 182 | "SOHN" 183 | ], 184 | "discnumber": 1, 185 | "duration_ms": 197720, 186 | "isrc": "GBAFL1600374", 187 | "listening_from": "spotify", 188 | "recording_mbid": "", 189 | "recording_msid": "b8203982-1a84-429e-a908-c09909edff04", 190 | "release_artist_name": "SOHN", 191 | "release_artist_names": [ 192 | "SOHN" 193 | ], 194 | "release_group_mbid": "", 195 | "release_mbid": "", 196 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 197 | "spotify_album_artist_ids": [ 198 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 199 | ], 200 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 201 | "spotify_artist_ids": [ 202 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 203 | ], 204 | "spotify_id": "https://open.spotify.com/track/6EN6YYxT2Cv88XJotvuCQW", 205 | "tags": [], 206 | "track_mbid": "", 207 | "tracknumber": 6, 208 | "work_mbids": [] 209 | }, 210 | "artist_name": "SOHN", 211 | "release_name": "Rennen", 212 | "track_name": "Rennen" 213 | }, 214 | "user_name": "iliekcomputers" 215 | }, 216 | { 217 | "listened_at": 1587244689, 218 | "recording_msid": "b11475f4-96ef-4f80-8781-48c9d0256c3f", 219 | "track_metadata": { 220 | "additional_info": { 221 | "artist_mbids": [], 222 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 223 | "artist_names": [ 224 | "SOHN" 225 | ], 226 | "discnumber": 1, 227 | "duration_ms": 207060, 228 | "isrc": "GBAFL1600373", 229 | "listening_from": "spotify", 230 | "recording_mbid": "", 231 | "recording_msid": "b11475f4-96ef-4f80-8781-48c9d0256c3f", 232 | "release_artist_name": "SOHN", 233 | "release_artist_names": [ 234 | "SOHN" 235 | ], 236 | "release_group_mbid": "", 237 | "release_mbid": "", 238 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 239 | "spotify_album_artist_ids": [ 240 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 241 | ], 242 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 243 | "spotify_artist_ids": [ 244 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 245 | ], 246 | "spotify_id": "https://open.spotify.com/track/01XhOduHG9wmJNCHwlCion", 247 | "tags": [], 248 | "track_mbid": "", 249 | "tracknumber": 5, 250 | "work_mbids": [] 251 | }, 252 | "artist_name": "SOHN", 253 | "release_name": "Rennen", 254 | "track_name": "Primary" 255 | }, 256 | "user_name": "iliekcomputers" 257 | }, 258 | { 259 | "listened_at": 1587244482, 260 | "recording_msid": "0217bf23-3373-4fda-a679-9e8c9e228fd8", 261 | "track_metadata": { 262 | "additional_info": { 263 | "artist_mbids": [], 264 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 265 | "artist_names": [ 266 | "SOHN" 267 | ], 268 | "discnumber": 1, 269 | "duration_ms": 183467, 270 | "isrc": "GBAFL1600372", 271 | "listening_from": "spotify", 272 | "recording_mbid": "", 273 | "recording_msid": "0217bf23-3373-4fda-a679-9e8c9e228fd8", 274 | "release_artist_name": "SOHN", 275 | "release_artist_names": [ 276 | "SOHN" 277 | ], 278 | "release_group_mbid": "", 279 | "release_mbid": "", 280 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 281 | "spotify_album_artist_ids": [ 282 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 283 | ], 284 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 285 | "spotify_artist_ids": [ 286 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 287 | ], 288 | "spotify_id": "https://open.spotify.com/track/6ORaBWypbWjYZ4hGyM7l9W", 289 | "tags": [], 290 | "track_mbid": "", 291 | "tracknumber": 4, 292 | "work_mbids": [] 293 | }, 294 | "artist_name": "SOHN", 295 | "release_name": "Rennen", 296 | "track_name": "Dead Wrong" 297 | }, 298 | "user_name": "iliekcomputers" 299 | }, 300 | { 301 | "listened_at": 1587244299, 302 | "recording_msid": "cae62206-d29c-4793-b9db-a7dbb0d7b0ac", 303 | "track_metadata": { 304 | "additional_info": { 305 | "artist_mbids": [], 306 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 307 | "artist_names": [ 308 | "SOHN" 309 | ], 310 | "discnumber": 1, 311 | "duration_ms": 267046, 312 | "isrc": "GBAFL1600350", 313 | "listening_from": "spotify", 314 | "recording_mbid": "", 315 | "recording_msid": "cae62206-d29c-4793-b9db-a7dbb0d7b0ac", 316 | "release_artist_name": "SOHN", 317 | "release_artist_names": [ 318 | "SOHN" 319 | ], 320 | "release_group_mbid": "", 321 | "release_mbid": "", 322 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 323 | "spotify_album_artist_ids": [ 324 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 325 | ], 326 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 327 | "spotify_artist_ids": [ 328 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 329 | ], 330 | "spotify_id": "https://open.spotify.com/track/3cDdNiSpGwgLosEwufaiTK", 331 | "tags": [], 332 | "track_mbid": "", 333 | "tracknumber": 3, 334 | "work_mbids": [] 335 | }, 336 | "artist_name": "SOHN", 337 | "release_name": "Rennen", 338 | "track_name": "Signal" 339 | }, 340 | "user_name": "iliekcomputers" 341 | }, 342 | { 343 | "listened_at": 1587244032, 344 | "recording_msid": "72570d36-5a6a-4f3a-976c-6d4b56f249bd", 345 | "track_metadata": { 346 | "additional_info": { 347 | "artist_mbids": [], 348 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 349 | "artist_names": [ 350 | "SOHN" 351 | ], 352 | "discnumber": 1, 353 | "duration_ms": 223095, 354 | "isrc": "GBAFL1600371", 355 | "listening_from": "spotify", 356 | "recording_mbid": "", 357 | "recording_msid": "72570d36-5a6a-4f3a-976c-6d4b56f249bd", 358 | "release_artist_name": "SOHN", 359 | "release_artist_names": [ 360 | "SOHN" 361 | ], 362 | "release_group_mbid": "", 363 | "release_mbid": "", 364 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 365 | "spotify_album_artist_ids": [ 366 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 367 | ], 368 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 369 | "spotify_artist_ids": [ 370 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 371 | ], 372 | "spotify_id": "https://open.spotify.com/track/65fXbdx5DstarNIGI7NRdS", 373 | "tags": [], 374 | "track_mbid": "", 375 | "tracknumber": 2, 376 | "work_mbids": [] 377 | }, 378 | "artist_name": "SOHN", 379 | "release_name": "Rennen", 380 | "track_name": "Conrad" 381 | }, 382 | "user_name": "iliekcomputers" 383 | }, 384 | { 385 | "listened_at": 1587243809, 386 | "recording_msid": "ff7453c5-1bce-412b-9267-ba194a14ea37", 387 | "track_metadata": { 388 | "additional_info": { 389 | "artist_mbids": [], 390 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 391 | "artist_names": [ 392 | "SOHN" 393 | ], 394 | "discnumber": 1, 395 | "duration_ms": 244186, 396 | "isrc": "GBAFL1600370", 397 | "listening_from": "spotify", 398 | "recording_mbid": "", 399 | "recording_msid": "ff7453c5-1bce-412b-9267-ba194a14ea37", 400 | "release_artist_name": "SOHN", 401 | "release_artist_names": [ 402 | "SOHN" 403 | ], 404 | "release_group_mbid": "", 405 | "release_mbid": "", 406 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 407 | "spotify_album_artist_ids": [ 408 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 409 | ], 410 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 411 | "spotify_artist_ids": [ 412 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 413 | ], 414 | "spotify_id": "https://open.spotify.com/track/7cKeJC6BEEFiHH6pEBVMx5", 415 | "tags": [], 416 | "track_mbid": "", 417 | "tracknumber": 1, 418 | "work_mbids": [] 419 | }, 420 | "artist_name": "SOHN", 421 | "release_name": "Rennen", 422 | "track_name": "Hard Liquor" 423 | }, 424 | "user_name": "iliekcomputers" 425 | }, 426 | { 427 | "listened_at": 1587243556, 428 | "recording_msid": "90083e75-f66e-4910-a74f-1e24cf713233", 429 | "track_metadata": { 430 | "additional_info": { 431 | "artist_mbids": [], 432 | "artist_msid": "232514b4-b231-4a74-90b4-094cdeb93190", 433 | "artist_names": [ 434 | "Prateek Kuhad" 435 | ], 436 | "discnumber": 1, 437 | "duration_ms": 210420, 438 | "isrc": "QM6MZ1811455", 439 | "listening_from": "spotify", 440 | "recording_mbid": "", 441 | "recording_msid": "90083e75-f66e-4910-a74f-1e24cf713233", 442 | "release_artist_name": "Prateek Kuhad", 443 | "release_artist_names": [ 444 | "Prateek Kuhad" 445 | ], 446 | "release_group_mbid": "", 447 | "release_mbid": "", 448 | "release_msid": "5d6a8ddb-667d-4bf5-b5cb-6b9086175903", 449 | "spotify_album_artist_ids": [ 450 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 451 | ], 452 | "spotify_album_id": "https://open.spotify.com/album/46skxGEaSS4gb8HrJUFGOL", 453 | "spotify_artist_ids": [ 454 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 455 | ], 456 | "spotify_id": "https://open.spotify.com/track/552vJkyV7hQmPSjmgwPa5Z", 457 | "tags": [], 458 | "track_mbid": "", 459 | "tracknumber": 6, 460 | "work_mbids": [] 461 | }, 462 | "artist_name": "Prateek Kuhad", 463 | "release_name": "cold / mess", 464 | "track_name": "100 words" 465 | }, 466 | "user_name": "iliekcomputers" 467 | }, 468 | { 469 | "listened_at": 1587243346, 470 | "recording_msid": "e36d179e-8967-454c-a876-0a2a52779135", 471 | "track_metadata": { 472 | "additional_info": { 473 | "artist_mbids": [], 474 | "artist_msid": "232514b4-b231-4a74-90b4-094cdeb93190", 475 | "artist_names": [ 476 | "Prateek Kuhad" 477 | ], 478 | "discnumber": 1, 479 | "duration_ms": 235402, 480 | "isrc": "QM6MZ1811452", 481 | "listening_from": "spotify", 482 | "recording_mbid": "", 483 | "recording_msid": "e36d179e-8967-454c-a876-0a2a52779135", 484 | "release_artist_name": "Prateek Kuhad", 485 | "release_artist_names": [ 486 | "Prateek Kuhad" 487 | ], 488 | "release_group_mbid": "", 489 | "release_mbid": "", 490 | "release_msid": "5d6a8ddb-667d-4bf5-b5cb-6b9086175903", 491 | "spotify_album_artist_ids": [ 492 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 493 | ], 494 | "spotify_album_id": "https://open.spotify.com/album/46skxGEaSS4gb8HrJUFGOL", 495 | "spotify_artist_ids": [ 496 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 497 | ], 498 | "spotify_id": "https://open.spotify.com/track/4oPBOMY6EdR2qAeyG28ZcJ", 499 | "tags": [], 500 | "track_mbid": "", 501 | "tracknumber": 5, 502 | "work_mbids": [] 503 | }, 504 | "artist_name": "Prateek Kuhad", 505 | "release_name": "cold / mess", 506 | "track_name": "fighter" 507 | }, 508 | "user_name": "iliekcomputers" 509 | }, 510 | { 511 | "listened_at": 1587243111, 512 | "recording_msid": "e1132f9e-cdd1-4cde-ad31-5397bfb1a6db", 513 | "track_metadata": { 514 | "additional_info": { 515 | "artist_mbids": [], 516 | "artist_msid": "232514b4-b231-4a74-90b4-094cdeb93190", 517 | "artist_names": [ 518 | "Prateek Kuhad" 519 | ], 520 | "discnumber": 1, 521 | "duration_ms": 186873, 522 | "isrc": "QM6MZ1811454", 523 | "listening_from": "spotify", 524 | "recording_mbid": "", 525 | "recording_msid": "e1132f9e-cdd1-4cde-ad31-5397bfb1a6db", 526 | "release_artist_name": "Prateek Kuhad", 527 | "release_artist_names": [ 528 | "Prateek Kuhad" 529 | ], 530 | "release_group_mbid": "", 531 | "release_mbid": "", 532 | "release_msid": "5d6a8ddb-667d-4bf5-b5cb-6b9086175903", 533 | "spotify_album_artist_ids": [ 534 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 535 | ], 536 | "spotify_album_id": "https://open.spotify.com/album/46skxGEaSS4gb8HrJUFGOL", 537 | "spotify_artist_ids": [ 538 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 539 | ], 540 | "spotify_id": "https://open.spotify.com/track/3NcXC8sOLQCTMa4DjJkyqq", 541 | "tags": [], 542 | "track_mbid": "", 543 | "tracknumber": 4, 544 | "work_mbids": [] 545 | }, 546 | "artist_name": "Prateek Kuhad", 547 | "release_name": "cold / mess", 548 | "track_name": "for your time" 549 | }, 550 | "user_name": "iliekcomputers" 551 | }, 552 | { 553 | "listened_at": 1587242924, 554 | "recording_msid": "60195ea6-ecea-4b6f-9f70-011e5141df35", 555 | "track_metadata": { 556 | "additional_info": { 557 | "artist_mbids": [], 558 | "artist_msid": "232514b4-b231-4a74-90b4-094cdeb93190", 559 | "artist_names": [ 560 | "Prateek Kuhad" 561 | ], 562 | "discnumber": 1, 563 | "duration_ms": 281218, 564 | "isrc": "QM6MZ1811444", 565 | "listening_from": "spotify", 566 | "recording_mbid": "", 567 | "recording_msid": "60195ea6-ecea-4b6f-9f70-011e5141df35", 568 | "release_artist_name": "Prateek Kuhad", 569 | "release_artist_names": [ 570 | "Prateek Kuhad" 571 | ], 572 | "release_group_mbid": "", 573 | "release_mbid": "", 574 | "release_msid": "5d6a8ddb-667d-4bf5-b5cb-6b9086175903", 575 | "spotify_album_artist_ids": [ 576 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 577 | ], 578 | "spotify_album_id": "https://open.spotify.com/album/46skxGEaSS4gb8HrJUFGOL", 579 | "spotify_artist_ids": [ 580 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 581 | ], 582 | "spotify_id": "https://open.spotify.com/track/4Psh3fEnAMftNPOTsAHPgG", 583 | "tags": [], 584 | "track_mbid": "", 585 | "tracknumber": 3, 586 | "work_mbids": [] 587 | }, 588 | "artist_name": "Prateek Kuhad", 589 | "release_name": "cold / mess", 590 | "track_name": "cold/mess" 591 | }, 592 | "user_name": "iliekcomputers" 593 | }, 594 | { 595 | "listened_at": 1587242642, 596 | "recording_msid": "71887f28-c98c-45ae-ad7f-c4e948086d2c", 597 | "track_metadata": { 598 | "additional_info": { 599 | "artist_mbids": [], 600 | "artist_msid": "232514b4-b231-4a74-90b4-094cdeb93190", 601 | "artist_names": [ 602 | "Prateek Kuhad" 603 | ], 604 | "discnumber": 1, 605 | "duration_ms": 172298, 606 | "isrc": "QM6MZ1811442", 607 | "listening_from": "spotify", 608 | "recording_mbid": "", 609 | "recording_msid": "71887f28-c98c-45ae-ad7f-c4e948086d2c", 610 | "release_artist_name": "Prateek Kuhad", 611 | "release_artist_names": [ 612 | "Prateek Kuhad" 613 | ], 614 | "release_group_mbid": "", 615 | "release_mbid": "", 616 | "release_msid": "5d6a8ddb-667d-4bf5-b5cb-6b9086175903", 617 | "spotify_album_artist_ids": [ 618 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 619 | ], 620 | "spotify_album_id": "https://open.spotify.com/album/46skxGEaSS4gb8HrJUFGOL", 621 | "spotify_artist_ids": [ 622 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 623 | ], 624 | "spotify_id": "https://open.spotify.com/track/6FYxi62fuPJk1tnpkuIR6j", 625 | "tags": [], 626 | "track_mbid": "", 627 | "tracknumber": 2, 628 | "work_mbids": [] 629 | }, 630 | "artist_name": "Prateek Kuhad", 631 | "release_name": "cold / mess", 632 | "track_name": "did you/fall apart" 633 | }, 634 | "user_name": "iliekcomputers" 635 | }, 636 | { 637 | "listened_at": 1587242470, 638 | "recording_msid": "c1aacf38-6afc-4574-9759-67ab8cfa83c3", 639 | "track_metadata": { 640 | "additional_info": { 641 | "artist_mbids": [], 642 | "artist_msid": "232514b4-b231-4a74-90b4-094cdeb93190", 643 | "artist_names": [ 644 | "Prateek Kuhad" 645 | ], 646 | "discnumber": 1, 647 | "duration_ms": 231897, 648 | "isrc": "QM6MZ1811453", 649 | "listening_from": "spotify", 650 | "recording_mbid": "", 651 | "recording_msid": "c1aacf38-6afc-4574-9759-67ab8cfa83c3", 652 | "release_artist_name": "Prateek Kuhad", 653 | "release_artist_names": [ 654 | "Prateek Kuhad" 655 | ], 656 | "release_group_mbid": "", 657 | "release_mbid": "", 658 | "release_msid": "5d6a8ddb-667d-4bf5-b5cb-6b9086175903", 659 | "spotify_album_artist_ids": [ 660 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 661 | ], 662 | "spotify_album_id": "https://open.spotify.com/album/46skxGEaSS4gb8HrJUFGOL", 663 | "spotify_artist_ids": [ 664 | "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" 665 | ], 666 | "spotify_id": "https://open.spotify.com/track/0HOVwkHQmGlVfwb8OQflEC", 667 | "tags": [], 668 | "track_mbid": "", 669 | "tracknumber": 1, 670 | "work_mbids": [] 671 | }, 672 | "artist_name": "Prateek Kuhad", 673 | "release_name": "cold / mess", 674 | "track_name": "with you/for you" 675 | }, 676 | "user_name": "iliekcomputers" 677 | }, 678 | { 679 | "listened_at": 1587242127, 680 | "recording_msid": "10258d79-e0fc-4d38-9073-ac55de646b55", 681 | "track_metadata": { 682 | "additional_info": { 683 | "artist_mbids": [], 684 | "artist_msid": "1aa0beaf-d428-425a-bc7f-56dc4883e768", 685 | "artist_names": [ 686 | "Majid Jordan" 687 | ], 688 | "discnumber": 1, 689 | "duration_ms": 214920, 690 | "isrc": "USWB11515054", 691 | "listening_from": "spotify", 692 | "recording_mbid": "", 693 | "recording_msid": "10258d79-e0fc-4d38-9073-ac55de646b55", 694 | "release_artist_name": "Majid Jordan", 695 | "release_artist_names": [ 696 | "Majid Jordan" 697 | ], 698 | "release_group_mbid": "", 699 | "release_mbid": "", 700 | "release_msid": "e86d5465-f719-4da3-82f1-407209964867", 701 | "spotify_album_artist_ids": [ 702 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 703 | ], 704 | "spotify_album_id": "https://open.spotify.com/album/7awpB1UEVeDF6h8mGMssTI", 705 | "spotify_artist_ids": [ 706 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 707 | ], 708 | "spotify_id": "https://open.spotify.com/track/6iPzFPafHG23FomvNwgOLl", 709 | "tags": [], 710 | "track_mbid": "", 711 | "tracknumber": 12, 712 | "work_mbids": [] 713 | }, 714 | "artist_name": "Majid Jordan", 715 | "release_name": "Majid Jordan", 716 | "track_name": "Every Step Every Way" 717 | }, 718 | "user_name": "iliekcomputers" 719 | }, 720 | { 721 | "listened_at": 1587241725, 722 | "recording_msid": "c6f11cfb-7f5b-4f0a-aeac-2bf3497a48b3", 723 | "track_metadata": { 724 | "additional_info": { 725 | "artist_mbids": [], 726 | "artist_msid": "1aa0beaf-d428-425a-bc7f-56dc4883e768", 727 | "artist_names": [ 728 | "Majid Jordan" 729 | ], 730 | "discnumber": 1, 731 | "duration_ms": 306066, 732 | "isrc": "USWB11515052", 733 | "listening_from": "spotify", 734 | "recording_mbid": "", 735 | "recording_msid": "c6f11cfb-7f5b-4f0a-aeac-2bf3497a48b3", 736 | "release_artist_name": "Majid Jordan", 737 | "release_artist_names": [ 738 | "Majid Jordan" 739 | ], 740 | "release_group_mbid": "", 741 | "release_mbid": "", 742 | "release_msid": "e86d5465-f719-4da3-82f1-407209964867", 743 | "spotify_album_artist_ids": [ 744 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 745 | ], 746 | "spotify_album_id": "https://open.spotify.com/album/7awpB1UEVeDF6h8mGMssTI", 747 | "spotify_artist_ids": [ 748 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 749 | ], 750 | "spotify_id": "https://open.spotify.com/track/27jnNdWxyRBabc3c4ZBtG2", 751 | "tags": [], 752 | "track_mbid": "", 753 | "tracknumber": 10, 754 | "work_mbids": [] 755 | }, 756 | "artist_name": "Majid Jordan", 757 | "release_name": "Majid Jordan", 758 | "track_name": "Day and Night" 759 | }, 760 | "user_name": "iliekcomputers" 761 | }, 762 | { 763 | "listened_at": 1587241419, 764 | "recording_msid": "089255e6-42d7-417d-abaa-4ec109b6ddf5", 765 | "track_metadata": { 766 | "additional_info": { 767 | "artist_mbids": [], 768 | "artist_msid": "1aa0beaf-d428-425a-bc7f-56dc4883e768", 769 | "artist_names": [ 770 | "Majid Jordan" 771 | ], 772 | "discnumber": 1, 773 | "duration_ms": 261792, 774 | "isrc": "USWB11515051", 775 | "listening_from": "spotify", 776 | "recording_mbid": "", 777 | "recording_msid": "089255e6-42d7-417d-abaa-4ec109b6ddf5", 778 | "release_artist_name": "Majid Jordan", 779 | "release_artist_names": [ 780 | "Majid Jordan" 781 | ], 782 | "release_group_mbid": "", 783 | "release_mbid": "", 784 | "release_msid": "e86d5465-f719-4da3-82f1-407209964867", 785 | "spotify_album_artist_ids": [ 786 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 787 | ], 788 | "spotify_album_id": "https://open.spotify.com/album/7awpB1UEVeDF6h8mGMssTI", 789 | "spotify_artist_ids": [ 790 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 791 | ], 792 | "spotify_id": "https://open.spotify.com/track/1y5g6vIm7KVdebf5bVyjWX", 793 | "tags": [], 794 | "track_mbid": "", 795 | "tracknumber": 9, 796 | "work_mbids": [] 797 | }, 798 | "artist_name": "Majid Jordan", 799 | "release_name": "Majid Jordan", 800 | "track_name": "Something About You" 801 | }, 802 | "user_name": "iliekcomputers" 803 | }, 804 | { 805 | "listened_at": 1587241157, 806 | "recording_msid": "f3a4f577-fb27-4198-8c36-538aef463411", 807 | "track_metadata": { 808 | "additional_info": { 809 | "artist_mbids": [], 810 | "artist_msid": "1aa0beaf-d428-425a-bc7f-56dc4883e768", 811 | "artist_names": [ 812 | "Majid Jordan" 813 | ], 814 | "discnumber": 1, 815 | "duration_ms": 192386, 816 | "isrc": "USWB11515050", 817 | "listening_from": "spotify", 818 | "recording_mbid": "", 819 | "recording_msid": "f3a4f577-fb27-4198-8c36-538aef463411", 820 | "release_artist_name": "Majid Jordan", 821 | "release_artist_names": [ 822 | "Majid Jordan" 823 | ], 824 | "release_group_mbid": "", 825 | "release_mbid": "", 826 | "release_msid": "e86d5465-f719-4da3-82f1-407209964867", 827 | "spotify_album_artist_ids": [ 828 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 829 | ], 830 | "spotify_album_id": "https://open.spotify.com/album/7awpB1UEVeDF6h8mGMssTI", 831 | "spotify_artist_ids": [ 832 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 833 | ], 834 | "spotify_id": "https://open.spotify.com/track/333eVY2brM1sNQMBPjeGhW", 835 | "tags": [], 836 | "track_mbid": "", 837 | "tracknumber": 8, 838 | "work_mbids": [] 839 | }, 840 | "artist_name": "Majid Jordan", 841 | "release_name": "Majid Jordan", 842 | "track_name": "Warm" 843 | }, 844 | "user_name": "iliekcomputers" 845 | }, 846 | { 847 | "listened_at": 1587240682, 848 | "recording_msid": "445d3228-e0ff-46dd-bb0a-96764d04f655", 849 | "track_metadata": { 850 | "additional_info": { 851 | "artist_mbids": [], 852 | "artist_msid": "1aa0beaf-d428-425a-bc7f-56dc4883e768", 853 | "artist_names": [ 854 | "Majid Jordan" 855 | ], 856 | "discnumber": 1, 857 | "duration_ms": 287813, 858 | "isrc": "USWB11515048", 859 | "listening_from": "spotify", 860 | "recording_mbid": "", 861 | "recording_msid": "445d3228-e0ff-46dd-bb0a-96764d04f655", 862 | "release_artist_name": "Majid Jordan", 863 | "release_artist_names": [ 864 | "Majid Jordan" 865 | ], 866 | "release_group_mbid": "", 867 | "release_mbid": "", 868 | "release_msid": "e86d5465-f719-4da3-82f1-407209964867", 869 | "spotify_album_artist_ids": [ 870 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 871 | ], 872 | "spotify_album_id": "https://open.spotify.com/album/7awpB1UEVeDF6h8mGMssTI", 873 | "spotify_artist_ids": [ 874 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 875 | ], 876 | "spotify_id": "https://open.spotify.com/track/4JZ6o0O6W2NVOXD1iIbVe8", 877 | "tags": [], 878 | "track_mbid": "", 879 | "tracknumber": 6, 880 | "work_mbids": [] 881 | }, 882 | "artist_name": "Majid Jordan", 883 | "release_name": "Majid Jordan", 884 | "track_name": "Shake Shake Shake" 885 | }, 886 | "user_name": "iliekcomputers" 887 | }, 888 | { 889 | "listened_at": 1587240394, 890 | "recording_msid": "dbc89f58-782b-415a-922d-4a3204585273", 891 | "track_metadata": { 892 | "additional_info": { 893 | "artist_mbids": [], 894 | "artist_msid": "1aa0beaf-d428-425a-bc7f-56dc4883e768", 895 | "artist_names": [ 896 | "Majid Jordan" 897 | ], 898 | "discnumber": 1, 899 | "duration_ms": 275826, 900 | "isrc": "USWB11515047", 901 | "listening_from": "spotify", 902 | "recording_mbid": "", 903 | "recording_msid": "dbc89f58-782b-415a-922d-4a3204585273", 904 | "release_artist_name": "Majid Jordan", 905 | "release_artist_names": [ 906 | "Majid Jordan" 907 | ], 908 | "release_group_mbid": "", 909 | "release_mbid": "", 910 | "release_msid": "e86d5465-f719-4da3-82f1-407209964867", 911 | "spotify_album_artist_ids": [ 912 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 913 | ], 914 | "spotify_album_id": "https://open.spotify.com/album/7awpB1UEVeDF6h8mGMssTI", 915 | "spotify_artist_ids": [ 916 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 917 | ], 918 | "spotify_id": "https://open.spotify.com/track/6rhUGIxFVgYjGPFsZfwUxL", 919 | "tags": [], 920 | "track_mbid": "", 921 | "tracknumber": 5, 922 | "work_mbids": [] 923 | }, 924 | "artist_name": "Majid Jordan", 925 | "release_name": "Majid Jordan", 926 | "track_name": "Pacifico" 927 | }, 928 | "user_name": "iliekcomputers" 929 | }, 930 | { 931 | "listened_at": 1587240118, 932 | "recording_msid": "677e7f1a-c739-4ae7-ad6c-2b4e70b60436", 933 | "track_metadata": { 934 | "additional_info": { 935 | "artist_mbids": [], 936 | "artist_msid": "1aa0beaf-d428-425a-bc7f-56dc4883e768", 937 | "artist_names": [ 938 | "Majid Jordan" 939 | ], 940 | "discnumber": 1, 941 | "duration_ms": 259173, 942 | "isrc": "USWB11515046", 943 | "listening_from": "spotify", 944 | "recording_mbid": "", 945 | "recording_msid": "677e7f1a-c739-4ae7-ad6c-2b4e70b60436", 946 | "release_artist_name": "Majid Jordan", 947 | "release_artist_names": [ 948 | "Majid Jordan" 949 | ], 950 | "release_group_mbid": "", 951 | "release_mbid": "", 952 | "release_msid": "e86d5465-f719-4da3-82f1-407209964867", 953 | "spotify_album_artist_ids": [ 954 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 955 | ], 956 | "spotify_album_id": "https://open.spotify.com/album/7awpB1UEVeDF6h8mGMssTI", 957 | "spotify_artist_ids": [ 958 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 959 | ], 960 | "spotify_id": "https://open.spotify.com/track/1CJmTfrlU1d6FtAYNT36wD", 961 | "tags": [], 962 | "track_mbid": "", 963 | "tracknumber": 4, 964 | "work_mbids": [] 965 | }, 966 | "artist_name": "Majid Jordan", 967 | "release_name": "Majid Jordan", 968 | "track_name": "Small Talk" 969 | }, 970 | "user_name": "iliekcomputers" 971 | }, 972 | { 973 | "listened_at": 1587239859, 974 | "recording_msid": "f20b8eb0-7a03-4985-bb0a-3fdb45dfbfa9", 975 | "track_metadata": { 976 | "additional_info": { 977 | "artist_mbids": [], 978 | "artist_msid": "d12b4068-9c69-473c-9242-b73b3e364ee1", 979 | "artist_names": [ 980 | "Majid Jordan", 981 | "Drake" 982 | ], 983 | "discnumber": 1, 984 | "duration_ms": 248432, 985 | "isrc": "USWB11507566", 986 | "listening_from": "spotify", 987 | "recording_mbid": "", 988 | "recording_msid": "f20b8eb0-7a03-4985-bb0a-3fdb45dfbfa9", 989 | "release_artist_name": "Majid Jordan", 990 | "release_artist_names": [ 991 | "Majid Jordan" 992 | ], 993 | "release_group_mbid": "", 994 | "release_mbid": "", 995 | "release_msid": "e86d5465-f719-4da3-82f1-407209964867", 996 | "spotify_album_artist_ids": [ 997 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk" 998 | ], 999 | "spotify_album_id": "https://open.spotify.com/album/7awpB1UEVeDF6h8mGMssTI", 1000 | "spotify_artist_ids": [ 1001 | "https://open.spotify.com/artist/4HzKw8XcD0piJmDrrPRCYk", 1002 | "https://open.spotify.com/artist/3TVXtAsR1Inumwj472S9r4" 1003 | ], 1004 | "spotify_id": "https://open.spotify.com/track/1JUvB8LRKYoik4BB1bEJWK", 1005 | "tags": [], 1006 | "track_mbid": "", 1007 | "tracknumber": 3, 1008 | "work_mbids": [] 1009 | }, 1010 | "artist_name": "Majid Jordan, Drake", 1011 | "release_name": "Majid Jordan", 1012 | "track_name": "My Love (feat. Drake)" 1013 | }, 1014 | "user_name": "iliekcomputers" 1015 | }, 1016 | { 1017 | "listened_at": 1587239566, 1018 | "recording_msid": "f1cececa-9f50-447c-bb94-38b9d12f3568", 1019 | "track_metadata": { 1020 | "additional_info": { 1021 | "artist_mbids": [], 1022 | "artist_msid": "34a9a83b-32f5-433d-a2ff-f8df22550fc0", 1023 | "artist_names": [ 1024 | "KIDS SEE GHOSTS" 1025 | ], 1026 | "discnumber": 1, 1027 | "duration_ms": 197000, 1028 | "isrc": "USUM71808240", 1029 | "listening_from": "spotify", 1030 | "recording_mbid": "", 1031 | "recording_msid": "f1cececa-9f50-447c-bb94-38b9d12f3568", 1032 | "release_artist_name": "KIDS SEE GHOSTS, Kanye West, Kid Cudi", 1033 | "release_artist_names": [ 1034 | "KIDS SEE GHOSTS", 1035 | "Kanye West", 1036 | "Kid Cudi" 1037 | ], 1038 | "release_group_mbid": "", 1039 | "release_mbid": "", 1040 | "release_msid": "9f2eb3e0-2164-48c9-aa05-b2d2cfec91b7", 1041 | "spotify_album_artist_ids": [ 1042 | "https://open.spotify.com/artist/2hPgGN4uhvXAxiXQBIXOmE", 1043 | "https://open.spotify.com/artist/5K4W6rqBFWDnAN6FQUkS6x", 1044 | "https://open.spotify.com/artist/0fA0VVWsXO9YnASrzqfmYu" 1045 | ], 1046 | "spotify_album_id": "https://open.spotify.com/album/6pwuKxMUkNg673KETsXPUV", 1047 | "spotify_artist_ids": [ 1048 | "https://open.spotify.com/artist/2hPgGN4uhvXAxiXQBIXOmE" 1049 | ], 1050 | "spotify_id": "https://open.spotify.com/track/4kUZvXB3LC3an3HX6h0s17", 1051 | "tags": [], 1052 | "track_mbid": "", 1053 | "tracknumber": 7, 1054 | "work_mbids": [] 1055 | }, 1056 | "artist_name": "KIDS SEE GHOSTS", 1057 | "release_name": "KIDS SEE GHOSTS", 1058 | "track_name": "Cudi Montage" 1059 | }, 1060 | "user_name": "iliekcomputers" 1061 | } 1062 | ], 1063 | "user_id": "iliekcomputers" 1064 | } 1065 | } 1066 | -------------------------------------------------------------------------------- /tests/testdata/get_playing_now_happy_path_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "payload": { 3 | "count": 1, 4 | "latest_listen_ts": 1587245842, 5 | "listens": [ 6 | { 7 | "recording_msid": "ae29cef0-4132-49d1-aee8-eeae67763e66", 8 | "track_metadata": { 9 | "additional_info": { 10 | "artist_mbids": [], 11 | "artist_msid": "f938216f-647c-4de3-8006-f793a7df4efa", 12 | "artist_names": [ 13 | "SOHN" 14 | ], 15 | "discnumber": 1, 16 | "duration_ms": 250407, 17 | "isrc": "GBAFL1600378", 18 | "listening_from": "spotify", 19 | "recording_mbid": "", 20 | "recording_msid": "ae29cef0-4132-49d1-aee8-eeae67763e66", 21 | "release_artist_name": "SOHN", 22 | "release_artist_names": [ 23 | "SOHN" 24 | ], 25 | "release_group_mbid": "", 26 | "release_mbid": "", 27 | "release_msid": "e5e40255-355a-48d5-8c20-51fd22ae4e3c", 28 | "spotify_album_artist_ids": [ 29 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 30 | ], 31 | "spotify_album_id": "https://open.spotify.com/album/4ReJh8aIFJ1LlHzg3PBA15", 32 | "spotify_artist_ids": [ 33 | "https://open.spotify.com/artist/6XZYAWJLL8UIbxAqjKj3cg" 34 | ], 35 | "spotify_id": "https://open.spotify.com/track/3wEYsKTvfWeCTa339clXBh", 36 | "tags": [], 37 | "track_mbid": "", 38 | "tracknumber": 10, 39 | "work_mbids": [] 40 | }, 41 | "artist_name": "SOHN", 42 | "release_name": "Rennen", 43 | "track_name": "Harbour" 44 | }, 45 | "user_name": "iliekcomputers" 46 | } 47 | ], 48 | "user_id": "iliekcomputers" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/testdata/good_submit_listens_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": "ok" 3 | } 4 | -------------------------------------------------------------------------------- /tests/testdata/no_playing_now.json: -------------------------------------------------------------------------------- 1 | { 2 | "payload": { 3 | "count": 0, 4 | "listens": [], 5 | "playing_now": true, 6 | "user_id": "iliekcomputers" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/testdata/token_validity_bad_token_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": 200, 3 | "message": "Token invalid.", 4 | "valid": false 5 | } 6 | -------------------------------------------------------------------------------- /tests/testdata/token_validity_good_token_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "code": 200, 3 | "message": "Token valid.", 4 | "user_name": "iliekcomputers", 5 | "valid": true 6 | } 7 | --------------------------------------------------------------------------------