How do I get the currently playing song in Rhythmbox using Python - python

Im using Ubuntu 12.04. I want to access Rhythymbox using Python .
This is how I've proceeded so far:
Ive gone through this site
https://live.gnome.org/RhythmboxPlugins/WritingGuide , but it gives details on how to write plugins , which Im not interested in right now. Ive gone through a few tutorials which tells me to do this.
import dbus
session_bus = dbus.SessionBus()
proxy_obj = session_bus.get_object(
'org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player')
But I am getting the following error
DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Rhythmbox was not provided by any .service files.
Could someone please point me in the right direction of what I would like to achieve?

A workaround, used by lyricsdownloader.py, is:
import subprocess
import shlex
proc = subprocess.Popen(shlex.split('rhythmbox-client --no-start --print-playing-format %tt')))
title, err = proc.communicate()
Note: This does not work with Ubuntu 11.10, which shipped without rhythmbox-client.

This might be useful. https://github.com/aliva/rhythmbox-microblogger
It is a twitter plugin for RhythmBox. So instead of twitter and Gtk, you can just take the current song.
from gi.repository import RB
RB.RhythmDBPropType.TITLE will give enum which you can use to get the title.

I think that you've encountered a bug in Rhythmbox DBus interface described on Launchpad. Tracker says that fix is committed, but possibly your version doesn't have that fix.

Related

Python break the command line, why?

I just want to launch my program written in C++ from a Python script.
I wrote the following script:
import subprocess
subprocess.call(['l:\Proj\Silium.exe', '--AddWatch c:\fff.txt'])
But to my c++ application the parameter "--AddWatch c:\fff.txt" arrives without hyphens - it arrives as "AddWatch c:\fff.txt". So my program doesn't work.
Why does this happen, and how can I fix it?
UPD: thx for comments - yours answer helps!
I explain the issue and the solution.
I need to launch my application in the following way:
l:\Proj\Silium.exe --AddWatch c:\fff.txt
When I tried to do this using some hint from internet:
import subprocess
subprocess.call(['l:\Proj\Silium.exe', '--AddWatch c:\fff.txt'])
the key "--AddWatch" arrives to my program without hyphens - like "AddWatch".
The solution is quite simple:
import subprocess
subprocess.call(['l:\Proj\Silium.exe', '--AddCMakeWatch', 'c:\fff.txt',])
And issue gone away.
P.S.: its very strange that my initial code didnt work, I dont have any idea why python corrupt the command line, I think it is the python bug.

Pyomo closes Excel

