
# LyricsScreenlet Copyright (C) 2009 by Marcel Dancak <dancakm@gmail.com>

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


import gio

def get_local_path_from_uri(uri):
	if uri != None and uri != "":
		try:			
			f = gio.File(uri)
			local_path = f.get_path()
			#print "converting URI to local_path"
			return local_path
		except Exception, e:
			print e
			print "Cannot convert URI: \"%s\"to local path" % uri
			print "URI calss: %s" % uri.__class__
			try:
				unicodeUri = unicode(str(uri), 'utf-8')
				f = gio.File(uri)
				local_path = f.get_path()
				return local_path
			except Exception, e:
				print e
				print "Cannot convert unicoded URI: \"%s\"to local path" % uri
		return uri
