7 sys
.path
.append(os
.path
.expanduser("~/src/ql/trunk/mutagen"))
10 SUPPORTED_EXTENSIONS
= '.mp3'
21 LOC
[INCOMING
] = "media"
22 LOC
[DEVICE
] = "device"
25 def list_files(top
, ext
):
26 if isinstance(ext
,list):
27 accept
= lambda e
: e
in ext
29 accept
= lambda e
: e
== ext
30 for r
,ds
,fs
in os
.walk(top
):
32 if accept( os
.path
.splitext(f
)[1] ):
33 yield os
.path
.join(r
,f
)
35 def get_device_tracks():
36 return list_files(LOC
[DEVICE
], SUPPORTED_EXTENSIONS
)
38 def get_incoming_tracks():
39 return list_files(LOC
[INCOMING
], SUPPORTED_EXTENSIONS
)
43 self
.window
= gtk
.Window()
44 self
.window
.set_title('sync')
45 self
.window
.connect('destroy', gtk
.main_quit
)
49 scroll
= gtk
.ScrolledWindow()
50 scroll
.set_policy(gtk
.POLICY_AUTOMATIC
,gtk
.POLICY_AUTOMATIC
)
53 self
.main_list
= gtk
.TreeView()
54 self
.main_list
.set_headers_visible(False)
56 text_renderer
= gtk
.CellRendererText()
57 column
= gtk
.TreeViewColumn("track", text_renderer
)
58 column
.add_attribute(text_renderer
, "text", TITLE
)
59 column
.add_attribute(text_renderer
, "background", BACKGROUND
)
61 self
.main_list
.append_column( column
)
62 scroll
.add(self
.main_list
)
64 go_button
= gtk
.Button('Go!')
65 go_button
.connect("clicked", self
.do_sync
)
66 vbox
.add_with_properties(go_button
,'expand',False)
70 self
.window
.resize(400,600)
71 self
.window
.show_all()
73 def add_entries(self
, lst
):
74 if self
.main_list
.get_model() is None:
75 self
.main_list
.set_model( gtk
.ListStore(str,str,str,int) )
77 self
.main_list
.get_model().append( i
)
79 def do_sync(self
,*argv
,**kw
):
81 for row
in self
.main_list
.get_model():
82 if row
[LOCATION
] == INCOMING
:
83 print "mv %s %s" % (row
[FULLPATH
], LOC
[DEVICE
])
86 try: return mutagen
.File(t
).tags
['TIT2']
87 except: return os
.path
.basename(t
)
90 LOC
[DEVICE
] = sys
.argv
[1]
91 LOC
[INCOMING
] = sys
.argv
[2]
96 for entry
in [(track_title(t
),'#d0d0f0',t
,DEVICE
) for t
in get_device_tracks()]:
97 app
.add_entries([entry
])
98 for entry
in [(track_title(t
),'#90ff90',t
,INCOMING
) for t
in get_incoming_tracks()]:
99 app
.add_entries([entry
])