Example #1
0
	def getSongurl(self, song_id):
		values = {'action' : 'song',
			'filter' : song_id,
			'auth'   : self.auth,
		}
		data = urllib.urlencode(values)
		try:
			response = urllib2.urlopen(self.xml_rpc + "?" + data)
			dom = xml.dom.minidom.parseString(response.read())
		except: # The data pulled from Ampache was invalid
			try:
				QMaemo5InformationBox.information(None, "Unable to get song-url --- Check Ampache!", 0)
			except:
				pass
			return False
		try:
			root     = dom.getElementsByTagName('root')[0]
			song     = root.getElementsByTagName('song')[0]
			song_url = song.getElementsByTagName('url')[0].childNodes[0].data
		except: # something failed, try to reauth and do it again
			if self.authenticate():
				self.getSongurl(song_id)
			else: # couldn't authenticate
				return False
		return song_url
Example #2
0
	def getAlbums(self,artist_id):
		if not os.path.exists("~/MyDocs/.MaAMP/albums"):
			os.system("mkdir -p ~/MyDocs/.MaAMP/albums")

		try:
			fh = open(os.path.expanduser("~/MyDocs/.MaAMP/albums/"+str(artist_id)+".dat"), 'r')
			lalbums = pickle.load(fh)
			fh.close()
			return lalbums
		except:
			values = {'action' : 'artist_albums',
				'filter' : artist_id,
				'auth'   : self.auth,
			}
			data = urllib.urlencode(values)
			try:
				response = urllib2.urlopen(self.xml_rpc + "?" + data)
				dom = xml.dom.minidom.parseString(response.read())
			except: # The data pulled from Ampache was invalid
				try:
					QMaemo5InformationBox.information(None, "Unable to get album-data --- Check Ampache!", 0)
				except:
					pass
				return False
			try: # try to get the list of artists
				root  = dom.getElementsByTagName('root')[0]
				nodes = root.getElementsByTagName('album')
				lalbums = []
				for child in nodes:
					album_id    = int(child.getAttribute('id'))
					album_name  = child.getElementsByTagName('name')[0].childNodes[0].data
					album_tracks = int(child.getElementsByTagName('tracks')[0].childNodes[0].data)
					album_cover = child.getElementsByTagName('art')[0].childNodes[0].data
					album_artist = child.getElementsByTagName('artist')[0].childNodes[0].data
					artist_id = artist_id
					album_year     = child.getElementsByTagName('year')[0].childNodes[0].data
					try:
						album_tags     = child.getElementsByTagName('tag')[0].childNodes[0].data
					except:
						album_tags = "No tag"
					if len(album_cover) > 3 and not os.path.exists("~/MyDocs/.MaAMP/albums/"+str(album_id)):
						art_file = os.path.expanduser('~/MyDocs/.MaAMP/albums/' + str(album_id))
						data = urllib2.urlopen(album_cover)
						f = open(art_file, 'w')
						f.write(data.read())
						f.close()
					album_cover = os.path.expanduser('~/MyDocs/.MaAMP/albums/'+str(album_id))

					l = [album_id,album_name,album_tracks,album_cover,album_artist,artist_id,album_year,album_tags]
					lalbums.append(l)
					fh = open(os.path.expanduser("~/MyDocs/.MaAMP/albums/"+str(artist_id)+".dat"), 'w')
					pickle.dump(lalbums,fh)
					fh.close()
				return lalbums
			except:
				if self.authenticate():
					self.getAlbums(artist_id)
				else: # couldn't authenticate
					return False
Example #3
0
   def setdefmode(self):
	if self.ui.checkBox.checkState()==0:
		self.tempconf.default_mode="auto"
		try:QMaemo5InformationBox.information(None, "automode set")
		except:print "default automode"

	else: 
		self.tempconf.default_mode="sketch"
		try:QMaemo5InformationBox.information(None, "sketchmode set")
		except: print "default sketchmode"
Example #4
0
	def clearCache(self):

		os.system("rm ~/MyDocs/.MaAMP/artists")
		os.system("rm -rf ~/MyDocs/.MaAMP/albums")
		artists = self.getArtists()
		current = ["","","",os.path.dirname( os.path.realpath( __file__ ) )+"/empty.png",""]
		return artists
		try:
			QMaemo5InformationBox.information(None, "Cache cleared!", 0)
		except:
			pass
