Esempio n. 1
0
def rate(track_id):
    rating = [
        utils.translate(30027),  # Thumbs up
        utils.translate(30028),  # No Thumbs
        utils.translate(30029),  # Thumbs down
    ]

    dialog = xbmcgui.Dialog()
    selection = dialog.select(utils.translate(30041), rating, 0)

    if selection == -1:
        return

    song = GMUSIC.get_track_info(track_id)

    if not song:
        return

    if selection == 0:
        GMUSIC.rate_songs(song, 5)

    elif selection == 1:
        GMUSIC.rate_songs(song, 0)

    elif selection == 2:
        GMUSIC.rate_songs(song, 1)

    utils.notify(utils.translate(30099), "")
Esempio n. 2
0
def station(station_id=None,
            station_name=None,
            artist_id=None,
            album_id=None,
            track_id=None,
            genre_id=None,
            curated_station_id=None,
            playlist_token=None):

    if not station_id:
        station_id = GMUSIC.create_station(
            name=station_name,
            artist_id=artist_id,
            album_id=album_id,
            track_id=track_id,
            genre_id=genre_id,
            curated_station_id=curated_station_id,
            playlist_token=playlist_token)

        if not station_id:
            utils.notify(utils.translate(30050), utils.translate(30051))
            return

    tracks = GMUSIC.get_station_tracks(station_id=station_id, num_tracks=25)

    items = listing.build_song_listitems(tracks=tracks, station_id=station_id)
    listing.list_songs(items)
Esempio n. 3
0
def unfollow(network, slug, show_name=''):
    aa = addict.AudioAddict.get(PROFILE_DIR, network)

    with utils.busy_dialog():
        aa.unfollow_show(slug)
        utils.notify(utils.translate(30337).format(show_name))

    xbmc.executebuiltin('Container.Refresh')
Esempio n. 4
0
def unfavorite(network, channel, channel_name=''):
    aa = addict.AudioAddict.get(PROFILE_DIR, network)

    with utils.busy_dialog():
        aa.remove_favorite(channel)
        utils.notify(utils.translate(30329).format(channel_name))

    xbmc.executebuiltin('Container.Refresh')
    def _make_call(self, protocol, *args, **kwargs):
        try:
            return super(GMusic, self)._make_call(protocol, *args, **kwargs)

        except:
            utils.notify(utils.translate(30050), utils.translate(30051))
            utils.log(traceback.format_exc(), lvl=xbmc.LOGERROR)
            return None
Esempio n. 6
0
def logout():
    for network in addict.NETWORKS.keys():
        addict.AudioAddict.get(PROFILE_DIR, network).logout()

    utils.clear_cache()

    ADDON.setSetting('aa.email', '')
    utils.notify(utils.translate(30306))
    sys.exit(0)
Esempio n. 7
0
def my_library_update():
    utils.notify(utils.translate(30030), utils.translate(30043))

    GMUSIC.get_my_library_songs(from_cache=False)
    GMUSIC.get_my_library_artists(from_cache=False)
    GMUSIC.get_my_library_albums(from_cache=False)

    utils.notify(utils.translate(30030), utils.translate(30044))

    xbmc.executebuiltin('Container.Refresh')
Esempio n. 8
0
def browse_stations_station(station_name, curated_station_id):
    station_id = GMUSIC.create_station(
        name=station_name, curated_station_id=curated_station_id)

    if not station_id:
        utils.notify(utils.translate(30050), utils.translate(30051))
        return

    items = listing.build_song_listitems(
        GMUSIC.get_station_tracks(station_id=station_id, num_tracks=25))
    listing.list_songs(items)
    def login(self):
        # Set Kodis locale to super class
        locale_code = xbmc.getLanguage(xbmc.ISO_639_1)
        locale_code = locale.normalize(locale_code).split('.')[0]
        if not locale_code:
            locale_code = 'en_US'

        self.locale = locale_code

        if self._is_logged_in and not self._should_test_login():
            return True

        username = ADDON.getSetting('username')
        password = ADDON.getSetting('password')
        device_id = ADDON.getSetting('device_id')
        authtoken = ADDON.getSetting('authtoken')

        if authtoken:
            self.android_id = device_id
            self.session._authtoken = authtoken
            self.session.is_authenticated = True

            ADDON.setSetting('last_login_check', str(int(time.time())))
            try:
                # Send a test request to ensure our authtoken
                # is still valide and working
                self.get_registered_devices()
                self._is_logged_in = True
                return True

            except:
                # Faild with the test-request so we set
                # "is_authenticated=False" and go through the login-process
                # again to get a new "authtoken"
                self.session.is_authenticated = False

        if device_id:
            success = super(GMusic, self).login(username, password, device_id,
                                                self.locale)

            if success:
                ADDON.setSetting('authtoken', self.session._authtoken)
                self._is_logged_in = True
                return True

        utils.notify(utils.translate(30048), '')
        ADDON.setSetting('is_setup', 'false')

        # Prevent further addon execution in case we failed with the login-process
        raise SystemExit
