Ejemplo n.º 1
0
	def metadata(self):
		d = dict(self.song.metadata)
		for (key,func) in (
			("artist",None),
			("title",None),
			("album",None),
			("duration",utils.formatTime),
			("url",None),
			("rating",None),
			("tags",self._convertTagsToText),
			("gain",self._formatGain),
			("completedCount",None),
			("skipCount",None),
			("lastPlayedDate",utils.formatDate),
			("id",repr),
		):
			try: value = getattr(self.song, key)
			except AttributeError: pass
			else:
				if func: value = func(value)
				if not isinstance(value, (str,unicode)):
					value = str(value)
				d[key] = utils.convertToUnicode(value)
		l = []
		for key,value in sorted(d.items()):
			l += [{"key": key, "value": value}]
		return l
Ejemplo n.º 2
0
 def metadata(self):
     d = dict(self.song.metadata)
     for (key, func) in (
         ("artist", None),
         ("title", None),
         ("album", None),
         ("duration", utils.formatTime),
         ("url", None),
         ("rating", None),
         ("tags", self._convertTagsToText),
         ("gain", self._formatGain),
         ("completedCount", None),
         ("skipCount", None),
         ("lastPlayedDate", utils.formatDate),
         ("id", repr),
     ):
         try:
             value = getattr(self.song, key)
         except AttributeError:
             pass
         else:
             if func: value = func(value)
             if not isinstance(value, (str, unicode)):
                 value = str(value)
             d[key] = utils.convertToUnicode(value)
     l = []
     for key, value in sorted(d.items()):
         l += [{"key": key, "value": value}]
     return l
Ejemplo n.º 3
0
 def tableView_objectValueForTableColumn_row_(self, tableView,
                                              tableColumn, rowIndex):
     try:
         with self.lock:
             if rowIndex >= len(self.data):
                 # This can happen if the data has changed in the middle
                 # of a tableView.redraw().
                 # Note that wrapping tableView.reloadData() doesn't work
                 # because that doesn't reload it internally - it just delays
                 # a redraw and inside the redraw, it reloads the data.
                 # So, overriding redraw with locking might work.
                 # But anyway, it doesn't really matter as we should have delayed
                 # a further reloadData().
                 # Also, in guiCocoa, there is another further workaround
                 # which probably makes this obsolete.
                 return None
             key = str(tableColumn.identifier())
             v = self.data[rowIndex].get(key, None)
             if key in self.formaters: v = self.formaters[key](v)
             if isinstance(v, str): v = utils.convertToUnicode(v)
             return v
     except Exception:
         import sys
         sys.excepthook(*sys.exc_info())
     return None
Ejemplo n.º 4
0
 def tableView_objectValueForTableColumn_row_(self, tableView,
                                              tableColumn, rowIndex):
     key = str(tableColumn.identifier())
     v = self.data[rowIndex].get(key, None)
     if key in self.formaters: v = self.formaters[key](v)
     if isinstance(v, str): v = utils.convertToUnicode(v)
     return v
Ejemplo n.º 5
0
 def tableView_objectValueForTableColumn_row_(self, tableView, tableColumn, rowIndex):
     key = str(tableColumn.identifier())
     v = self.data[rowIndex].get(key, None)
     if key in self.formaters:
         v = self.formaters[key](v)
     if isinstance(v, str):
         v = utils.convertToUnicode(v)
     return v
Ejemplo n.º 6
0
 def handleRowIndex(index, stop):
     try:
         url = self.data[index].get("url", None)
         if url:
             url = utils.convertToUnicode(url)
             possibleSources.append(url)
     except Exception:
         import sys
         sys.excepthook(*sys.exc_info())
Ejemplo n.º 7
0
			def handleRowIndex(index, stop):
				try:
					url = self.data[index].get("url", None)
					if url:
						url = utils.convertToUnicode(url)
						possibleSources.append(url)
				except Exception:
					import sys
					sys.excepthook(*sys.exc_info())						