Example #5
0
	def authenticate(self):
		self.xml_rpc = str(self.configuration[0])+"/server/xml.server.php"
		timestamp = int(time.time())
		password = hashlib.sha256(str(self.configuration[2])).hexdigest()
		authkey = hashlib.sha256(str(timestamp) + password).hexdigest()
		values = {'action'    : 'handshake',
				'auth'      : authkey,
				'timestamp' : timestamp,
				'user'      : str(self.configuration[1]),
				'version'   : '350001',
		}
		data = urllib.urlencode(values)
		try:
			response = urllib2.urlopen(self.xml_rpc + "?" + data)
			dom = xml.dom.minidom.parseString(response.read())
			self.auth = dom.getElementsByTagName("auth")[0].childNodes[0].data
			self.artists_num = int(dom.getElementsByTagName("artists")[0].childNodes[0].data)
		except: # couldn't auth, try up to AUTH_MAX_RETRY times
			self.auth = None
			self.auth_current_retry += 1
			### ERROR AUTH... RETRYING MAX TIMES ###
			if ( self.auth_current_retry < MAX ):
				time.sleep(1)
				self.authenticate()
			else:
				self.auth_current_retry = 0
				try:
					QMaemo5InformationBox.information(None, "Unable to authenticate!?!", 0)
				except:
					pass
				### FAILED MAX TIMES, REPORT ERROR (SIGNAL?!)
			return False
		self.new_last_update_time = 0
		try: 
			# check to see if ampache has been updated or cleaned since the last time this ran
			update = dom.getElementsByTagName("update")[0].childNodes[0].data
			add    = dom.getElementsByTagName("add")[0].childNodes[0].data
			clean  = dom.getElementsByTagName("clean")[0].childNodes[0].data
			# convert ISO 8601 to epoch
			update = int(time.mktime(time.strptime( update[:-6], "%Y-%m-%dT%H:%M:%S" )))
			add    = int(time.mktime(time.strptime( add[:-6], "%Y-%m-%dT%H:%M:%S" )))
			clean  = int(time.mktime(time.strptime( clean[:-6], "%Y-%m-%dT%H:%M:%S" )))
			new_time  = max([update, add, clean])
			self.new_last_update_time = new_time
		except:
			try:
				QMaemo5InformationBox.information(None, "Something is wrong with update time!?!", 0)
			except:
				pass
			#print "Couldn't get time catalog was updated -- assuming catalog is dirty"
		self.auth_current_retry = 0
		return True
Example #6
0
 def display_message(self, message, level="information"):
     """
     Display a message for a level ([information|warning|critical]), and handle the
     Maemo5 special case
     """
     if MAEMO5_PRESENT:
         QMaemo5InformationBox.information(self.win, '<p>%s</p>' % message, QMaemo5InformationBox.DefaultTimeout)
     else:
         box = QMessageBox(self.win)
         box.setText(message)
         box.setWindowTitle(QApplication.applicationName())
         if level == "critical":
             box.setIcon(QMessageBox.Critical)
         elif level == "warning":
             box.setIcon(QMessageBox.Warning)
         else:
             box.setIcon(QMessageBox.Information)
         box.exec_()
Example #7
0
	def getSongs(self, album_id):
		values = {'action' : 'album_songs',
			'filter' : album_id,
			'auth'   : self.auth,
		}
		data = urllib.urlencode(values)
		try:
			response = urllib2.urlopen(self.xml_rpc + "?" + data)
			dom = xml.dom.minidom.parseString(response.read())
		except: # The data pulled from Ampache was invalid
			try:
				QMaemo5InformationBox.information(None, "Unable to get song-data --- Check Ampache!", 0)
			except:
				pass
			return False
		try:
			root  = dom.getElementsByTagName('root')[0]
			nodes = root.getElementsByTagName('song')
			songs = []
			count = 0
			for child in nodes:
				song_id     = int(child.getAttribute('id'))
				song_title  = child.getElementsByTagName('title')[0].childNodes[0].data
				song_track  = int(child.getElementsByTagName('track')[0].childNodes[0].data)
				song_time   = int(child.getElementsByTagName('time')[0].childNodes[0].data)
				song_size   = int(child.getElementsByTagName('size')[0].childNodes[0].data)
				artist_name = child.getElementsByTagName('artist')[0].childNodes[0].data
				album_name  = child.getElementsByTagName('album')[0].childNodes[0].data
				song_time = time.strftime('%H:%M:%S', time.gmtime(song_time))
				if song_time[:2] == "00": # strip out hours if below 60 minutes
					song_time = song_time[3:]
				song_size = self.__human_readable_filesize(float(song_size))
				songs.append([song_track, song_title, artist_name, album_name, song_time, song_size, song_id])
			return songs
		except: # something failed, try to reauth and do it again
			if self.authenticate():
				self.getSongs(album_id)
			else: # couldn't authenticate
				return False
