GithubHelp home page GithubHelp logo

foosiee / spotify-lyrics Goto Github PK

View Code? Open in Web Editor NEW
16.0 0.0 0.0 38 KB

Flask App to display lyrics on webpage

Python 42.11% CSS 12.15% HTML 21.88% JavaScript 23.86%
python flask spotify spotify-api current-track lyrics lyrics-fetcher

spotify-lyrics's Introduction

Spotify-Lyrics

THIS REPO HAS BEEN MOVED TO THIS NEW REPO

  • The main change is to a serverless architecture

a python flask App for obtaining the users current track and displaying its lyrics on the browser.

(http://spotify-lyrics.com/)

login

screen shot 2019-02-11 at 7 52 08 pm

authorization

  • Spotify-Lyrics follows Spotify's authorization code flow.
  • scope of authorization is for user-read-currently-playing
  • a user authorization token is generated on the server and sent client side as json

getting lyrics

  • with the token now on the clients machine the code makes a request to the spotify api with the token
 fetch('https://api.spotify.com/v1/me/player/currently-playing', {
headers: {
    'Authorization': `Bearer ${token}`
}
  • this api call will return a json object that contains all information to obtain the lyrics to the song
    • track
    • artist
  • this information is then sent back server side

getting lyrics case 1

  • to obtain lyrics Spotify-Lyrics uses python package tswift
  • tswift is a very simple metrolyrics "api" to retrieve lyrics
  • the first attempt to get lyrics is very simple
s = Song(track,artist)
  • the song object from tswift is instantiatiated with the track and artist sent up from the client
  • simply return s's lyrics property
return s.lyrics
  • send lyrics back to client as json

getting lyrics case 2

  • tswifts song object sometimes will not find the lyrics with track and artist arguments
  • to counter this you can provide a link to the song object
  • to do this a google search is done using the requests package
  • program finds first instance of metrolyrics
def lyricsLink(track,artist,website):

        track +=  " " + artist + ' ' + website
        name = urllib.parse.quote_plus(track)

        hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11'
            '(KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
            'Accept-Language': 'en-US,en;q=0.8',
            'Connection': 'keep-alive'}

        url = 'http://www.google.com/search?q=' + name

        result = requests.get(url, headers=hdr).text
        if website == 'azlyrics':
            link_start = result.find('https://www.azlyrics.com')
        else:
            link_start = result.find('http://www.metrolyrics.com')
        link_end = result.find('.html', link_start + 1)
        link = result[link_start:link_end +5]
        return link
  • Song object is created and lyrics are returned in a similar fashion

case 3

  • if both these methods do not work
  • we will generate a link to azlyrics
  • this link is generated in the same method as the metrolyrics link
  • this link is sent down to the client as json

displaying lyrics

result

screen shot 2018-12-05 at 5 08 54 pm

bugs / additions

  • website fails if the user refreshs the page because token is lost upon refresh
    • possible solution: send token down in a template
  • need to implent refresh tokens so the users session is not over after an hour

spotify-lyrics's People

Contributors

foosiee avatar

Stargazers

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

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.