Skip to content

Instantly share code, notes, and snippets.

@Self-Perfection
Last active June 15, 2020 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Self-Perfection/104dc961369188a0dafcc893c8402d49 to your computer and use it in GitHub Desktop.
Save Self-Perfection/104dc961369188a0dafcc893c8402d49 to your computer and use it in GitHub Desktop.
Couple of scripts to skip yandex music ads while listening in browser with enabled plasma-browser-integration
#!/usr/bin/python
from pydbus import SessionBus
from gi.repository import GLib
import subprocess
bus = SessionBus()
def event_handler(a_str, b_dict, c_list):
if 'Metadata' not in b_dict:
return
if b_dict['Metadata'].get('xesam:title') != 'Реклама':
return
#Used to check for b_dict.get('CanSeek') bool, but after update there is no such field
if b_dict.get('PlaybackStatus') != 'Playing':
return
length_mu_s=b_dict['Metadata']['mpris:length']
subprocess.run(['notify-send','Яндекс.Музыка','Пропускаем рекламу'])
subprocess.run(['playerctl', 'position', str((length_mu_s - 400000)/1000000)])
# Кажется нельзя создавать, пока не зарегистрирован такой [канал]
proxy = bus.get('org.mpris.MediaPlayer2.plasma-browser-integration', '/org/mpris/MediaPlayer2')
proxy.onPropertiesChanged = event_handler
loop = GLib.MainLoop()
loop.run()
#!/bin/sh
while sleep 2; do
if [ "$(playerctl metadata xesam:title)" = 'Реклама' ]; then
notify-send 'Яндекс.Музыка' 'Пропускаем рекламу'
DURATION=$(playerctl metadata mpris:length)
playerctl position $((DURATION/1000000-1))
sleep 5m
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment