Giter Club home page Giter Club logo

bpm-searcher's Introduction

スクリーンショット 2021-09-23 13 50 36

bpm-searcher

This repository has the code used for bpm-searcher. bpm-searcher can search bpm of a given song by querying Spotify API.

Spotify chart API

This repository also offers simple Spotify chart API which shows the charts in https://spotifycharts.com/regional. You can get this chart information in JSON as the following example. The first element of the array represents the top of the ranking.

GET https://bpm-searcher.onrender.com/api/v1/ranking
[
  {
    "album_name": "F*CK LOVE 3: OVER YOU",
    "artist": "The Kid LAROI",
    "bpm": 169.928,
    "danceability": 0.591,
    "energy": 0.764,
    "image_url": "https://i.scdn.co/image/ab67616d0000b2738e6551a2944764bc8e33a960",
    "key": 1,
    "mode": 1,
    "preview_url": "https://p.scdn.co/mp3-preview/dd4d8d66b97b6edcb5358135e72620715e1449f9?cid=12f045556f09486ba2ca641e0f062fa0",
    "song_name": "STAY (with Justin Bieber)",
    "spotify_id": "5PjdY0CKGZdEuoNab3yDmX"
  },
  {
    "album_name": "MONTERO",
    "artist": "Lil Nas X",
    "bpm": 150.087,
    "danceability": 0.741,
    "energy": 0.691,
    "image_url": "https://i.scdn.co/image/ab67616d0000b273be82673b5f79d9658ec0a9fd",
    "key": 10,
    "mode": 0,
    "preview_url": "https://p.scdn.co/mp3-preview/c1cb40d748692992bd5e476fc17ffe16f31016e3?cid=12f045556f09486ba2ca641e0f062fa0",
    "song_name": "INDUSTRY BABY (feat. Jack Harlow)",
    "spotify_id": "5Z9KJZvQzH6PFmb8SNkxuk"
  },
  ...
]

bpm-searcher's People

Contributors

ooyamatakehisa avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

bpm-searcher's Issues

incorrect mode

attribute "key" from spotify api only shows root note and not shows the mode of it.

some modification

  • handle the case where no query is specified
  • delete runtime error
  • return flask.Response object in controller
  • fix typo

refactoring

  • add singleton decorator (injector)
  • new access_token service
  • add logger.info() message
  • raise error when environmental variables are empty

cache top page ranking

no need to request spotify api to fetch chart information every time.
update per day?

fix bug not to be able to search tracks

@singleton
class TrackInteractor(TrackUsecase):
    @inject
    def __init__(
        self,
        track_repository: TrackRepository,
    ) -> None:
        self.track_repository = track_repository

    def get_tracks_by_query(self, query: str) -> List[Track]:
        return self.get_tracks_by_query(query) # this line causes the bug

add testcase for playlist interactor, repository

  • add testcase for playlist interactor, repository, and controller

    • interactor
    • repository
    • controller
    • model(patch_track_order)
  • modify testcases for track interactor and track repository

    • interactor
    • repository

毎回access_tokenをとりに行っていたのをredisにキャッシュ

ttl属性を設けてそこにexpireする時間を保存時に設定
取得時にその時間を過ぎていたら新しくaccess_tokenを取得して新たに上書きする

spotifyのaccess_tokenは1時間で期限が切れるためttlは50分に設定
https://community.spotify.com/t5/Other-Podcasts-Partners-etc/API-Access-token-expired/td-p/4695256#:~:text=The%20access%20tokens%20expire%20after,This%20is%20a%20security%20measure.

invalid mysql host

Before

app.config["SQLALCHEMY_DATABASE_URI"] = (
    f"mysql://{envs.MYSQL_USER}:{envs.MYSQL_PASSWORD}@mysql/{envs.MYSQL_DATABASE}"
)

After

app.config["SQLALCHEMY_DATABASE_URI"] = (
    f"mysql://{envs.MYSQL_USER}:{envs.MYSQL_PASSWORD}@{envs.MYSQL_ADDR}/{envs.MYSQL_DATABASE}"
)

refactoring

  • "create" -> "save" in repository
  • error handling in redis repository
  • add logger to controller
  • move get track function from spotify to repository
  • use DTO
  • #49
  • aggregate .py file to src dir
  • #40
      if response.status_code != requests.codes.ok:
          self.logger.error(
              f"cannot fetch tracks by ids correctly: {response.json()}"
          )
  • send track data from front end(https://github.com/ooyamatakehisa/bpm-searcher/blob/feature/test/interactor/playlist_interactor.py#L103)
  • #50
  • no logger is given in init of playlist_interactor
  • add docstring to methods in the playlist model
  • in the add method in the playlist method, not to add a PlaylistTrack but a Track
  • move process to get track information to inside if statement in /persistence/playlist.pyスクリーンショット 2021-11-11 22 31 02
  • add Optional typing to return value of the following function and add docstring
    class AuthUsecase(metaclass=ABCMeta):
        @abstractmethod
        def verify_user(self, id_token: str) -> dict:
            pass
  • return playlist and playlist track object when delete_track function is called in playlist_interactor

add test

  • track_controller
  • ranking_controller
  • access_token_interactor
  • ranking_interactor
  • track_interactor
  • access_token_repository
  • ranking_repository

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.