Esempio n. 1
0
    def enqueue(self) -> None:
        assert self.queued_song
        if not playback.queue.filter(id=self.queued_song.id).exists():
            # this song was already deleted, do not enqueue
            return

        metadata = self.get_metadata()

        assert metadata["external_url"]
        self.queued_song.artist = metadata["artist"]
        self.queued_song.title = metadata["title"]
        self.queued_song.duration = metadata["duration"]
        self.queued_song.internal_url = metadata["internal_url"]
        self.queued_song.external_url = metadata["external_url"]
        self.queued_song.stream_url = metadata["stream_url"]
        # make sure not to overwrite the index as it may have changed in the meantime
        self.queued_song.save(update_fields=[
            "artist",
            "title",
            "duration",
            "internal_url",
            "external_url",
            "stream_url",
        ])

        musiq.update_state()
        playback.queue_changed.set()
Esempio n. 2
0
def fetch_enqueue(provider: MusicProvider, session_key: str,
                  archive: bool) -> None:
    """Fetch and enqueue the music managed by the given provider."""
    if not provider.make_available():
        provider.remove_placeholder()
        musiq.update_state()
        return

    enqueue(provider, session_key, archive)
Esempio n. 3
0
 def _decorator(request: WSGIRequest) -> HttpResponse:
     if storage.get(
             "interactivity"
     ) != storage.Interactivity.full_control and not user_manager.has_controls(
             request.user):
         return HttpResponseForbidden()
     response = func(request)
     musiq.update_state()
     if response is not None:
         return response
     return HttpResponse()
Esempio n. 4
0
def vote(request: WSGIRequest) -> HttpResponse:
    """Modify the vote-count of the given song by the given amount.
    If a song receives too many downvotes, it is removed."""
    key_param = request.POST.get("key")
    amount_param = request.POST.get("amount")
    if key_param is None or amount_param is None:
        return HttpResponseBadRequest()
    key = int(key_param)
    amount = int(amount_param)
    if amount < -2 or amount > 2:
        return HttpResponseBadRequest()

    if storage.get("ip_checking") and not user_manager.try_vote(
            user_manager.get_client_ip(request), key, amount):
        return HttpResponseBadRequest("nice try")

    models.CurrentSong.objects.filter(queue_key=key).update(votes=F("votes") +
                                                            amount)
    try:
        current_song = models.CurrentSong.objects.get()
        if (current_song.queue_key == key
                and current_song.votes <= -storage.get(  # pylint: disable=invalid-unary-operand-type
                    "downvotes_to_kick")):
            with playback.mopidy_command() as allowed:
                if allowed:
                    PLAYER.playback.next()
    except models.CurrentSong.DoesNotExist:
        pass

    removed = playback.queue.vote(
        key,
        amount,
        -storage.get("downvotes_to_kick"),  # pylint: disable=invalid-unary-operand-type
    )
    # if we removed a song by voting, and it was added by autoplay,
    # we want it to be the new basis for autoplay
    if removed is not None:
        if not removed.manually_requested:
            playback.handle_autoplay(removed.external_url or removed.title)
        else:
            playback.handle_autoplay()
    musiq.update_state()
    return HttpResponse()
Esempio n. 5
0
 def make_available(self) -> bool:
     if not os.path.isfile(self.get_path()):
         musiq.update_state()
         # only download the file if it was not already downloaded
         return self._download()
     return True