Skip to content

Commit

Permalink
bumped to version 12.1, fixed renaming of 'duration' to 'trackCount'
Browse files Browse the repository at this point in the history
  • Loading branch information
KoljaWindeler committed Dec 17, 2020
1 parent dc7bb41 commit c4fb9de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/ytube_music_player/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"documentation": "https://github.com/KoljaWindeler/ytube_music_player",
"config_flow": true,
"requirements": [
"ytmusicapi>=0.11.0",
"ytmusicapi==0.12.1",
"pytube",
"integrationhelper"
],
Expand Down
14 changes: 9 additions & 5 deletions custom_components/ytube_music_player/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pytube import request
from pytube import extract
from pytube.cipher import Cipher
from ytmusicapi import YTMusic
import ytmusicapi



Expand Down Expand Up @@ -78,13 +78,15 @@ def __init__(self, hass, config):
if(self._brand_id!=""):
_LOGGER.debug("using brand ID: "+self._brand_id)
try:
self._api = YTMusic(config.get(CONF_HEADER_PATH, default_header_file),self._brand_id)
self._api = ytmusicapi.YTMusic(config.get(CONF_HEADER_PATH, default_header_file),self._brand_id)
_LOGGER.debug("\tYouTube Api version: "+str(ytmusicapi.__version__))
except:
self._api = None
self.exc(resp="ytmusicapi")
else:
try:
self._api = YTMusic(config.get(CONF_HEADER_PATH, default_header_file))
self._api = ytmusicapi.YTMusic(config.get(CONF_HEADER_PATH, default_header_file))
_LOGGER.debug("\tYouTube Api version: "+str(ytmusicapi.__version__))
except:
self._api = None
self.exc(resp="ytmusicapi")
Expand Down Expand Up @@ -355,7 +357,6 @@ def _sync_player(self, entity_id=None, old_state=None, new_state=None):
self.schedule_update_ha_state()

def _ytubemusic_play_media(self, event):

_speak = event.data.get('speakers')
_source = event.data.get('source')
_media = event.data.get('name')
Expand Down Expand Up @@ -423,7 +424,10 @@ def _update_playlists(self, now=None):
if not('count' in playlist):
try:
extra_info = self._api.get_playlist(playlistId=playlist['playlistId'])
self._playlists[idx]['count'] = max(25,int(''.join([x for x in extra_info['duration'] if x.isdigit()])))
if('trackCount' in extra_info):
self._playlists[idx]['count'] = int(extra_info['trackCount'])
else:
self._playlists[idx]['count'] = 25
except:
if('playlistId' in playlist):
_LOGGER.debug("Failed to get_playlist count for playlist ID '"+str(playlist['playlistId'])+"' setting it to 25")
Expand Down

0 comments on commit c4fb9de

Please sign in to comment.