Code Monkey home page Code Monkey logo

genius-lyrics's Introduction

genius-lyrics

This is a custom component for Home Assistant to allow fetching song lyrics from Genius.

NOTE: this is a work in progress -- expect changes.

Installation

With HACS

  1. Open HACS Settings and add this repository (https://github.com/robert-alfaro/genius-lyrics) as a Custom Repository (use Integration as the category).
  2. The Genius Lyrics page should automatically load (or find it in the HACS Store)
  3. Click Install

Manual

Copy the genius_lyrics directory from custom_components in this repository, and place inside your Home Assistant installation's custom_components directory.

Setup

  1. Sign up for a free account at genius.com and authorize access to the Genius API to get your client_access_token.
  2. Install this component
  3. Install markdown card mod lovelace-markdown-mod
  4. Add the following to your configuration.yaml
genius_lyrics:
  access_token: "your Genius client access token"

sensors:
  - platform: template
    sensors:
      lyrics:
        friendly_name: "Lyrics"
        value_template: ""
  1. Create markdown card in lovelace.
  - type: markdown
    content: >
      ## [[ sensor.lyrics.attributes.artist ]] - [[ sensor.lyrics.attributes.title ]]

      [[ sensor.lyrics.attributes.lyrics ]]
  1. Create an automation to call service genius_lyrics.search_lyrics upon media_player state change, providing "Artist", "Title".

Screenshot

lyrics-card


Example service call JSON

{
 "artist_name":"Protoje",
 "song_title":"Mind of a King",
 "entity_id":"sensor.lyrics"
}

Thanks to

  • @johnwmillr for lyricsgenius python package!
  • @thomasloven for lovelace markdown-mod!

genius-lyrics's People

Contributors

airdrummingfool avatar robert-alfaro avatar

Watchers

 avatar

genius-lyrics's Issues

Crash when search fails (e.g. song not found at Genius)

Service call:

{
 "api_key":"[redacted]",
 "artist_name":"EMBRZ, Leo Stannard",
 "song_title":"She Won't Let Me Down (feat. Leo Stannard)",
 "entity_id":"sensor.lyrics"
}

Error:

Sat Aug 17 2019 23:15:08 GMT-0500 (Central Daylight Time)
Error while executing automation automation.misc_update_genius_lyrics_when_spotify_song_changes. Unknown error for call_service at pos 1: 
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 427, in action
    await script_obj.async_run(variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 235, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 318, in _async_call_service
    context=context,
  File "/usr/src/app/homeassistant/helpers/service.py", line 97, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/app/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/app/homeassistant/core.py", line 1262, in _execute_service
    await self._hass.async_add_executor_job(handler.func, service_call)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/genius_lyrics/__init__.py", line 51, in search_lyrics
    attrs = song.to_dict()
AttributeError: 'NoneType' object has no attribute 'to_dict'

Add API Key as configuration parameter

Right now the API key must be passed in each service call. This should instead be part of the configuration.yaml settings, so we can (e.g.) pull from secrets.yaml.

Searching Lights and Sounds by Yellowcard brings up incorrect song

2019-08-21 05:37:49 DEBUG (SyncWorker_1) [custom_components.genius_lyrics] Searching for lyrics with artist 'Yellowcard' and title 'Lights And Sounds'
2019-08-21 05:37:51 DEBUG (SyncWorker_1) [custom_components.genius_lyrics] Song data: 
{'title': 'This is Bilgewater', [...]}

Worth noting that searching on Genius shows the correct song as "Top Result", but the incorrect song as the first "Lyric match":
image

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.