Esempio n. 10
0
def setup(notice=True, update_cache=False):
    for network in addict.NETWORKS.keys():
        addict.AudioAddict.get(PROFILE_DIR, network).logout()

    aa = addict.AudioAddict.get(PROFILE_DIR, TEST_LOGIN_NETWORK)

    ADDON.setSetting('aa.email', '')

    if notice:
        xbmcgui.Dialog().textviewer(utils.translate(30300),
                                    utils.translate(30301))

    k = xbmc.Keyboard(aa.member.get('email', ''), utils.translate(30319))
    k.doModal()
    if not k.isConfirmed():
        return False
    username = k.getText()

    k = xbmc.Keyboard('', utils.translate(30320), True)
    k.doModal()
    if not k.isConfirmed():
        return False
    password = k.getText()

    if not aa.login(username, password):
        if xbmcgui.Dialog().yesno(utils.translate(30309),
                                  utils.translate(30310)):
            return setup(False, update_cache)
        return False

    ADDON.setSetting('aa.email', username)

    utils.notify(utils.translate(30304), utils.translate(30305))
    if not aa.is_premium:
        utils.go_premium()
        ADDON.setSettingInt('addon.last_premium_prompt', int(time.time()))

    if update_cache:
        update_networks()

    return True
Esempio n. 11
0
def clear_cache():
    utils.clear_cache()
    utils.notify(utils.translate(30315))
    sys.exit(0)
Esempio n. 12
0
def clear_search_history():
    history_file = os.path.join(_CACHE_DIR, 'search_history.json')
    if os.path.exists(history_file):
        os.remove(history_file)

    utils.notify(utils.translate(30095), '', display_time=1000)
Esempio n. 13
0
def clear_cache():
    if os.path.exists(_CACHE_DIR):
        shutil.rmtree(_CACHE_DIR)

    utils.notify(utils.translate(30094), '', display_time=1000)
