Amarok Script to synchronise with podcast subscription service - OPML
Greg Chrystall
greg at chrystall.co.nz
Thu Jun 7 11:47:12 UTC 2007
Hi List,
The following is a script i whipped together to synchronise Podnova podcast
subscriptions with Amarok. It uses the podnova OPML Url, one problem is that
I can not get a list of podcasts already subscribed to through DCOP, so it
pops up warnings, that the podcasts have already been subscribed to in
Amarok whenever the script runs...
I have attached the tar.bz2 package, and the source is below, not sure on
what the process for distribution is...
Cheers,
Greg
podnovasync_conf.rb:
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'Korundum'
require 'net/http'
class PodnovaOpmlConfig < Qt::Widget
slots 'testUrl()', 'saveUrl()'
attr_reader :lineEdit1
attr_reader :testButton
attr_reader :saveButton
attr_reader :resultText
attr_reader :inputLabel
def initialize(parent = nil, name = nil, fl = 0)
super
if name.nil?
setName("PodnovaOpmlConfig")
end
@podNovaUrl = ""
@lineEdit1 = Qt::LineEdit.new(self, "lineEdit1")
@lineEdit1.setGeometry( Qt::Rect.new(160, 50, 270, 22) )
@testButton = Qt::PushButton.new(self, "testButton")
@testButton.setGeometry( Qt::Rect.new(450, 50, 70, 24) )
@saveButton = Qt::PushButton.new(self, "saveButton")
@saveButton.setGeometry( Qt::Rect.new(410, 270, 112, 24) )
@resultText = Qt::TextView.new(self, "resultText")
@resultText.setGeometry( Qt::Rect.new(50, 90, 451, 161) )
@inputLabel = Qt::Label.new(self, "inputLabel")
@inputLabel.setGeometry( Qt::Rect.new(20, 50, 120, 20) )
connect( @testButton, SIGNAL('clicked()'), self, SLOT( 'testUrl()' )
)
connect( @saveButton, SIGNAL('clicked()'), self, SLOT( 'saveUrl()' )
)
languageChange()
resize( Qt::Size.new(568, 320).expandedTo(minimumSizeHint()) )
clearWState( WState_Polished )
end
def testUrl
@podNovaUrl = @lineEdit1.text()
Thread.new(@podNovaUrl) { |myPage|
req = Net::HTTP.get_response(URI.parse(myPage))
@resultText.setText(req.body)
}
end
def saveUrl
conf_file = File.open("./synpodnova.conf", "w")
conf_file.truncate(0)
conf_file.write("opmlUrl=" + @podNovaUrl + "\n")
conf_file.close
Qt::Application.exit( 0 )
end
#
# Sets the strings of the subwidgets using the current
# language.
#
def languageChange()
setCaption(trUtf8("Podnova OPML Sync Config"))
@testButton.setText( trUtf8("Test") )
@testButton.setAccel(Qt::KeySequence.new(nil))
@saveButton.setText( trUtf8("S&ave") )
@saveButton.setAccel( Qt::KeySequence.new(trUtf8("Alt+A")) )
@inputLabel.setText( trUtf8("Podnova OPML URL") )
Qt::ToolTip.add( @inputLabel, nil )
end
protected :languageChange
end
podnovasyn.rb:
#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))
require 'podnovasync_conf.rb'
require 'net/http'
require 'rexml/document'
begin
require 'logger'
require 'Korundum'
rescue LoadError
error="Korundum is required for this script, please install it."
`kdialog --sorry '#{error}'`
exit
end
class PodnovaSync
SYNC_INTERVAL = 60
def initialize
trap( "SIGTERM" ) {
cleanup()
}
trap("SIGINT"){
cleanup()
}
@log = Logger.new("./podnova_sync.log")
KDE::CmdLineArgs.init(ARGV, KDE::AboutData.new("chwallpaper",
"Change wallpaper", "0.1"))
@kde_application = KDE::Application.new()
@dcopclient = KDE::DCOPClient.new
@dcopclient.attach
@dcopclient.registerAs("PodnovaSync",false)
@amarok_playlist_browser = KDE::DCOPRef.new('amarok',
'playlistbrowser')
@amarok_playlist_browser.setDCOPClient(@dcopclient)
@config_done = false
end
def cleanup()
@log.debug( "Recieved SIGTERM, cleanup and close." )
exit
end
def do_configuration
if !@config_done
@config_done = true
config = PodnovaOpmlConfig.new()
@kde_application.setMainWidget(config)
config.show()
@kde_application.exec()
else
error="Config has already run, please restart the script to run
it again."
`kdialog --sorry '#{error}'`
end
end
def sync_podcasts
opml_url = get_config_value("opmlUrl")
if !opml_url.nil?
opml = Net::HTTP.get_response(URI.parse(opml_url)).body
rss_xml_urls = get_rss_xml_urls(opml)
rss_xml_urls.each do |url|
@amarok_playlist_browser.addPodcast(url)
end
@amarok_playlist_browser.scanPodcasts()
end
end
def get_rss_xml_urls(opml_string)
url_list = []
doc = REXML::Document.new opml_string
REXML::XPath.each( doc, "/opml/body/outline/outline/@xmlUrl") {
|url| url_list << url.to_s }
return url_list
end
def get_config_value(key)
begin
File.open("./synpodnova.conf", "r").each_line do |line|
if line[key]
return line.split("=")[1].chomp
end
end
rescue Exception
end
return nil
end
def run
sync_podcasts
@log.debug("Running...")
syncThread = Thread.new(){
loop do
sync_podcasts
sleep(SYNC_INTERVAL * 60)
end
}
loop do
message = gets().chomp() #Read message from stdin
if(message == "configure")
do_configuration()
end
end
syncThread.join()
@log.debug("Done.")
end
end
PodnovaSync.new().run
--
Greg Chrystall
greg at chrystall.co.nz
+64 27 696 7464
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/amarok/attachments/20070607/13d404e1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: podnovasync.amarokscript.tar.bz2
Type: application/x-bzip2
Size: 2874 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/amarok/attachments/20070607/13d404e1/attachment.bin>
More information about the Amarok
mailing list