Categorygithub.com/YouTube2Spotify/y2s-backend
repositorypackage
0.0.0-20220320085507-348d6ec671f9
Repository: https://github.com/youtube2spotify/y2s-backend.git
Documentation: pkg.go.dev

# README

YouTube 2 Spotify (Y2S) Backend

YouTube 2 Spotify saves the currently playing YouTube song into your Spotify library.

A complete rewrite of YouTube 2 Spotify's original Node.js backend into Golang for performance improvements.

This is the backend that powers YouTube 2 Spotify's functionality. Using the URL and Spotify access token provided by the Chrome extension, this program will download the video, convert it to an audio file, then use Odesli or AudD's API to identify the track. The track will then be added to the user's Spotify liked playlist.

Get the extension on the Chrome Store or GitHub


Overview

Running the backend locally

  1. Set up base files

    $ git clone https://github.com/YouTube2Spotify/y2s-backend
    $ touch .env
    
  2. Install ffmpeg (for converting downloaded video files to mp3s for AudD.io's API)

    • For MacOS: brew install ffmpeg
  3. Create Spotify developer account & app

    • Visit this link and click CREATE AN APP.
    • Enter your Application Name and Application Description and click Create.
    • Click on your newly created app within the dashboard to find your Client ID and Client Secret.
    • Set redirect uris to your extension's callback (ex. https://iigamqfeafobbpahkaiiammplhmeegga.chromiumapp.org/callback)
      • The ID preceding chromiumapp.org must match your extension's unique ID.
      • You can obtain the ID of your extension by going to the extensions page in your Chrome browser. The developer mode toggle on the upper right of the page must be enabled to view extension IDs.
  4. Obtain an API key from AudD

  5. Set environment variables

    Open and edit .env

    PORT=port
    AUDDIO_API_KEY=your_audD_api_key
    ODESLI_API_KEY=your_odesli_api_key
    FFMPEG_PATH=path_to_ffmpeg
    
  6. Run the application

    $ go run main.go
    

API Endpoint

POST /localhost:<your port>/api/like_song

Uses the provided YouTube url and Spotify access token to download the youtube video, convert the video to an mp3 file, use AudD's music recognition service to retrieve info on the song, and use retrieved info to add the song to the user's Spotify liked list.

After performing said operations, the API will also return a JSON with information about the Title, Artist, and Spotify ID of the song that was discovered. This data is used by the Chrome extension to notify the user the name and artist of the song that was just added to their liked playlist.

Parameters

NameRequiredTypeDescription
videoUrlrequiredstringURL of YouTube video
accessTokenrequiredstringAccess token for Spotify generated by Spotify's authentication flow.

This is normally generated by the extension itself. If you want to manually post to this endpoint, you will need manually generate the access token yourself.

Response

{
   "title": "Example Song Title",
   "artist": "Example Song Artist",
   "spotifyId": "Example Spotify Track ID"
}


Building

$ go build -o main

Powered by


License

Y2S is available under the MIT license. See the LICENSE for more info.