Example #8
0
File: gui.py Project: flyser/maamp
	def getconnected(self):
		### GET AMACHE CONFIGURATION AND STUFF ###
		self.amp = ampache()
		self.config = self.amp.getconfig()
		if not self.config[0] == "http://":
			if self.amp.authenticate():
				self.ui.actionConnect.setText(QtGui.QApplication.translate("MainWindow", "Connected", None, QtGui.QApplication.UnicodeUTF8))
				self.ui.actionClearRefresh.setEnabled(True)
				self.ui.actionFM_Radio.setEnabled(True)
				self.ui.actionConnect.setChecked(True)
				self.artists = self.amp.getArtists()
				self.setWindowTitle("MaAmp - Online")
				ONLINE = True
				self.ui.frame.setEnabled(True)
				try:
					QMaemo5InformationBox.information(None, "Connected ... :)", 5000)
				except:
					pass
			else:
				self.setWindowTitle("MaAmp - Offline") 
				self.ui.frame.setEnabled(False)
				self.ui.cover_art.setEnabled(False)
				self.ui.actionConnect.setText(QtGui.QApplication.translate("MainWindow", "Connect", None, QtGui.QApplication.UnicodeUTF8))
				self.ui.actionClearRefresh.setEnabled(False)
				self.ui.actionFM_Radio.setEnabled(False)
				self.ui.actionConnect.setChecked(False)
				ONLINE = False
		else:
			self.setWindowTitle("MaAmp - Offline") 
			self.ui.frame.setEnabled(False)
			self.ui.cover_art.setEnabled(False)
			self.ui.actionConnect.setText(QtGui.QApplication.translate("MainWindow", "Connect", None, QtGui.QApplication.UnicodeUTF8))
			self.ui.actionClearRefresh.setEnabled(False)
			self.ui.actionFM_Radio.setEnabled(False)
			self.ui.actionConnect.setChecked(False)
			ONLINE = False
			#try:
			QMaemo5InformationBox.information(None, "You need to configure MaAmp!", 5000)
Example #9
0
	def fetchArtists(self):
		values = {'action' : 'artists',
			'auth'   : self.auth,
		}
		data = urllib.urlencode(values)
		try: 
			response = urllib2.urlopen(self.xml_rpc + "?" + data)
			dom = xml.dom.minidom.parseString(response.read())
		except: # The data pulled from Ampache was invalid
			try:
				QMaemo5InformationBox.information(None, "Unable to get artist-data --- Check Ampache!", 0)
			except:
				pass
			return False
		try: # try to get the list of artists
			root  = dom.getElementsByTagName('root')[0]
			nodes = root.getElementsByTagName('artist')
		except:
			if self.authenticate():
				self.fetchArtists()
			else: # couldn't authenticate
				return False
			nodes = ""
		return nodes
Example #10
0
 def display_message(self, message, level="information"):
     QMaemo5InformationBox.information(self.win, '<p>%s</p>' % message, QMaemo5InformationBox.DefaultTimeout)
Example #11
0
 def display_message(self, message, level="information", timeout=None):
     if timeout is None:
         timeout = QMaemo5InformationBox.DefaultTimeout
     QMaemo5InformationBox.information(self.win, "<p>%s</p>" % message, timeout)
Example #12
0
 def show_banner(self, message, timeout = 5000):
     QMaemo5InformationBox.information(None, QString(message), timeout)
Example #13
0
 def show_note(self, message):
     QMaemo5InformationBox.information(None, QString(message), 0)
Example #14
0
 def showInfoPopup(self,  target,  text):
     QMaemo5InformationBox.information(target, text)