Hi List,<br><br>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...
<br><br>I have attached the tar.bz2 package, and the source is below, not sure on what the process for distribution is...<br><br>Cheers,<br><br>Greg<br>
<br>
<br>
podnovasync_conf.rb:<br><br>#!/usr/bin/ruby<br>$:.unshift File.join(File.dirname(__FILE__))<br>require 'Korundum'<br>require 'net/http'<br><br>class PodnovaOpmlConfig < Qt::Widget<br><br> slots 'testUrl()', 'saveUrl()'
<br> attr_reader :lineEdit1<br> attr_reader :testButton<br> attr_reader :saveButton<br> attr_reader :resultText<br> attr_reader :inputLabel<br><br><br> def initialize(parent = nil, name = nil, fl = 0)<br>
super<br><br> if name.nil?<br> setName("PodnovaOpmlConfig")<br> end<br><br> @podNovaUrl = ""<br><br> @lineEdit1 = Qt::LineEdit.new(self, "lineEdit1")
<br> @lineEdit1.setGeometry( Qt::Rect.new(160, 50, 270, 22) )<br><br> @testButton = Qt::PushButton.new(self, "testButton")<br> @testButton.setGeometry( Qt::Rect.new(450, 50, 70, 24) )<br><br>
@saveButton = Qt::PushButton.new(self, "saveButton")<br> @saveButton.setGeometry( Qt::Rect.new(410, 270, 112, 24) )<br><br> @resultText = Qt::TextView.new(self, "resultText")<br> @
resultText.setGeometry( Qt::Rect.new(50, 90, 451, 161) )<br><br> @inputLabel = Qt::Label.new(self, "inputLabel")<br> @inputLabel.setGeometry( Qt::Rect.new(20, 50, 120, 20) )<br><br> connect( @testButton, SIGNAL('clicked()'), self, SLOT( 'testUrl()' ) )
<br> connect( @saveButton, SIGNAL('clicked()'), self, SLOT( 'saveUrl()' ) )<br><br> languageChange()<br> resize( Qt::Size.new(568, 320).expandedTo(minimumSizeHint()) )<br> clearWState( WState_Polished )
<br> end<br> <br> def testUrl<br> @podNovaUrl = @lineEdit1.text()<br> Thread.new(@podNovaUrl) { |myPage|<br> req = Net::HTTP.get_response(URI.parse(myPage))<br> @resultText.setText
(req.body)<br> }<br> end<br> <br> def saveUrl<br> conf_file = File.open("./synpodnova.conf", "w")<br> conf_file.truncate(0)<br> conf_file.write("opmlUrl=" + @podNovaUrl + "\n")
<br> conf_file.close<br> Qt::Application.exit( 0 )<br> end<br><br> #<br> # Sets the strings of the subwidgets using the current<br> # language.<br> #<br> def languageChange()<br> setCaption(trUtf8("Podnova OPML Sync Config"))
<br> @testButton.setText( trUtf8("Test") )<br> @testButton.setAccel(Qt::KeySequence.new(nil))<br> @saveButton.setText( trUtf8("S&ave") )<br> @saveButton.setAccel( Qt::KeySequence.new
(trUtf8("Alt+A")) )<br> @inputLabel.setText( trUtf8("Podnova OPML URL") )<br> Qt::ToolTip.add( @inputLabel, nil )<br> end<br> protected :languageChange<br><br><br>end<br><br><br><br>
podnovasyn.rb:<br><br>#!/usr/bin/ruby<br>$:.unshift File.join(File.dirname(__FILE__))<br>require 'podnovasync_conf.rb'<br>require 'net/http'<br>require 'rexml/document'<br><br>begin<br>require 'logger'
<br>require 'Korundum'<br><br>rescue LoadError<br> error="Korundum is required for this script, please install it."<br> `kdialog --sorry '#{error}'`<br> exit<br>end<br><br>class PodnovaSync
<br> SYNC_INTERVAL = 60<br> def initialize<br> trap( "SIGTERM" ) {<br> cleanup()<br> }<br> trap("SIGINT"){<br> cleanup()<br> }<br> @log =
Logger.new("./podnova_sync.log")<br> KDE::CmdLineArgs.init(ARGV, KDE::AboutData.new("chwallpaper", "Change wallpaper", "0.1"))<br> @kde_application = KDE::Application.new
()<br> @dcopclient = KDE::DCOPClient.new<br> @dcopclient.attach<br> @dcopclient.registerAs("PodnovaSync",false)<br> @amarok_playlist_browser = KDE::DCOPRef.new('amarok', 'playlistbrowser')
<br> @amarok_playlist_browser.setDCOPClient(@dcopclient)<br> @config_done = false<br><br> end<br> <br> def cleanup()<br> @log.debug( "Recieved SIGTERM, cleanup and close." )<br>
exit<br> end<br> <br> def do_configuration<br> if !@config_done<br> @config_done = true<br> config = PodnovaOpmlConfig.new()<br> @kde_application.setMainWidget(config)
<br> config.show()<br> @kde_application.exec()<br> else<br> error="Config has already run, please restart the script to run it again."<br> `kdialog --sorry '#{error}'`
<br> end<br> end<br><br> def sync_podcasts<br> opml_url = get_config_value("opmlUrl")<br> if !opml_url.nil?<br> opml = Net::HTTP.get_response(URI.parse(opml_url)).body<br> rss_xml_urls = get_rss_xml_urls(opml)
<br> rss_xml_urls.each do |url|<br> @amarok_playlist_browser.addPodcast(url)<br> end<br> @amarok_playlist_browser.scanPodcasts()<br> end<br> end<br><br> def get_rss_xml_urls(opml_string)
<br> url_list = []<br> doc = REXML::Document.new opml_string<br> REXML::XPath.each( doc, "/opml/body/outline/outline/@xmlUrl") { |url| url_list << url.to_s }<br> return url_list
<br> end<br><br> def get_config_value(key)<br> begin<br> File.open("./synpodnova.conf", "r").each_line do |line|<br> if line[key]<br> return line.split
("=")[1].chomp<br> end<br> end<br> rescue Exception<br> end<br> return nil<br> end<br> def run<br> sync_podcasts<br> @log.debug("Running...")
<br> syncThread = Thread.new(){<br> loop do<br> sync_podcasts<br> sleep(SYNC_INTERVAL * 60)<br> end<br> }<br> <br> loop do<br> message = gets().chomp() #Read message from stdin
<br> if(message == "configure")<br> do_configuration()<br> end<br> end<br> syncThread.join()<br> @log.debug("Done.")<br> end<br>end<br><br>PodnovaSync.new
().run<br><br><br><br clear="all"><br>-- <br>Greg Chrystall<br><a href="mailto:greg@chrystall.co.nz">greg@chrystall.co.nz</a><br>+64 27 696 7464