Whenever I run a python script from cmd prompt containing the following
from pyomo.environ import *
any open instance of excel closes. I have no idea why this is happening? Any help would be great. Thanks
This appears to be a bug with how Pyomo (really PyUtilib) interacts with Excel on Windows (see https://github.com/Pyomo/pyomo/issues/355). If you plan to use Pyomo with Excel, there really isn't a workaround. If you are OK with disabling support for Pyomo's excel-specific data import mechanisms, then you can work around this bug by editing pyomo/core/plugins/data/sheet.py and disabling the following code:
if win32com_available:
from pyutilib.excel.spreadsheet_win32com import ExcelSpreadsheet_win32com
tmp = ExcelSpreadsheet_win32com()
try:
tmp._excel_dispatch()
tmp._excel_quit()
_excel_available = True
except:
pass
(The simplest thing to do is change if win32com_available: to if False:)

Getting rid of black console windows when running sympy through spyder

Whenever I try to display symbolic math in Spyder via the IPython console, several black console windows pop up and then disappear in quick succession. It prints the expression, but I'd like to know if there is a way to get rid of these windows. The windows have the title "C:\Program Files\MikTex 2.9..." if that helps.
It looks like someone already figured it out and posted a solution on GitHub. This is the link: https://github.com/sympy/sympy/issues/11882
It took me (as a novice) some time to figure out exactly what he did, so the following is just a more detailed explanation:
You first need to find the compatibility module in the sympy package. For me, it was located at "C:\Users\Lucas\Anaconda3\Lib\site-packages\sympy\core\compatibility.py". Next, you need to search (in the source code of that module) for the check_output function. The surrounding code should look something like:
# check_output() is new in Python 2.7
import os
try:
try:
from subprocess import check_output
Finally, you need to get rid of the last line, and replace it with the code found in the GitHub link. The resulting block should look like:
# check_output() is new in Python 2.7
import os
try:
try:
from subprocess import check_output as subprocess_check_output
def check_output(*args, **kwargs):
return subprocess_check_output(*args, **kwargs, creationflags=0x08000000) # CREATE_NO_WINDOW
It appears to me that he defines a function which takes the place of check_output, except that the argument to suppress the output windows is always fed in. Hope this helps anyone else having this problem, and I appreciate the fix from Adam on GitHub.
I submitted a pull request to fix this for good:
https://github.com/sympy/sympy/pull/12391

Python- Error in playing mp3 audio using vlc-command line

Objective
I wanted to use the os module to play an audio file using VLC player at a faster rate.
os.system("vlc 'C:\Users\user\Desktop\file1.mp3' --rate=1.5")
What should have happened
A VLC player window should have popped open and the music should have started playing at a speed 1.5 times that of the default speed.
What happened instead
File reading failed:
VLC could not open the file "C:\Program Files\VideoLAN\VLC\'C:\Users\user\Desktop\file1.mp3'". (%m)
Your input can't be opened:
VLC is unable to open the MRL 'file:///C:/Program%20Files/VideoLAN/VLC/%27C%3A/Users/user/Desktop/file1.mp3%27'. Check the log for details.
Code
import os
os.chdir("C:\Program Files\VideoLAN\VLC")
os.system("vlc 'C:\Users\user\Desktop\file1.mp3' --rate=1.5")
Where did I go wrong?
How can I resolve the error?
This might be because of the extra quoting required in Windows paths
If you are using Python >=3.5 you can use subprocess.run instead of os.system which could help with the quoting issues as well.
import subprocess
subprocess.run(['vlc', r'C:\Users\user\Desktop\file1.mp3',
'--play-and-exit', '--rate=1.5'])
If you are using python 2.7 you may also use the following.
import subprocess
subprocess.Popen(r'vlc --rate 5 C:\Users\user\Desktop\file1.mp3',shell = True)
AFAIK, the rate switch should be given immediately after vlc. This worked for me
Please let me know if it solved your purpose.

How to show the default beautiful popup message in ubuntu using python?

http://tinypic.com/r/5dv7kj/7
How can i show the message like in the picture(top right)?
I'm new to linux and now tring to use pygtk to make a client application to show/popup some random hint/mems.
Using traditional winodw is OK,but this one is much more friendly to me.I have tried scanning through the pygtk guide but still missing the solution.Other
Is there any body could give me some hint?Any python GUI libs are also OK.
It's an Ubuntu specific thing called NotifyOSD. There are examples of programming for it here.
Quick and Dirty codes in python
import pynotify
# Only Text Notification
pynotify.init('Basic')
pynotify.Notification("Title", "simple text").show()
# Lets try with an image
pynotify.init('Image')
## Use absolute Path of the photo
pynotify.Notification("Title", "My Photo here!!", "/home/nafis/Pictures/me.png").show()
# Try Markup
pynotify.init("markup") ## all smallerCase "markup"
# but in parameter, first letter capital
pynotify.Notification("Markup",
'''
<b>bold</b>, <i>italic</i>, <u>underline</u>
and even links are supported!
'''
).show()
Also You can use it from shell (I use lubuntu, it works here.)
#!/bin/bash
### try it in terminal
notify-send -t 900 "Title" "Message"
A simple method without any additional packages.
you can execute commands via os.system.
import os
def message(title, message):
os.system(f"notify-send '{title}' '{message}'")
message("Title", "Im message")

Categories