Ejemplo n.º 8
0
	def notifyCurSong():
		pynotify.init("MusicPlayer")
		song = state.curSong
		s = None
		try:
			s = convertToUnicode(song.userString)
		except: pass

		notif = pynotify.Notification(s)
		notif.show()
Ejemplo n.º 9
0
	def notifyCurSong():
		notif = AppKit.NSUserNotification.alloc().init()
		notif.setTitle_("MusicPlayer")
		song = state.curSong
		s = None
		try:
			s = utils.convertToUnicode(song.userString)
		except: pass
		notif.setInformativeText_(s)
		notifCenter.deliverNotification_(notif)
Ejemplo n.º 10
0
    def notifyCurSong():
        pynotify.init("MusicPlayer")
        song = state.curSong
        s = None
        try:
            s = convertToUnicode(song.userString)
        except:
            pass

        notif = pynotify.Notification(s)
        notif.show()
Ejemplo n.º 11
0
 def notifyCurSong():
     notif = AppKit.NSUserNotification.alloc().init()
     notif.setTitle_("MusicPlayer")
     song = state.curSong
     s = None
     try:
         s = utils.convertToUnicode(song.userString)
     except:
         pass
     notif.setInformativeText_(s)
     notifCenter.deliverNotification_(notif)
Ejemplo n.º 12
0
	def __init__(self, *args, **kwargs): # we must support an empty init for PersistentObject
		self.f = None
		self._fileMetadata = None
		self._metadata = None
		self._useDb = True
		for key,value in kwargs.items():
			setattr(self, key, value)
		if len(args) == 1: # guess this is the url
			assert "url" not in kwargs
			self.url = args[0]
		if self.url:
			self.url = utils.convertToUnicode(self.url)
Ejemplo n.º 13
0
def ratingsIter():
	import urllib
	import re
	import utils
	for song in librarySongsIter:
		rating = song["Rating"]
		if rating is None: continue # print only songs with any rating set
		rating /= 100.0 # the maximum is 100
		fn = song["Location"]
		fn = urllib.unquote(fn)
		fn = re.sub("^file://(localhost)?", "", fn)
		fn = utils.convertToUnicode(fn)
		yield (fn, rating)
Ejemplo n.º 14
0
	def __init__(self, *args, **kwargs): # we must support an empty init for PersistentObject
		self.f = None
		self.error = None
		self._fileMetadata = None
		self._metadata = None
		self._useDb = True
		for key,value in kwargs.items():
			setattr(self, key, value)
		if len(args) == 1: # guess this is the url
			assert "url" not in kwargs
			self.url = args[0]
		if self.url:
			self.url = utils.convertToUnicode(self.url)
Ejemplo n.º 15
0
def search(query, limitResults=Search_ResultLimit):
	query = utils.convertToUnicode(query)
	cur = songSearchIndexDb._selectCmd("select docid from data where data match ? limit %i" % limitResults, (query,))
	results = [r[0] for r in cur]
	def getSongIdByRowId(rowId):
		songId = songSearchIndexRefDb._selectCmd("select songid from data where rowid=?", (rowId,)).fetchone()
		if songId is not None:
			songId = songId[0]
			return str(songId)
		return None
	results = map(getSongIdByRowId, results)
	results = map(getSongSummaryDictById, results)
	results = filter(None, results)
	return results
Ejemplo n.º 16
0
def _export_m3u(path, songs):
	f = open(path, "wb")
	f.write("#EXTM3U\n\n")
	for song in songs:
		if isinstance(song, Song):
			song = {attrib: song.get(attrib, timeout=None)
					for attrib in ("id", "url", "artist", "title", "duration")}
		assert isinstance(song, dict)
		for attrib in ("url", "artist", "title"):
			song[attrib] = utils.convertToUnicode(song[attrib]).encode("utf8")
		f.write("#%s:id=%s\n" % (appinfo.appid, repr(song["id"])))
		f.write("#EXTINF:%i,%s - %s\n" % (song["duration"], song["artist"], song["title"]))
		f.write("%s\n\n" % song["url"])
	f.write("#Playlist finished with %i songs.\n\n" % len(songs))
	f.close()
