Ändra tidszon från terminalen
Kör följande kommando och välj passande tidszon :)
sudo dpkg-reconfigure tzdata
Detta är en blogg som jag skriver till mig själv för att komma ihåg olika saker... Det har börjat bli lite väl många post-it lappar på skrivbordet ;)
Framförallt kommer det att handla om olika saker gällande Ubuntu/kubuntu. Just nu kör jag Kubuntu 11.10 och är jätte nöjd!
sudo apt-get install python3-dbus
# This script is NOT supported by or made by Spotify.
# Spotify are NOT responsible for anything that goes wrong.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# --------------------------------------
#
# Author: Jonas Lindberg
# Contact: badomen02 gmail
# Created: March 10, 2013
#
# Purpose: To show pop-up notification about current track when track changes in Spotify.
# Usage: Start Spotify, make sure 'handle_notification-spotify.py' is in the same folder as this script, then start this script. This script will self exit when spotify exits or if you press ctrl+c.
# Dependencies: python3-dbus, sudo apt-get install python3-dbus to install it.
# Troubleshooting: The Printed output will give you a hint where the problem lies. Also test this ./handle_notification-spotify.py "Artis" "Album" "Title". Hopefully it will show a simple Notification or an error that will tell you something :).
#
#
# This script is NOT supported by or made by Spotify.
# Spotify are NOT responsible for anything that goes wrong.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY.
#
# --------------------------------------
from gi.repository import GLib
import subprocess
from subprocess import Popen, PIPE, STDOUT
import sys
import dbus
from dbus.exceptions import DBusException
from dbus.mainloop.glib import DBusGMainLoop
import re
def handle_properties_changed(interface, changed_props, invalidated_props):
"""Handle track changes."""
# changed_props is a dict, in it there is a key that is named 'Metadata' and is containing another dictionary as Value. An empty dict will be created if 'Metadata' does not exist.
metadata =changed_props.get("Metadata", {})
# if pause is pressed then metadata will be an empty dict, i.e. False.
if(bool(metadata)):
sArtist = metadata['xesam:artist'][0]
sAlbum = metadata['xesam:album']
sTitle = metadata['xesam:title']
#Check if the track has an artUrl
try:
sIcon = str(metadata['mpris:artUrl'])
except:
sIcon = ""
# Just make the pop-up notification if a new track is playing.
if (bool(re.search(r"(?i)spotify|http:", sArtist)))or (bool(re.search(r"(?i)spotify|http:", sTitle))) or (bool(re.search(r"(?i)spotify|http:", sAlbum))) :
pass
else:
cmd = ["./handle_notification-spotify.py", sArtist, sAlbum, sTitle, sIcon]
# If I do not PIPE I get GLib-GObject-WARNING. In Python 3.3 I think DEVNULL will work instead of PIPE.
try:
subprocess.Popen(cmd , shell=False, stderr=subprocess.PIPE)
print("Notification sent")
except OSError as e:
print("In line 57: ",e)
print("Could not send notification. Make sure the handle_notification-spotify.py is in the same directory as this script.")
loop.quit()
def isSpotify():
"""This checks if Spotify service is running. Its name is 'org.mpris.MediaPlayer2.spotify' """
player = bus_Session.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
iface = dbus.Interface(player, 'org.freedesktop.DBus')
l=list(iface.ListNames())
running = False
for name in l:
name=str(name)
if name=="org.mpris.MediaPlayer2.spotify":
running=True
if bool(running):
pass
else:
print("Spotify is NOT running.")
# Quit the main loop if it is running.
if bool(loop.is_running()):
loop.quit()
return running
def connectToSpotify():
if bool(isSpotify()):
print("Spotify is running")
props_changed_listener()
return True
else:
sys.exit()
def props_changed_listener():
"""Hook up callback to PropertiesChanged event."""
print("Trying to connect with spotify ")
try:
spotify = bus_Session.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
spotify.connect_to_signal("PropertiesChanged", handle_properties_changed)
print("Connection Succesful")
except:
print("Connection Faild.")
if __name__ == '__main__':
loop = GLib.MainLoop(None, False)
dbus_loop = DBusGMainLoop(set_as_default=True)
bus_Session = dbus.SessionBus(mainloop=dbus_loop)
#This is making the connection to spotify or exit if it is not running.
connectToSpotify()
#checks every 7 sec if spotify is running, so that if you quit spotify this script will exit in less then 7 sec.
GLib.timeout_add_seconds(7,isSpotify)
loop.run()
print("Script Exit")
handle_notification-spotify.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# --------------------------------------
#
# Author: Jonas Lindberg
# Contact: badomen02 gmail
# Created: March 10, 2013
#
# Purpose: To show pop-up notification about current track when track changes in Spotify.
# Usage: Start Spotify, then run the script 'main_handle-spotify.py' it will call This script with the argumets "Artis" "Album" "Title" "artUrl". The script will self exit in 8 seconds.
#
# Dependencies: python3-dbus, sudo apt-get install python3-dbus to install it.
# Troubleshooting: Test this ./handle_notification-spotify.py "Artis" "Album" "Title". Hopefully it will show a simple Notification or an error that will tell you something :).
#
#
# This script is NOT supported or created by Spotify.
# Spotify is NOT responsible for anything that goes wrong.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY.
#
# --------------------------------------
from gi.repository import GLib, Gio
from gi.repository import Notify
from gi.repository.GdkPixbuf import Pixbuf
import sys
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import re
def next_cb(n, action, data):
try:
spotify = session_bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
iface = dbus.Interface(spotify, 'org.mpris.MediaPlayer2.Player')
iface.Next()
except:
#print("Spotify is not running")
loop.quit()
def closed_cb(user_data):
Notify.uninit()
loop.quit()
if __name__ == '__main__':
artist = sys.argv[1]
album = sys.argv[2]
title = sys.argv[3]
#Checks if the artUrl is sent. Sets the icon to a Pixbuf or None.
if (len(sys.argv)==5 and bool(sys.argv[4])):
artUrl = str(sys.argv[4])
file = Gio.File.new_for_uri(artUrl)
icon =Pixbuf.new_from_stream(file.read(None), None)
else:
icon=None
sLabel = artist
sBody='Album: ' +album+'\n'+ 'Track: ' + title
sActionlabel = "Next"
loop = GLib.MainLoop(None, False)
dbus_loop = DBusGMainLoop(set_as_default=True)
session_bus = dbus.SessionBus(mainloop=dbus_loop)
# Any name will do.
Notify.init("Played on Spotify")
n = Notify.Notification.new(sLabel, sBody, None)
try:
n.set_image_from_pixbuf(icon)
except TypeError as e:
#print("No Art Url, Spotify can't find the cover.",e)
pass
n.set_urgency(Notify.Urgency.CRITICAL)
n.connect("closed", closed_cb)
# Uncomment the next line to get a "Next" button. It only works while the notification is displayed, 7 seconds.
#n.add_action("next", sActionlabel, next_cb, None, None)
n.set_timeout(7000)
loop=GLib.MainLoop()
Notify.Notification.show(n)
loop.run()
#!/bin/bash
# --------------------------------------
#
# Author: Jonas Lindberg
# Contact: badomen02 gmail
# Created: February 17, 2013
#
# Purpose: Pop up notification of what Spotify is playing.
# Usage: Start Spotify then start this script. This script will self exit when spotify exits.
# Dependencies: libnotify-bin, sudo apt-get install libnotify-bin to install it.
# Troubleshooting: Test this command notify-send "Artist" "Album" in a terminal.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY.
#
# --------------------------------------
echo "Started"
title_playing=""
# It will run as long spotify is runing.
while [ "$(pidof spotify)" ];do
title_compare="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' 2>/dev/null |egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$)"
# Just make a notify when a new song is played
if [ "$title_playing" != "$title_compare" ];then
album="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' 2>/dev/null |egrep -A 2 "album"|egrep -v "album"|egrep -v "array"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$)"
artist="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' 2>/dev/null |egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1|egrep -v ^$)"
title_playing="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' 2>/dev/null |egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$)"
# Checks that the artist is not empty and that the title doesn't start with Spotify.
if [ -n "$artist" ]; then
if [[ $title_playing != Spotify* ]]; then
notify-send "$artist" "Album: $album
Title: $title_playing"
fi
fi
fi
# How often in seconds it will update
sleep 5
done
echo "Ended"
.import QtQuick.LocalStorage 2.0 as LS db = LS.LocalStorage.openDatabaseSync("your_db_name", "db_Version_Nr", "db_description", estimated_size_of_db_in_bytes);