Exemple #1
0
def stopped(offset):
    kodi = Kodi(config, context)
    playlist_queue = music.MusicPlayer(kodi)

    playlist_queue.current_offset = offset
    playlist_queue.save_to_mongo()
    log.info('Streaming stopped')
Exemple #2
0
def alexa_stream_audio_playlist(kodi, AudioPlaylist, shuffle=False):
  heard_search = str(AudioPlaylist).lower().translate(None, string.punctuation)

  if shuffle:
    op = render_template('shuffling_empty').encode("utf-8")
  else:
    op = render_template('playing').encode("utf-8")

  card_title = render_template('action_audio_playlist', action=op).encode("utf-8")
  log.info(card_title)

  playlist = kodi.FindAudioPlaylist(heard_search)
  if playlist:
    songs = kodi.GetPlaylistItems(playlist)['result']['files']

    songs_array = []

    for song in songs:
      songs_array.append(kodi.PrepareDownload(song['file']))

    if len(songs_array) > 0:
      if shuffle:
        random.shuffle(songs_array)
      playlist_queue = music.MusicPlayer(kodi, songs_array)

      response_text = render_template('playing_playlist', action=op, playlist_name=heard_search).encode("utf-8")
      audio('').clear_queue(stop=True)
      return audio(response_text).play(songs_array[0])
    else:
      response_text = render_template('could_not_find_playlist', heard_name=heard_search).encode("utf-8")
  else:
    response_text = render_template('could_not_find_playlist', heard_name=heard_search).encode("utf-8")

  return statement(response_text).simple_card(card_title, response_text)
Exemple #3
0
def alexa_stream_party_play(kodi):
    card_title = render_template('streaming_party_mode').encode("utf-8")
    log.info(card_title)

    response_text = render_template('streaming_party').encode("utf-8")

    songs = kodi.GetSongsPath()

    if 'result' in songs and 'songs' in songs['result']:
        songs_array = []

        for song in songs['result']['songs']:
            songs_array.append(kodi.PrepareDownload(song['file']))

        if len(songs_array) > 0:
            random.shuffle(songs_array)
            playlist_queue = music.MusicPlayer(kodi, songs_array)

            response_text = render_template('streaming_party').encode("utf-8")
            audio('').clear_queue(stop=True)
            return audio(response_text).play(songs_array[0])
        else:
            response_text = render_template('error_parsing_results').encode(
                "utf-8")
    else:
        response_text = render_template('error_parsing_results').encode(
            "utf-8")

    return statement(response_text).simple_card(card_title, response_text)
Exemple #4
0
def alexa_stream_restart_track(kodi):
    playlist_queue = music.MusicPlayer(kodi)

    if playlist_queue.current_item:
        return audio('').play(playlist_queue.current_item, offset=0)
    else:
        response_text = render_template('no_current_song').encode("utf-8")
        return audio(response_text)
Exemple #5
0
def alexa_stream_this(kodi):
    card_title = render_template('streaming_current_playlist').encode("utf-8")
    log.info(card_title)

    current_item = kodi.GetActivePlayItem()

    if current_item and current_item['type'] == 'song':
        play_status = kodi.GetPlayerStatus()
        playlist_items = []
        final_playlist = []
        songs_array = []

        offset = 0
        current_time = play_status['time']
        if len(current_time) == 5:
            x = time.strptime(current_time, '%M:%S')
        else:
            x = time.strptime(current_time, '%H:%M:%S')
        offset = int(
            datetime.timedelta(hours=x.tm_hour,
                               minutes=x.tm_min,
                               seconds=x.tm_sec).total_seconds()) * 1000

        playlist_result = kodi.GetAudioPlaylistItems()

        if 'items' in playlist_result['result']:
            playlist_items = playlist_result['result']['items']

        if len(playlist_items) > 0:
            current_playing = next(
                (x for x in playlist_items if x['id'] == current_item['id']),
                None)
            current_index = playlist_items.index(current_playing)
            final_playlist = playlist_items[current_index:]

        if len(final_playlist) > 0:
            for song in final_playlist:
                song_detail = kodi.GetSongIdPath(song['id'])
                song_detail = song_detail['result']['songdetails']
                songs_array.append(kodi.PrepareDownload(song_detail['file']))

        if len(songs_array) > 0:
            playlist_queue = music.MusicPlayer(kodi, songs_array)

            kodi.PlayerStop()
            kodi.ClearAudioPlaylist()

            response_text = render_template('transferring_stream').encode(
                "utf-8")
            audio('').clear_queue(stop=True)
            return audio(response_text).play(songs_array[0])

    else:
        response_text = render_template('nothing_currently_playing')

    return statement(response_text).simple_card(card_title, response_text)
Exemple #6
0
def alexa_stream_prev(kodi):
    playlist_queue = music.MusicPlayer(kodi)

    if playlist_queue.prev_item:
        playlist_queue.prev_song()
        # current_item is now set as the previous item from the playlist
        return audio('').play(playlist_queue.current_item)
    else:
        response_text = render_template('no_songs_history').encode("utf-8")
        return audio(response_text)