Ejemplo n.º 17
0
def insertSearchEntry_raw(songId, tokens):
	songId = buffer(songId)
	with songSearchIndexRefDb.writelock:
		rowId = songSearchIndexRefDb._selectCmd("select rowid from data where songid=?", (songId,)).fetchone()
		if rowId is not None:
			rowId = rowId[0]
		else:
			# insert new
			songSearchIndexRefDb._actionCmd("insert into data(songid) values(?)", (songId,))
			rowId = songSearchIndexRefDb._selectCmd("select rowid from data where songid=?", (songId,)).fetchone()
			assert rowId is not None
			rowId = rowId[0]
	tokens = " ".join(tokens)
	tokens = utils.convertToUnicode(tokens)
	songSearchIndexDb._actionCmd("replace into data(docid, content) values (?,?)", (rowId, tokens))
Ejemplo n.º 18
0
def _export_m3u(path, songs):
    f = open(path, "wb")
    f.write("#EXTM3U\n\n")
    for song in songs:
        if isinstance(song, Song):
            song = {
                attrib: song.get(attrib, timeout=None)
                for attrib in ("id", "url", "artist", "title", "duration")
            }
        assert isinstance(song, dict)
        for attrib in ("url", "artist", "title"):
            song[attrib] = utils.convertToUnicode(song[attrib]).encode("utf8")
        f.write("#%s:id=%s\n" % (appinfo.appid, repr(song["id"])))
        f.write("#EXTINF:%i,%s - %s\n" %
                (song["duration"], song["artist"], song["title"]))
        f.write("%s\n\n" % song["url"])
    f.write("#Playlist finished with %i songs.\n\n" % len(songs))
    f.close()
Ejemplo n.º 19
0
		def tableView_objectValueForTableColumn_row_(self, tableView, tableColumn, rowIndex):
			try:
				with self.lock:
					if rowIndex >= len(self.data):
						# This can happen if the data has changed in the middle
						# of a tableView.redraw().
						# Note that wrapping tableView.reloadData() doesn't work
						# because that doesn't reload it internally - it just delays
						# a redraw and inside the redraw, it reloads the data.
						# So, overriding redraw with locking might work.
						# But anyway, it doesn't really matter as we should have delayed
						# a further reloadData().
						# Also, in guiCocoa, there is another further workaround
						# which probably makes this obsolete.
						return None
					key = str(tableColumn.identifier())
					v = self.data[rowIndex].get(key, None)
					if key in self.formaters: v = self.formaters[key](v)
					if isinstance(v, str): v = utils.convertToUnicode(v)
					return v
			except Exception:
				import sys
				sys.excepthook(*sys.exc_info())
			return None
Ejemplo n.º 20
0
 def handleRowIndex(index, stop):
     url = self.data[index].get("url", None)
     if url:
         url = utils.convertToUnicode(url)
         possibleSources.append(url)
Ejemplo n.º 21
0
	def makeMetadataUnicode(self, metadata=None):
		import utils
		if metadata is None: metadata = self.metadata
		for key, value in metadata.items():
			if not isinstance(value, str): continue
			metadata[key] = utils.convertToUnicode(value)
Ejemplo n.º 22
0
 def handleRowIndex(index, stop):
     url = self.data[index].get("url", None)
     if url:
         url = utils.convertToUnicode(url)
         possibleSources.append(url)
Ejemplo n.º 23
0
def locateFile(filename):
	print "locateFile", utils.convertToUnicode(filename).encode("utf-8")
Ejemplo n.º 24
0
	def makeMetadataUnicode(self, metadata=None):
		import utils
		if metadata is None: metadata = self.metadata
		for key, value in metadata.items():
			if not isinstance(value, str): continue
			metadata[key] = utils.convertToUnicode(value)
Ejemplo n.º 25
0
def locateFile(filename):
    print "locateFile", utils.convertToUnicode(filename).encode("utf-8")