Skip to main content

LAN-PLAY API Python

Project description

LanPlay API

lanplaypy

Visitors Stars Issues

This is the unofficial API for LanPlay.
It's made for getting servers, rooms, games and players easily from LanPlay API.
It was designed to make life easier for developers with LanPlay. It’s a more direct and simple interface with the API.

Table of Contents

Installation

pip install lanplaypy

Get API Key

To use the LanPlay package you will need a specific, non-transferable API key that can be retrieved from LanPlay.
Please follow these steps :

  1. Open a Web Browser and go to http://www.lan-play.com
  2. Open a Console Mode (Ctrl + Shift + C should work, or Google is your friend to find how to access the Console Mode 🫠)
  3. Go to Network tab and refresh the current page
  4. Search a line named getMonitors and click on it
  5. Open the Payload tab
  6. Copy the api_key value and paste it into the LanPlay('LAN_PLAY_API_KEY') definition below (replace 'LAN_PLAY_API_KEY' with the api_key value)

Script Example

Before doing anything be sure to get your api_key from Get API Key section

Here is an example of a simple script using LanPlay API that gets server infos refreshed every 1 second

import asyncio
import lanplay
import time
import os


async def main(time_to_refresh: int = 1):
    # time_to_refresh let you update the informations of the server every 1 seconds
    # You can change this variable from execution in loop.run_until_complete(main()) at the end of this script with some other values
    # For example to update the infos of the server every 0.5 seconds or 500ms, you can use await main(0.5)

    lan = lanplay.LanPlay('LAN_PLAY_API_KEY')
    # Create an instance of the LanPlay class with LAN_PLAY_API_KEY
    # It's the main variable where all data will be stored

    print('List of all LanPlay servers available : ', lan.servers)
    # Useful when you don't know wich LanPlay server to choose...

    await lan.setServer('joinsg.net:11453')
    # Initialize the server with any LanPlay server you want
    # Here is an example with the joinsg.net:11453 server
    # Replace with 'http:/joinsg.net:11453/' will works too

    # You can now access all data from 'lan' variable

    while True:
        os.system('clear')
        # Clear the console to get a clean UI with updated server's infos

        # See below some useful examples

        for room in lan.rooms:
            # Display games info of a room

            print(room.advertise_data)
            print(f'Room {lan.rooms.index(room) + 1} :')
            print('Host Player : ', room.host_player)
            print('Unique Nintendo Host Player Name : ',
                  room.host_player_nintendo_name)
            # Unique Nintendo host player name

            if room.game:
                print('Game : ', room.game.name)
                # Or 'room.game' will also displays the name of the game

                print('Icon URL of the Game : ', room.game.icon_url)
                # Useful when you want a cool picture of the current game played

                print('Game Size : ', room.game.size)
                # To see if you've enough space to download this game on your Switch...

                print('Publisher of the Game : ', room.game.publisher)
                # Get the publisher of the actual played game

            print('Max Players number in the room : ', room.node_count_max)
            # Max Players allowed to play in a room

            print('Actual number of Players in the room: ', room.node_count)
            # Actual number of Players playing in a room

            for player in room.players:
                # Display players infos of a room

                print(f'Player {room.players.index(player) + 1} : ', player)
                # Or 'player.player_name' will also displays the name of the player

        print('Players Online : ', lan.server_info.online)
        # Displays the current number of Online players in the server

        print('Players Idle : ', lan.server_info.idle)
        # Displays the current number of Idle players in the server

        await lan.refreshServer()
        # Function that refresh all infos of the server, rooms, games and players to stay up-to-date

        time.sleep(time_to_refresh)
        # Wait 'time_to_refresh' seconds (1 second in this example) before continue the loop

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
  • Or you can also use it in CLI as well with the same syntax.

Contributing

Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/NewFeature)
  3. Commit your Changes (git commit -m 'Add some NewFeature')
  4. Push to the Branch (git push origin feature/NewFeature)
  5. Open a Pull Request

Thanks to every contributors who have contributed in this project.

License

Distributed under the MIT License. See LICENSE for more information.


Author/Maintainer: Garoh | Discord: GarohRL#4449 1.1.0 (2023-05-09)

Security Fixes

  • Improve security and data integrity assurance in general.

New Features

  • Changed how to access the attributes of a class instance. (Transparent to the user.)

Bug Fixes

  • Fixed codec decoding. Please use 'utf-8' or 'utf-16' in Room(encoding='utf-X').

Improvements

  • Optimize class access and remove some useless data accesses for the user. It's a more clean coding environment now.

Documentation

  • Update the example script with more code explanation and more user-friendly UI.

  • Clarify the steps to get the api_key value from LanPlay website. Update some other infos.

MIT License

Copyright (c) [2023][Kilian Douarinou]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

lanplaypy-1.1.0.tar.gz (11.5 kB view hashes)

Uploaded Source

Supported by

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