Exemple #7
0
def alexa_stream_skip(kodi):
    playlist_queue = music.MusicPlayer(kodi)

    if playlist_queue.next_item:
        playlist_queue.skip_song()
        # current_item is now set as the next item from the playlist
        return audio('').play(playlist_queue.current_item)
    else:
        response_text = render_template('no_more_songs').encode("utf-8")
        return audio(response_text)
Exemple #8
0
def alexa_stream_artist(kodi, Artist):
    heard_artist = str(Artist).lower().translate(None, string.punctuation)

    card_title = render_template('stream_artist',
                                 heard_artist=heard_artist).encode("utf-8")
    log.info(card_title)

    artists = kodi.GetMusicArtists()
    if 'result' in artists and 'artists' in artists['result']:
        artists_list = artists['result']['artists']
        located = kodi.matchHeard(heard_artist, artists_list, 'artist')

        if len(located):
            located = located[0]
            songs_result = kodi.GetArtistSongsPath(located['artistid'])
            songs = songs_result['result']['songs']

            songs_array = []

            for song in songs:
                songs_array.append(kodi.PrepareDownload(song['file']))

            if len(songs_array) > 0:
                random.shuffle(songs_array)
                playlist_queue = music.MusicPlayer(kodi, songs_array)

                response_text = render_template(
                    'streaming', heard_name=heard_artist).encode("utf-8")
                audio('').clear_queue(stop=True)
                return audio(response_text).play(songs_array[0])
            else:
                response_text = render_template(
                    'could_not_find', heard_name=heard_artist).encode("utf-8")
        else:
            response_text = render_template(
                'could_not_find', heard_name=heard_artist).encode("utf-8")
    else:
        response_text = render_template(
            'could_not_find', heard_name=heard_artist).encode("utf-8")

    return statement(response_text).simple_card(card_title, response_text)
Exemple #9
0
def title():
    """Display the title screen, replace with black when user
    hits a key.  Also plays title music.
    """
    box = globalvars.images["misctitle"]
    box_rect = box.get_rect()
    box_rect.topleft = (0, 0)
    globalvars.window.blit(box, box_rect)
    pygame.display.update()
    song = music.MusicPlayer("title.mp3")
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == KEYDOWN:
                blackbox = pygame.Surface(
                    (CENTERWIDTH + BORDERWIDTH * 2, CENTERHEIGHT))
                blackbox.fill(BLACK)
                globalvars.window.blit(blackbox, (0, 0))
                return
        globalvars.clock.tick(FPS)
Exemple #10
0
def alexa_stream_recently_added_songs(kodi):
  card_title = render_template('streaming_recent_songs').encode("utf-8")
  response_text = render_template('no_recent_songs').encode("utf-8")
  log.info(card_title)

  songs_result = kodi.GetRecentlyAddedSongsPath()
  if songs_result:
    songs = songs_result['result']['songs']

    songs_array = []

    for song in songs:
      songs_array.append(kodi.PrepareDownload(song['file']))

    if len(songs_array) > 0:
      random.shuffle(songs_array)
      playlist_queue = music.MusicPlayer(kodi, songs_array)

      response_text = render_template('streaming_recent_songs').encode("utf-8")
      audio('').clear_queue(stop=True)
      return audio(response_text).play(songs_array[0])

  return statement(response_text).simple_card(card_title, response_text)
Exemple #11
0
def play_back_finished():
    kodi = Kodi(config, context)
    playlist_queue = music.MusicPlayer(kodi)

    if playlist_queue.next_item:
        playlist_queue.skip_song()
Exemple #12
0
def nearly_finished():
    kodi = Kodi(config, context)
    playlist_queue = music.MusicPlayer(kodi)

    if playlist_queue.next_item:
        return audio().enqueue(playlist_queue.next_item)
