Skip to main content

Python API for vgmusic.com.

Project description

vgmusic.py

Code style: black PyPI - Downloads PyPI - License PyPI PyPI - Python Version Lines of code

(unofficial) Python API for VGMusic. This project is in no way affiliated with or sponsered by Mike Newman or any of the staff at VGMusic.

Usage

Thoughout these examples, we will be using the API object as the api:

import vgmusic

api = vgmusic.API()

It is recommended to close it once you are done:

# do something here...
api.close()

The best way is to use a context manager, a.k.a with statement:

with vgmusic.API() as api:
    # do something here

Note that the API is lazy: It will only retrieve data for a console/system the first time it is queried for it. To override this behaviour, use force_cache (see Module Documentation).

Backends

The API has two backends: dictionary-like (access from Python code) and a REST-based web interface (through Flask, from elsewhere) (WIP). You can also use it from the command-line.

Dictionary/Key

To query songs, you have to provide the name of the system/catagory and the game title:

songs = api["Sony PlayStation 4"]["titles"]["Persona 5"]

You can manipulate the API using standard dictionary methods:

# list all titles for a system
titles = list(api["Nintendo Switch"].keys())  # ['Sonic Mania'], as of 5/1/2021
# count how many songs in total
total = sum(len(songs) for songs in api["Nintendo Switch"]["titles"].values())  # 12, as of 5/1/2021

Anything you can do with a dictionary, it's basically possible with this API.

API index format (all URLs are absolute):

// Any keys starting with '$' are variable.
{
    // The system's name
    "$system_name": {
        // The system's url, i.e https://www.vgmusic.com/music/console/sony/ps4/
        "url": ...,
        // The section's name, i.e Sony
        "section": ...,
        // All the titles available for this system
        "titles": {
            // The game's name.
            "$game_name": [
                // The direct url to the song's MIDI file
                "song_url": ...,
                // The song's title
                "song_title": ...,
                // The song's file size, in bytes (as an int)
                "file_size": ...,
                // Who sequenced the midi
                "sequenced_by": ...,
                // url to comments
                "comments_url": ...,
            ]
        },
        // When the system's page was last updated (as a Unix timestamp as int)
        "last_updated": ...,
        // Used to track page revisions
        "_etag": ...,
        // Version of the VGMusic indexer.
        "indexer_version": ...
    }
}

CLI

Install the CLI first:

pip install vgmusic[cli]

And then run with

vgmusic

On first run, it might take a while to initally cache all the systems. Maybe grab a cup of tea or two.

Once parsing is done, it will download all the MIDI files by default.

To fliter out songs using regex, use the -s/--search option:

vgmusic -s "Sony PlayStation \d::Persona \d::.*"

This downloads all songs from the system Sony PlayStation \d and the game Persona \d which has any name.

-s/--search maps directly to API.search_by_regex().

Help is always useful:

vgmusic --help

REST/Flask

NOTE: This is WIP, it has not been finished yet. Make sure you have installed the Flask extension:

pip install vgmusic[REST]

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vgmusic-0.1.1a3.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vgmusic-0.1.1a3-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file vgmusic-0.1.1a3.tar.gz.

File metadata

  • Download URL: vgmusic-0.1.1a3.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.0

File hashes

Hashes for vgmusic-0.1.1a3.tar.gz
Algorithm Hash digest
SHA256 0f405978c8165a2676e7438b239c7d5dcebc52a2115d18531fbfe003685ac44b
MD5 c262725f689f609deb3f35430735a150
BLAKE2b-256 add4890cf918452e2b56c0d887757e14d17fe3aa3e13ccff8965023474c9ba86

See more details on using hashes here.

File details

Details for the file vgmusic-0.1.1a3-py3-none-any.whl.

File metadata

  • Download URL: vgmusic-0.1.1a3-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.0

File hashes

Hashes for vgmusic-0.1.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 6a9c1a6e3a6160cd594c0860ce312ee20e01d2ca74a8a75a4fd6af8e69669ff3
MD5 718b2d6e492713a028888c1611b36c9b
BLAKE2b-256 6c1ae516be8fae65af8756aed234708a604dae295bd42a1d5830ccb82f3ba302

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page