Giter VIP home page Giter VIP logo

amreshsinha / spotify-cards-api Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 11.0 6.14 MB

๐Ÿš€ Unofficial Spotify PromoCards API

Home Page: https://spotify-cards.fossian.com/

License: MIT License

JavaScript 47.89% CSS 1.16% HTML 14.32% SCSS 36.23% Less 0.35% Procfile 0.01% Dockerfile 0.04% Shell 0.01%
spotify spotify-api spotify-cards cards card node-canvas canvas node nodejs hacktoberfest

spotify-cards-api's Introduction

An unofficial open-source Spotify PromoCards API built to serve Song Cards. For more information on using this API, see Docs

Table of contents

Usage

By Song Track Name*

*Results can differ as there can be another song with the Same Name

https://spotify-cards.fossian.com/api?name={song name}&color={color hex without #}

Example

https://spotify-cards.fossian.com/api?name=Silver%20Lining&color=A0C3D2

By Song Track ID {Recommended}

https://spotify-cards.fossian.com/api?id={song id}&color={color hex without #}

Example

https://spotify-cards.fossian.com/api?id=05iALOptaNoV3EmXnxz1IJ&color=A0C3D2

Orientation

Landscape{Default} or Square

Example

https://spotify-cards.fossian.com/api?id={song id}&color={color hex without #}&orientation={landscape/square}

How to get Spotify Song Track ID?

  • Go to your song
  • Right Click >> Share (Keep Ctrl Pressed) >> Copy Spotify URI
  • The ID after spotify: is the Spotify Song Track ID

Support

To log any issue or help with any issue, check out Issues Section.

Release Versions

  • 1.0.0: Supports only Song Tracks. It can take input from the user as name or id only currently.

Host Your Own

See HOSTING for instructions on how to host your own service

Run Locally

  1. Clone the Repository
git clone https://github.com/AmreshSinha/Spotify-Cards-API.git
  1. Get into the project folder and install node modules
npm i
  1. Go to Spotify Developer Dashboard and Create a New Application with no scopes Make a .env and add
  • Client_ID var with your Spotify Dev Application Details
  • Client_Secret var with your Spotify Dev Application Details
  1. Start and Run the Project
npm start

The server will start on port 3000

Contributing

Help Needed

  • Text Wrap: If the Song Name is too long, the text size should decrease and wrap into 2 lines. Spacing between "SONG" and Song Name, and Song Name and Artist name should change accordingly. (Partial Support, Optimization needed)
  • Theme Color Extraction from the image instead of Black as the Default Color. Done Thanks to @delivey
  • Adding Portrait Orientation. Done Thanks to @delivey

All the Issues are in ISSUES section.

Also, before making a PR checkout Code of Conduct

License

Spotify Cards API is available under the MIT license. Spotify Cards API also includes external libraries that are available under a variety of licenses. See LICENSE for the full license text.

spotify-cards-api's People

Contributors

amreshsinha avatar delivey avatar dependabot[bot] avatar letsintegreat avatar mrjmpl3 avatar purvarth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spotify-cards-api's Issues

Landscape image not showing up.

Version

v17.3.0

Platform

OS: Garuda Linux

What steps will reproduce the bug?

  • Start the server in localhost & open docs-page.html in live server.
  • You'll see the landscape image is not getting fetched. It looks like as shown in the given picture
    screenshot-127 0 0 1_5500-2022 01 02-05_35_35
    .

How often does it reproduce? Is there a required condition?

It happens whenever the site is opened in localhost.

Is there any Package conflicting with other packages?

No. As per my knowledge there is no issue for package conflicting.

What is the expected behavior?

The landscape image should show up just like the square image.

What do you see instead?

Provided in the screenshot above.

Additional information

No response

Song name is being overlapped by the "song" label in portrait and landscape cards

Version

v16.13.0

Platform

Microsoft Windows NT 10.0.22621.0 x64

What steps will reproduce the bug?

Running the program locally and testing the portrait and landscape examples with different song IDs.

How often does it reproduce? Is there a required condition?

Every time, no matter the song ID.

Is there any Package conflicting with other packages?

No response

What is the expected behavior?

I'm not too sure what the expected behavior is. Either the 'song' label sits above the song name or the label shouldn't be there at all.

What do you see instead?

"Song" label overlaps the song name.

image

image

Additional information

Just came across this while messing around with the examples on my local machine. Not sure if this is a known issue. I can try to fix it if you want to label this under "hacktoberfest"?.

Add Portrait Orientation.

