Giter Site home page Giter Site logo

sofakingcool / webradio-api Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 27 KB

A minimal multi-service oriented search and streaming API in PHP for your Multi Theft Auto server

License: MIT License

PHP 100.00%
streaming-api youtube php soundcloud jamendo multi-theft-auto mtasa mp3library myfreemp3 webradio-api

webradio-api's Introduction

Webradio-API

A minimal multi-service oriented search and streaming API for your Multi Theft Auto server

Getting Started

Prerequisites

You need a web server like nginx or apache with PHP. The web server should serve content from the public directory and not anywhere else to reduce the attack margin to a minimum. Due to the early stages of the project you are forced to use >= PHP 7 because the code uses e.g. the null coalesce operator, which was first introduced in PHP 7.

Installing

Clone the repository to your disk, copy the config.example.php file as config.php in the root-directory and open it in an editor of your choice.

Remove the default keys in the two $searchKeys and $streamKeys arrays and add your own secret key strings to the array. There is no character limit on the keys and you can use any character, whitespace too. Example:

$searchKeys = [
    "2JXR861JPWJ1CENHF51WA3QF3UK1I1QA", // You shouldn't use this one
    "9LRAP2PIJRCDYTQL5844O2VV2QX3TCQ6", // Neither this one
    // ...
];

$streamKeys = [
    "M97JY494ZONC", // Don't even think about using
    "6Z3NRRU8YW56", // these exact keys in your application
];

Finally, you should add your private API keys for YouTube, Soundcloud and Jamendo. Other included services do not require an API key.

Note: You MUST configure your webserver to point to the public directory of the application.

Shortcuts for API registration

Cron: Cleanup

You have to setup a cronjob to execute the clean up script to remove old files in the storage subdirectories. Please change the URL to the PHP script in this example to fit your environment.
0 0 * * 0 /usr/bin/curl http://127.0.0.1/webradio-api/cleanup.php?key=<a key from $streamKeys> >/dev/null 2>&1

Development

You should set the $debug_mode variable in config.php to true if you want to receive the fine details of the exception whenever your application drops an Out of Order error.

Troubleshooting

Permission denied for mkdir()

Make sure your webserver user has enough permissions for writing in the /storage (sub-)directories.

Many YouTube videos stopped working

You might run into this issue everytime the YouTube's player JavaScript code changes the layout and the decoder can not figure out the decoding algorithm. Feel free to submit an issue here on GitHub to notify me about it, but don't open a new issue if there is already opened issue regarding this problem, please.

Usage

Search

/search.php?key=<a key from $searchKeys>&service=YouTube&query=Bohemian+Rhapsody
/search.php?key=<a key from $searchKeys>&service=Soundcloud&query=Adele+Hello
/search.php?key=<a key from $searchKeys>&service=Jamendo&query=Sunshine
/search.php?key=<a key from $searchKeys>&service=MyFreeMP3&query=We+Right+Here
/search.php?key=<a key from $searchKeys>&service=MP3Library&query=Bob+Dylan

Stream

/stream.php?key=<a key from $streamKeys>&service=YouTube&id=<song id>
/stream.php?key=<a key from $streamKeys>&service=Soundcloud&id=<song id>
/stream.php?key=<a key from $streamKeys>&service=Jamendo&id=<song id>
/stream.php?key=<a key from $streamKeys>&service=MyFreeMP3&id=<song id>
/stream.php?key=<a key from $streamKeys>&service=MP3Library&id=<song id>

Examples

YouTube

/search.php?query=Bohemian+Rhapsody&service=YouTube&key=<a key from $searchKeys>

[
  {
    "id": "fJ9rUzIMcZQ",
    "title": "Queen - Bohemian Rhapsody (Official Video)"
  },
  {
    "id": "3p4MZJsexEs",
    "title": "Bohemian Rhapsody by Queen FULL HD"
  },
  {
    "id": "irp8CNj9qBI",
    "title": "Queen - Bohemian Rhapsody"
  }
]

Soundcloud

/search.php?query=Adele+Hello&service=Soundcloud&key=<a key from $searchKeys>

[
  {
    "id": "230155983",
    "title": "Hello - Adele",
    "duration": 300
  },
  {
    "id": "229791977",
    "title": "Adele - Hello (Cover by Lianna Joy)",
    "duration": 295
  },
  {
    "id": "230335097",
    "title": "Hello โ€ Adele",
    "duration": 294
  }
]

Error

This example shows the JSON output if you omit the key query parameter in your request.

{
  "error": "Unauthorized",
  "errno": 2
}

Contribute

Contributions are always welcome. Feel free to write an ISSUE or PULL REQUEST.

License

This project is licensed under the MIT License - see the LICENSE file for details.

webradio-api's People

Contributors

botder avatar necktrox avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

webradio-api's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.