Esempio n. 14
0
def setup(force=False):
    is_setup = True if ADDON.getSetting('is_setup') == 'true' else False

    if is_setup and not force:
        return True

    dialog = xbmcgui.Dialog()

    username = dialog.input(utils.translate(30075),
                            type=xbmcgui.INPUT_ALPHANUM)
    if not username:
        return False

    # If 2-Factor Authentication is used
    is_two_factor = dialog.yesno(utils.translate(30071),
                                 utils.translate(30072))
    if is_two_factor:
        if not dialog.ok(utils.translate(30071), utils.translate(30073),
                         utils.translate(30074)):
            return False

    password = dialog.input(utils.translate(30076),
                            type=xbmcgui.INPUT_ALPHANUM,
                            option=xbmcgui.ALPHANUM_HIDE_INPUT)
    if not password:
        return False

    device_id = None
    if is_two_factor:
        # If Android Device available
        if dialog.yesno(utils.translate(30077), utils.translate(30078)):
            if not dialog.ok(utils.translate(30079), utils.translate(30081)):
                return False

            device_id = dialog.input(utils.translate(30084),
                                     type=xbmcgui.INPUT_ALPHANUM)
            if not device_id:
                return False
        else:
            # If using MAC-Address
            if dialog.yesno(utils.translate(30082), utils.translate(30083)):
                device_id = gmusicapi.Mobileclient.FROM_MAC_ADDRESS
            else:
                return False
    else:
        web = gmusicapi.Webclient()
        if not web.login(username, password):
            # If re-run setup due to login failed
            if dialog.yesno(utils.translate(30048), utils.translate(30085)):
                return setup(force=True)
            else:
                return False

        try:
            devices = web.get_registered_devices()
            if not devices:
                raise

            dev_list = []
            for dev in devices:
                # Not an Android Device so we skip as streaming would not work
                if dev['deviceType'] != 2:
                    continue

                if 'id' in dev and dev['id']:
                    dev_list.append('%s - %s' % (
                        dev.get('carrier', '').strip(' '),
                        dev.get('model', '').strip(' '),
                    ))
                    dev_list = sorted(dev_list)

            if len(dev_list) <= 0:
                raise

            elif len(dev_list) == 1:
                device_id = devices[0]['id'].lstrip('0x')

            else:
                selection = dialog.select(utils.translate(30042), dev_list, 0)

                if selection >= 0:
                    device_id = devices[selection]['id'].lstrip('0x')

                else:
                    return False

        except Exception:
            # If use MAC-Address instead due to no devices found
            if not dialog.yesno(utils.translate(30079),
                                utils.translate(30097)):
                return False

            device_id = gmusicapi.Mobileclient.FROM_MAC_ADDRESS

    # Test login
    mobile = gmusicapi.Mobileclient()
    if mobile.login(username, password, device_id):

        # Test if this is an all-access account
        if not mobile.get_all_stations():
            dialog.ok(utils.translate(30091), utils.translate(30092))
            return False

        ADDON.setSetting('username', username)
        ADDON.setSetting('password', password)
        ADDON.setSetting('authtoken', mobile.session._authtoken)

        if device_id == gmusicapi.Mobileclient.FROM_MAC_ADDRESS:
            mac_address = ''.join(re.findall('..', '%012x' % uuid.getnode()))
            ADDON.setSetting('device_id', mac_address)
        else:
            ADDON.setSetting('device_id', device_id)

        ADDON.setSetting('is_setup', 'true')

        utils.notify(utils.translate(30086), utils.translate(30087))

        return True

    else:
        # If re-run setup
        if dialog.yesno(utils.translate(30048), utils.translate(30085)):
            return setup(force=True)

        return False
Esempio n. 15
0
def monitor_live(skip_shows=None):
    if not skip_shows:
        skip_shows = []

    now = addict.datetime_now()
    addon = xbmcaddon.Addon()

    for network in addict.NETWORKS.keys():
        aa = addict.AudioAddict.get(PROFILE_DIR, network)

        if not aa.is_active or not aa.network['has_shows']:
            continue

        followed = [s.get('slug') for s in aa.get_shows_followed()]

        shows = aa.get_live_shows()
        live_show_ids = [s.get('id') for s in shows]

        # Remove shows which are not live anymore
        skip_shows = [i for i in skip_shows if i in live_show_ids]

        for show in shows:
            if show.get('id') in skip_shows:
                continue

            end_at = addict.parse_datetime(show.get('end_at'))
            if end_at < now:
                continue

            skip_shows.append(show.get('id'))

            _show = show.get('show')
            if _show.get('slug') in followed and addon.getSettingBool(
                    'addon.notify_live'):
                utils.notify('[B]{}[/B] is live!'.format(_show.get('name')))

            if addon.getSettingBool('addon.tune_in_live'):
                filename = xbmc.getInfoLabel('Player.Filenameandpath')
                if not filename:
                    continue

                playing = utils.get_playing()
                if not playing:
                    continue

                chan = _show.get('channels', [])[0]
                if (playing['network'] != network
                        or playing['channel'] != chan.get('key')):
                    utils.logd(
                        'Different network/channel playing, not tuning in.')
                    continue

                if playing['live']:
                    utils.logd('Live stream already playing.')
                    break

                time_left = (end_at - now).seconds
                if time_left < 2:
                    utils.log('Less than 2 minutes left, not tuning in.')
                    break

                utils.log('Tuning in to live stream...')
                xbmc.executebuiltin('RunPlugin({})'.format(
                    utils.build_path('play',
                                     network,
                                     playing['channel'],
                                     live=True)))

    return skip_shows