Exemple #13
0
def alexa_stream_album_or_song(kodi, Song, Album, Artist):
    if Song:
        heard_search = str(Song).lower().translate(None, string.punctuation)
    elif Album:
        heard_search = str(Album).lower().translate(None, string.punctuation)
    if Artist:
        heard_artist = str(Artist).lower().translate(None, string.punctuation)

    card_title = render_template('streaming_album_or_song').encode("utf-8")
    log.info(card_title)

    artists = kodi.GetMusicArtists()
    if 'result' in artists and 'artists' in artists['result']:
        artists_list = artists['result']['artists']
        located = kodi.matchHeard(heard_artist, artists_list, 'artist')

        if len(located):
            located = located[0]
            albums = kodi.GetArtistAlbums(located['artistid'])
            if 'result' in albums and 'albums' in albums['result']:
                albums_list = albums['result']['albums']
                album_located = kodi.matchHeard(heard_search, albums_list)

                if len(album_located):
                    album_located = album_located[0]
                    songs_result = kodi.GetAlbumSongsPath(
                        album_located['albumid'])
                    songs = songs_result['result']['songs']

                    songs_array = []

                    for song in songs:
                        songs_array.append(kodi.PrepareDownload(song['file']))

                    if len(songs_array) > 0:
                        random.shuffle(songs_array)
                        playlist_queue = music.MusicPlayer(kodi, songs_array)

                        response_text = render_template(
                            'streaming_album_artist',
                            album_name=heard_search,
                            artist=heard_artist).encode("utf-8")
                        audio('').clear_queue(stop=True)
                        return audio(response_text).play(songs_array[0])
                    else:
                        response_text = render_template(
                            'could_not_find_album_artist',
                            album_name=heard_search,
                            artist=heard_artist).encode("utf-8")
                else:
                    songs = kodi.GetArtistSongs(located['artistid'])
                    if 'result' in songs and 'songs' in songs['result']:
                        songs_list = songs['result']['songs']
                        song_located = kodi.matchHeard(heard_search,
                                                       songs_list)

                        if len(song_located):
                            song_located = song_located[0]
                            songs_array = []
                            song = None

                            song_result = kodi.GetSongIdPath(
                                song_located['songid'])

                            if 'songdetails' in song_result['result']:
                                song = song_result['result']['songdetails'][
                                    'file']

                            if song:
                                songs_array.append(kodi.PrepareDownload(song))

                            if len(songs_array) > 0:
                                random.shuffle(songs_array)
                                playlist_queue = music.MusicPlayer(
                                    kodi, songs_array)

                                response_text = render_template(
                                    'streaming_song_artist',
                                    song_name=heard_search,
                                    artist=heard_artist).encode("utf-8")
                                audio('').clear_queue(stop=True)
                                return audio(response_text).play(
                                    songs_array[0])
                            else:
                                response_text = render_template(
                                    'could_not_find_song_artist',
                                    song_name=heard_search,
                                    artist=heard_artist).encode("utf-8")
                        else:
                            response_text = render_template(
                                'could_not_find_song_artist',
                                heard_name=heard_search,
                                artist=heard_artist).encode("utf-8")
                    else:
                        response_text = render_template(
                            'could_not_find_song_artist',
                            heard_name=heard_search,
                            artist=heard_artist).encode("utf-8")
            else:
                response_text = render_template(
                    'could_not_find_song_artist',
                    heard_name=heard_search,
                    artist=heard_artist).encode("utf-8")
        else:
            response_text = render_template(
                'could_not_find_song_artist',
                heard_name=heard_search,
                artist=heard_artist).encode("utf-8")
    else:
        response_text = render_template(
            'could_not_find', heard_name=heard_artist).encode("utf-8")

    return statement(response_text).simple_card(card_title, response_text)
Exemple #14
0
    def read(self, filename):
        """Read area data from a data file into an Area object"""
        # Open the area file
        fin = open(filename, 'r')

        # Read each object from the file
        for line in fin.readlines():
            line = line.split(' ')

            # Get the name, coordinates, and properties of the object
            name = line[0]
            x = float(line[1])
            y = float(line[2])
            properties = ''.join(line[3:]).strip('\n')

            # Create a blank object
            obj = None

            # Audio/visual stuff
            if name == "Background":
                obj = Background(img=pyglet.image.load(properties),
                                 x=x,
                                 y=y,
                                 batch=self.batch,
                                 group=self.background)
            if name == "MusicPlayer":
                self.music = music.MusicPlayer(name=properties)
                continue

            # Heroes
            if name == "Player":
                obj = heroes.CaptainZero(x=x,
                                         y=y,
                                         batch=self.batch,
                                         group=self.foreground)

            # Objects
            if name == "Ground":
                properties = str2list(properties)
                n_horiz = int(properties[0])
                n_vert = int(properties[1])
                print(n_horiz, n_vert)

                for i in range(0, n_vert):
                    for j in range(0, n_horiz):
                        if obj != None: self.objects.append(obj)
                        obj = tiles.Ground(x=x + (32 * j),
                                           y=y + (32 * i),
                                           batch=self.batch,
                                           group=self.foreground)

            # Villains

            # Enemies
            if name == "InfinityMook":
                obj = enemies.InfinityMook(x=x,
                                           y=y,
                                           batch=self.batch,
                                           group=self.foreground)

            # NPCs

            # Items

            # UI
            if name == "Text":
                properties = str2list(properties)

                obj = ui.Text(text=properties[0],
                              size=int(properties[1]),
                              color=properties[2],
                              x=x,
                              y=y,
                              batch=self.batch,
                              group=self.foreground)
            if name == "Button":
                properties = str2list(properties)

                click_mod_func = properties[1].split('.')
                module = __import__(click_mod_func[0])
                on_click = eval("module." + click_mod_func[1])

                obj = ui.Button(img=pyglet.image.load(properties[0]),
                                x=x,
                                y=y,
                                on_click=on_click,
                                batch=self.batch,
                                group=self.foreground)

            self.objects.append(obj)