File: staleAlbums.rb

package info (click to toggle)
amarok 3.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112,168 kB
  • sloc: cpp: 195,056; xml: 4,322; ansic: 2,634; javascript: 673; ruby: 528; python: 507; sh: 252; makefile: 12
file content (40 lines) | stat: -rwxr-xr-x 1,238 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env ruby
#
# script to remove stale entries in some database tables (album)
#
# (c) 2006 Roland Gigler <rolandg@web.de>
# License: GNU General Public License V2

class String
    def shellquote
        return "'" + self.gsub("'", "'\\\\''") + "'"
    end
end

system("dcop", "amarok", "playlist", "shortStatusMessage", "Removing stale 'album' entries from the database")

qresult = `dcop amarok collection query #{"SELECT id FROM album;".shellquote}`
result = qresult.split( "\n" )

i = 0

result.each do |id|
    print "Checking: #{id}, "
    qresult2 = `dcop amarok collection query #{"SELECT COUNT(*) FROM tags where album = #{id};".shellquote}`
    count = qresult2.chomp()
    printf "count: %s", count
    if  count == "0"
        i = i + 1
	qresult3 = `dcop amarok collection query #{"SELECT name FROM album where id = #{id} ;".shellquote}`
        result3 = qresult3.split( "\n" )
        puts "==>: Deleting: #{id}, #{result3}"
        system("dcop", "amarok", "collection", "query", "DELETE FROM album WHERE id = '#{id}'")
    end
    print "\n"
end
puts "removed #{i} albums."

if i > 0
    system("dcop", "amarok", "playlist", "popupMessage", "Removed #{i.shellquote} stale 'album' entries from the database")
end