Implement portrait orientation, apply text wrap for song name and artist name, and add the respective information in docs.

Text Wrap

Is your feature request related to a problem? Please describe.
Currently, if a song has a big name then it's full name crosses the canvas instead of wrapping into new line

Describe the solution you'd like
Implementing Text Wrap with which longer names can automatically wrap into next line and also the font size of the name should decrease dynamically.

This might help: http://jsfiddle.net/mg9jxhbn/1/

  • Font size should decrease dynamically too
  • Space between "S O N G" and song name, and song name and the artist name should decrease too
  • This wrapping is also needed for artists name section too

Describe alternatives you've considered
No Alternatives right now.

Ideas for the project

Hi! I have some ideas about the project:

  • Text color (same a background color but with the text)
  • Sort the files of the project
  • Use prettier and huskyjs (to format the code and get a standard codelines)
  • Use Vuejs and Vite or Webpack (That depends is you want)

If you want, I can do that things

Different aspect ratios

DISCUSSION NEEDED

So the official Spotify promo cards website has a feature where you can select the size.
image
I think we could do something like this.

We would need to add a total of 2 styles:

  • Square
  • Portrait

What do you think?

(Don't assign me just yet, if after the discussion we agree on adding this, I can experiment with something like this)

Removal of brackets from song name.

All the songs' names I have come across on Spotify use brackets to add their artist's name.
I think we should remove the bracketed text from the song name before displaying it on the card because it is just noise as we have artists' names in another field anyways.

Removing the bracketed text will make the card more minimal and less congested.

image

image

Adding create card button option for user.

Is your feature request related to a problem? Please describe.
Currently, there is no input or create card button option in the page. User has to copy the API link and hit the end points after entering the data in the url to get the result.

Describe the solution you'd like
A feature can be implemented for the user. So that the user can type the song name and color code as desired and the result will be show on the same or new page. Similarly, for other option like for song id the input can be changed depending on the option chosen by the user. This will result in more user friendly UI.
Just a simple representation of the proposed feature.
screenshot-127 0 0 1_5500-2021 12 29-05_18_51(1)

Describe alternatives you've considered
No alternatives right now.

Even if `color=000` is used in the api request, black color is not being used.

Version

v16.13.1

Platform

No response

What steps will reproduce the bug?

/api?name=Silver%20Lining&color=000

This request should get black background color, but that's not the case.

How often does it reproduce? Is there a required condition?

Every time 000 is used for hex, if one uses 000000, it works fine.

Is there any Package conflicting with other packages?

No response

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

let imageColor = '#000';

Instead of using #000 as a flag to determine if the user has specified the value of color, a boolean variable should be used.

Add Docker steps in HOSTING.md

Is your feature request related to a problem? Please describe.
The HOSTING.md does not have steps for hosting with docker under the host on your own server section.

Describe the solution you'd like
Add steps for hosting with docker and reverse proxying it with Traefik. Make sure you add a reference to installing Traefik, which can be found here: https://fossian.com/simplify-deployment-traefik-walk-through/ .

Make sure you verify the steps by trying it on an actual virtual server and attaching a subdomain or domain to it.
You can get a virtual server for free on the oracle cloud free tier or digitalocean trial.
And for a subdomain, you can get one for free on afraid DNS or any other provider.

You can also add images for the steps.

Other Languages Support

Is your feature request related to a problem? Please describe.
Currently, it does not support many other languages out there like Japanese.
Spotify Song ID: 51oc6MEsXTpnPn6GOw5VuP
Spotify Track Link: https://open.spotify.com/track/51oc6MEsXTpnPn6GOw5VuP?si=815531d53b484cae
Name: ใใ‚‰ใ‚Š by Fujii Kaze
Image:
ใใ‚‰ใ‚Š by Fujii Kaze

Describe the solution you'd like
Needs more investigation. Will do it in my free time. Up for grabs if anyone wants to resolve it.

Describe alternatives you've considered

Add CONTRIBUTING guidelines

Is your feature request related to a problem? Please describe.
Currently, there are no CONTRIBUTING guidelines for newcomers.

Describe the solution you'd like
Add a CONTRIBUTING.md file listing all the rules and guidelines which should be followed while contributing to the repo.

Anything extra you want to add?
Make sure it at least follows the general rules of creating a new branch and how to name PRs.

References
You are free to see any references and examples. Just don't copy them straightforwardly.
Some examples:
https://github.com/AmreshSinha/sshot/blob/main/CONTRIBUTING.md
https://github.com/appwrite/appwrite/blob/master/CONTRIBUTING.md
https://reactjs.org/docs/how-to-contribute.html
https://github.com/vercel/next.js/blob/canary/contributing.md

Improve accuracy for searching by name.

(Discussion needed first)

When searching by name, the 6th result of the search will be omitted due to this line:
await spotifyApi.searchTracks(name, {market:'US', limit:1, offset:5})
In my opinion, we should remove the offset and show the 1st result instead. This will result in the most popular song being omitted which statistically speaking should be what the user was searching for.

Examples:
Query: the%20nights (the nights)
Offset 5:
image
No offset:
image

Very simple issue to fix, literally just removing a few characters from the line mentioned above in /index.js

Theme Color Extraction

Is your feature request related to a problem? Please describe.
By default the color for the background is black. So, if in the request, color is not provided the client will get an image with Black background.

Describe the solution you'd like
Instead of Black Color, we can extract the Dominant or Average color from the image and can set the background for that Song Card with that color code.

Describe alternatives you've considered
You can either code your own script for this or use already available packages like Vibrant.

[BUG] Picking Album Name instead of Song Name

What steps will reproduce the bug?

Well sharing the code for merging the functions in a code block in this issue would not be optimal. I'm not sure we're on the same page here. Let me know if later on you want to save time and let me create the PR for merging the functions.

Will open a PR for this issue (Theme Color Extraction) in a few minutes.

On another note, is it just me or does the image sometimes contain the album name instead of the actual song name?

Album Name: Somewhere New
Link to Album: https://open.spotify.com/album/2tYcFWd25g2Y69VQHiNJwD?si=kpz0IFRgQtqpKUDSKDXTew&dl_branch=1

Song Name: Your Spell
Link to Song: https://open.spotify.com/track/1y6ZCzDYOkXXq5o7BUkbIi?si=a1f1311e917542d9
ID: 1y6ZCzDYOkXXq5o7BUkbIi

Spotify Card for that image:

Have to Fix

@delivey thanks for pointing it out. I will open an issue for it. If you wanna work on that too you are welcome ๐Ÿ‘

Originally posted by @AmreshSinha in #3 (comment)

How often does it reproduce? Is there a required condition?

<--BUG-->

Is there any Package conflicting with other packages?

<--NO-->

What is the expected behavior?

It should have shown the song name instead of the parent album's name.

What do you see instead?

A card with its parent album's name.

Additional information

For info, you can test it out yourself by using the reproducing step.
Also,
Issue #3

Server Not Responding

I entered a random name "SomeoneNoone", after which the server is not responding :/

Not sure if you stopped the server ๐Ÿ˜† or it was due to this

Overall code cleanup

The codebase is pretty messy right now, this issue suggests what to fix to change that.

  1. Remove unused imports like this:
const fetch = require('cross-fetch') // Not Used
const path = require("path")
const express = require('express')
const bodyParser = require('body-parser') // Not Used
const url = require('url') // Not Used
const querystring = require('querystring') // Not Used
const fs = require('fs') // Not Used
const SpotifyWebApi = require('spotify-web-api-node')
const cors = require('cors');
  1. Remove unused vars, for example:
let songName, songArtist, songImageURL; // Not Used
  1. Use await for the newToken function instead of the current then method:
  2. Use awaits instead of thens in the searchTracksByName and searchTracksById functions
  3. Use a join instead of this:
    for (let i = 0; i < artistList.length; i++) {
        if (i==artistList.length-1) {
            artistString += artistList[i]
        }
        else {
            artistString += artistList[i] + ", "
        }
    }
  1. Merge the searchTracksByName and searchTracksById functions. I suggest to provide the function with a string called searchType using which the function decides whether to call the spotify API for song data like in the searchTracksByName function or like in the searchTracksById function.
  2. Remove unused comments, for example:
            // const spotifyCard = {
            //     spotifyCardURL: cardURL
            // }
            // res.render('api', spotifyCard)
            // res.send(cardURL)
            // res.write('<img src = "'+cardURL+'">');
            // console.log(cardURL) // Image which we want
            // fs.writeFileSync('./test.png', buffer)

These are all of my suggestions for now, I can do all of them, let me know if I should do this and which ones.

Text not visible when background is white.

Text is not visible when the chosen background color is similar to white, as here:

image

I think the text color should be changed depending on the background color.
This answer can be super useful.

IMO, text color should be changed when delta E <= 2.
Right now, I am thinking of using the average color of img as the text color, in case the background color is similar to white.

But if the average color is also similar to the background color, I haven't figured that out. WDYT?

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.