コード例 #1
0
def check_for_ads(spotify: Wasp):
    try:
        track = spotify.get_track()
        state = spotify.get_state()
    except Exception:
        # spotify was closed
        exit()

    if state['state'] != 'playing':
        time.sleep(5)
        return

    duration_sec = track['duration'] / 1000

    if duration_sec < 40 and track['popularity'] == 0:
        # this check handles also video ads
        previous_volume = state['volume']
        mute_duration = math.floor(duration_sec - state['position']) + 0.5
        if mute_duration > 0:
            # weird bug occured that sometimes duration was negative
            pync.notify(
                f'Ad detected, muting spotify for {mute_duration} seconds',
                title='Spotify ads muter')
            spotify.set_volume(0)
            time.sleep(mute_duration)
            spotify.set_volume(previous_volume)
    else:
        time.sleep(1)
コード例 #2
0
ファイル: test_wasp.py プロジェクト: danthelion/wasp
def main():
    if WaspLib.check_if_spotify_is_running():
        exit('Close Spotify before running the tests!')

    wasp = Wasp()

    test_open_spotify(wasp=wasp)
    test_start_track_from_uri(
        wasp=wasp, spotify_uri='spotify:track:4uLU6hMCjMI75M1A2tKUQC')
    set_volume_to(wasp=wasp, volume=50)
    jump_to_second(wasp=wasp, target=40)
    mute(wasp=wasp)
    unmute(wasp=wasp)
コード例 #3
0
ファイル: test_wasp.py プロジェクト: danthelion/wasp
def test_open_spotify(wasp: Wasp) -> None:
    wasp.start_spotify()
    sleep(3)
    assert WaspLib.check_if_spotify_is_running()
コード例 #4
0
ファイル: test_wasp.py プロジェクト: danthelion/wasp
def jump_to_second(wasp: Wasp, target: int) -> None:
    wasp.jump_to(jump_to_second=target)
    assert wasp.get_state()['position'] == 40
コード例 #5
0
ファイル: test_wasp.py プロジェクト: danthelion/wasp
def unmute(wasp: Wasp) -> None:
    wasp.unmute()
    state = wasp.get_state()
    assert state['volume'] == 48
コード例 #6
0
ファイル: test_wasp.py プロジェクト: danthelion/wasp
def set_volume_to(wasp: Wasp, volume: int) -> None:
    wasp.set_volume(volume=volume)
    state = wasp.get_state()
    assert state['volume'] == 49
コード例 #7
0
ファイル: test_wasp.py プロジェクト: danthelion/wasp
def test_start_track_from_uri(wasp: Wasp, spotify_uri: str) -> None:
    wasp.play_track(spotify_uri=spotify_uri)
    track = wasp.get_track()
    sleep(2)
    assert track['artist'] == 'Rick Astley'
コード例 #8
0
ファイル: cool_lock_macos.py プロジェクト: w0land/dotfiles
#!/usr/bin/env python3

from subprocess import call
from wasp_spotify_bindings.core import Wasp
from time import sleep
import Quartz

spotify_state=Wasp.get_state()

status_ = spotify_state["state"]

if status_ == "playing": 
    Wasp.pause()

call(["m", "lock"])

d = Quartz.CGSessionCopyCurrentDictionary()
while d and d.get("CGSSessionScreenIsLocked", 0) == 1: 
    sleep(1)
    d = Quartz.CGSessionCopyCurrentDictionary()

if status_ == "playing": 
    Wasp.play()
コード例 #9
0
        exit()

    if state['state'] != 'playing':
        time.sleep(5)
        return

    duration_sec = track['duration'] / 1000

    if duration_sec < 40 and track['popularity'] == 0:
        # this check handles also video ads
        previous_volume = state['volume']
        mute_duration = math.floor(duration_sec - state['position']) + 0.5
        if mute_duration > 0:
            # weird bug occured that sometimes duration was negative
            pync.notify(
                f'Ad detected, muting spotify for {mute_duration} seconds',
                title='Spotify ads muter')
            spotify.set_volume(0)
            time.sleep(mute_duration)
            spotify.set_volume(previous_volume)
    else:
        time.sleep(1)


if __name__ == '__main__':
    spotify = Wasp()
    spotify.start_spotify()

    while True:
        check_for_ads(spotify)