def repeat(event): write_on_line_one('repeat:') with connection(): write_on_line_two(client.currentsong()['artist']) for index, song in enumerate(client.playlistsearch('artist', client.currentsong()['artist'])): with connection(): new_pos = index + 1 print('move', song['id'], 'to', new_pos) client.moveid(song['id'], new_pos) print('now play at position 1')
def show_sysinfo(): global mode while True: if mode != 'recording': with connection(): try: write_on_line_one(client.currentsong()['artist']) except KeyError: write_on_line_one('hmm, unknown') with connection(): try: write_on_line_two(client.currentsong()['title']) except KeyError: write_on_line_one('hmm, unknown') sleep(UPDATE_INTERVAL)
def display_popup(): current_song=client.currentsong() popup=[] if 'title' in current_song.keys(): if len(current_song['title'])<=30: popup.append(current_song['title']) else: popup.append(current_song['title'][0:30]) else: insert=current_song['file'].split('/') insert=insert[len(insert)-1] if len(insert)<=30: popup.append(insert) else: popup.append(insert[0:30]) if 'artist' in current_song.keys(): popup.append('by '+current_song['artist']) if 'album' in current_song.keys(): if len(current_song['album']+' on ')<=30: popup[1]+=' on '+current_song['album'] else: popup[1]+=' on '+current_song['album'][0:30] else: popup[1]+=' on unknown album' else: if len(popup)==2: popup[1]='by unknown artist '+popup[1] else: popup.append('by unknown artist on unknown album') notifier.update(popup[0],popup[1]) notifier.show()
def song_change(): song=get_insert(client.currentsong()) mainwindow_wTree.get_widget('current_song_label').set_property("label","<span font_size='12344'>"+song[0]+"</span>") infowindow_wTree.get_widget('artist_entry').set_text(song[1]) infowindow_wTree.get_widget('title_entry').set_text(song[2]) infowindow_wTree.get_widget('album_entry').set_text(song[3]) highlight_song()
def rate_it(delta): rating = None file = None with connection(): file = '/mnt/share/' + client.currentsong()['file'] if file != None: tagr.rate_it(file, delta) return rating
def save_artistbio(bio,show): artist=client.currentsong()['artist'] artist=artist.lower().replace(' ','+') artist=artist.replace('/','+') temp=open(os.getenv("HOME")+'/.pinna/bios/'+artist,'w') temp.write(bio) temp.close() if show==True: info_vars.view='bio' infowindow_wTree.get_widget('info_textview').get_buffer().set_text(bio)
def save_albumart(artwork): song=client.currentsong() file_name=song['artist']+':'+song['album'] file_name=file_name.lower().replace(' ','+') file_name=file_name.replace('/','+') file_name=os.getenv("HOME")+'/.pinna/album_art/'+file_name+'.jpg' temp=open(file_name,'w') temp.write(artwork) temp.close() infowindow_wTree.get_widget('info_textview').get_buffer().delete(infowindow_wTree.get_widget('info_textview').get_buffer().get_iter_at_line_offset(0,0),infowindow_wTree.get_widget('info_textview').get_buffer().get_iter_at_line_offset(0,1)) set_albumart()
def save_lyrics(lyrics): info_vars.view='lyrics' file_name=client.currentsong()['file'].split('/') file_name=file_name[len(file_name)-1] file_name=file_name.replace(' ','+') file_name=file_name[0:len(file_name)-4] file_name=os.getenv("HOME")+'/.pinna/lyrics/'+file_name+'.txt' temp=open(file_name,'w') temp.write(lyrics) temp.close() change_lyrics(None)
def scrape_artistbio(show): song=client.currentsong() if 'artist' in song.keys(): bio='' artist=infowindow_wTree.get_widget('artist_entry').get_text().lower().replace(' ','+') url='http://www.last.fm/music/'+artist+'/+wiki' u=urllib2.urlopen(url) data=u.read() start=data.find('<div id="wiki">')+36 end=data.find('</div><!-- #wiki -->') data=data[start:end] save_artistbio(format_text(data),show)
def favourite(event): global mode favourites = load_favourites() if mode == 'recording': mode = 'playing' print(event.ir_code) write_on_line_one(event.ir_code) with connection(): write_on_line_two('FAVE: ' + client.currentsong()['artist']) with connection(): favourites[event.ir_code] = client.currentsong()['artist'] save_favourites(favourites) else: print('play track by artist saved as', event.ir_code) try: print(event.ir_code, favourites[event.ir_code]) play_now(favourites[event.ir_code]) except KeyError: print('nothing saved as', event.ir_code) pass print(favourites)
def change_biography(widget): info_vars.view='bio' song=client.currentsong() artist=song['artist'].replace(' ','+') artist=artist.lower().replace('/','+') if os.path.isfile(os.getenv("HOME")+'/.pinna/bios/'+artist): temp=open(os.getenv("HOME")+'/.pinna/bios/'+artist) infowindow_wTree.get_widget('info_textview').get_buffer().set_text('\n'+temp.read()) temp.close() else: infowindow_wTree.get_widget('info_textview').get_buffer().set_text('') set_albumart()
def filechooser_ok(widget): song=client.currentsong() song=song['artist']+':'+song['album']+'.jpg' song=song.lower().replace(' ','+') song=song.replace('/','+') width=170 height=170 image_file=gtk.gdk.pixbuf_new_from_file_at_size(infowindow_wTree.get_widget('filechooser').get_filename(),width,height) infowindow_wTree.get_widget('info_textview').get_buffer().delete(infowindow_wTree.get_widget('info_textview').get_buffer().get_iter_at_line_offset(0,0),infowindow_wTree.get_widget('info_textview').get_buffer().get_iter_at_line_offset(0,1)) image_file.save(os.getenv("HOME")+'/.pinna/album_art/'+song,'jpeg') set_albumart() infowindow_wTree.get_widget('filechooser').hide() return True
def change_info(): song=client.currentsong() if info_vars.view=='lyrics': change_lyrics(None) if info_vars.view=='bio': change_biography(None) if 'album' in song.keys() and 'artist' in song.keys(): infowindow_wTree.get_widget('album_entry').set_sensitive(True) infowindow_wTree.get_widget('from_file').set_sensitive(True) else: infowindow_wTree.get_widget('album_entry').set_sensitive(False) infowindow_wTree.get_widget('from_file').set_sensitive(False) display_popup()
def set_albumart(main=True): song=client.currentsong() pixbuf=default_albumart if 'artist' in song.keys() and 'album' in song.keys(): song=song['artist']+':'+song['album']+'.jpg' song=song.lower().replace(' ','+') song=song.replace('/','+') check=os.getenv("HOME")+"/.pinna/album_art/"+song if os.path.isfile(check): pixbuf = gtk.gdk.pixbuf_new_from_file(check) if main==True: mainwindow_wTree.get_widget('main_window_album_art').set_from_pixbuf(pixbuf.scale_simple(80,80,gtk.gdk.INTERP_BILINEAR)) infowindow_wTree.get_widget('info_textview').get_buffer().insert_pixbuf(infowindow_wTree.get_widget('info_textview').get_buffer().get_iter_at_line_offset(0,0),pixbuf) notifier.set_icon_from_pixbuf(pixbuf.scale_simple(40,40,gtk.gdk.INTERP_BILINEAR))
def change_lyrics(widget): info_vars.view='lyrics' file_name=client.currentsong()['file'].split('/') file_name=file_name[len(file_name)-1] file_name=file_name.replace(' ','+') file_name=file_name[0:len(file_name)-4]+'.txt' check=os.getenv("HOME")+'/.pinna/lyrics/'+file_name if os.path.isfile(check): temp=open(check) lyrics=temp.read() infowindow_wTree.get_widget('info_textview').get_buffer().set_text('\n'+lyrics) temp.close() else: infowindow_wTree.get_widget('info_textview').get_buffer().set_text('') set_albumart()
def scrape_albumart(): song=client.currentsong() if 'artist' in song.keys() and 'album' in song.keys(): artist=infowindow_wTree.get_widget('artist_entry').get_text() album=infowindow_wTree.get_widget('album_entry').get_text() try: if not scrape_rhapsody(artist,album): try: scrape_amazon(artist,album) except: pass except: try: scrape_amazon(artist,album) except: pass
def initiate_filechooser(first=False): chooser=infowindow_wTree.get_widget('filechooser') if first==True: file_filter=gtk.FileFilter() file_filter.set_name('Images') file_filter.add_mime_type("image/png") file_filter.add_mime_type("image/jpg") file_filter.add_pattern("*.jpg") file_filter.add_pattern("*.gif") file_filter.add_pattern("*.bmp") chooser.add_filter(file_filter) else: if settings.music_directory: song=client.currentsong()['file'].split('/') song.pop(len(song)-1) song=settings.music_directory+'/'.join(song) chooser.set_current_folder(song) else: chooser.set_current_folder(os.getenv("HOME")) chooser.show()
def set_current_browser(deleted,to_modify,old_length): model=browserwindow_wTree.get_widget('browser_list').get_model() browserwindow_wTree.get_widget('browser_list').set_model(None) if deleted: for i in range(old_length-1,old_length-deleted-1,-1): model.remove(model.get_iter(i)) if len(to_modify)!=0: for item in to_modify: try: liter=model.get_iter(item[0]) model.set_value(liter,1,item[1]) except: model.append([gtk.STOCK_CDROM,item[1]]) browserwindow_wTree.get_widget('browser_list').set_model(model) playing_song=client.currentsong() if len(playing_song.keys())!=0: if checks.last_song: if checks.last_song[0]!=playing_song['pos']: checks.last_song=(playing_song['pos'],get_insert(playing_song)[0],playing_song['file']) highlight_song()
def highlight_song(): playing_song=client.currentsong() model=browserwindow_wTree.get_widget('browser_list').get_model() if browser_vars.view=='current': if checks.last_song: if checks.last_song[0]!=int(playing_song['pos']): model.set_value(model.get_iter(checks.last_song[0]),1,checks.last_song[1]) checks.last_song=(int(playing_song['pos']),get_insert(playing_song)[0],playing_song['file']) model.set_value(model.get_iter(checks.last_song[0]),1,'<b>'+checks.last_song[1]+'</b>') if browser_vars.view=='file': if checks.last_song: browser_files=map(operator.itemgetter(2),browser_vars.browser_list[1]) if checks.last_song[2] in browser_files: index=browser_files.index(checks.last_song[2]) liter=model.get_iter(index) model.set_value(liter,1,'<b>'+checks.last_song[1]+'</b>') if playing_song['file'] in browser_files: index=browser_files.index(playing_song['file']) liter=model.get_iter(index) model.set_value(liter,1,'<b><i>'+get_insert(playing_song)[0]+'</i></b>') if 'pos' in playing_song.keys(): checks.last_song=(int(playing_song['pos']),get_insert(playing_song)[0],playing_song['file'])
#!/usr/bin/env python3 ''' Tag the currently playing song on mpd ''' __copyright__ = 'Copyright 2016 Paul Clarke' __licence__ = 'GPL' import sys from connection import connection, client from tagr import tag_it, untag_it with connection(): print(client.currentsong()) file = '/mnt/share/' + client.currentsong()['file'] tag = None if len(sys.argv) == 1: tag_it(file, tag) if len(sys.argv) == 2: tag = sys.argv[1] tag_it(file, tag) if len(sys.argv) == 3: tag = sys.argv[2] untag_it(file, tag)