def __init__(self, player, playlisttt): threading.Thread.__init__(self) os.system("clear") self.cmdInput = None self._player = player self.pp = playlisttt self.color = colorPrint.bcolors() self.mediaInfo = mediaInfo2.mediaTag() print(self.color.HEADER + "<---- mOTHmUSICpLAYER ---->" + self.color.ENDC + "\n") # load on startup if bool(configuration.get_conf("player", "remember_last_track")): self.pp.external_playlist_flag = True item = self.pp.get_items_from_playlist("last_track_and_playlist", "none") # print item self.pp.playlist = item[2] if len(item) == 3: load_index = 1 else: load_index = int(item[3].strip()) self._player.load_track_from_playlist(self.pp.playlist, load_index) elif bool(configuration.get_conf("player", "load_from_playlist_on_startup")): self._player.load_track_from_playlist(self.pp.playlist, int(0)) # load the eq for x in range(1, 11): value = configuration.get_conf("eq", "band" + str(int(x) - 1), "int") self._player.eq_set(int(x), int(value))
def destroy(self, widget, data=None): print("destroy") if bool(configuration.get_conf("player", "empty_playlist_on_close")): self.playlist.empty_playlist(os.path.abspath(os.getcwd() + '/' + self.playlist.playlist)) self.player.exit_player() self.player_controls.settings.destroy() Gtk.main_quit()
def load_track_from_playlist(self, playlist_path, index_): logging.debug("loading track from playlist") #get the items from the playlist #promijenjo!!! self.music_items = self.playlist_instance.get_items_from_playlist(playlist_path) if index_ >= 0: if index_ <= len(self.music_items): #print index_ self.item_to_play = self.music_items[index_ - 1] self.current_track_playlist_index = index_ else: #print " <ERROR: could not load track from playlist" if bool(configuration.get_conf("player", "repeat_all")): self.item_to_play = self.music_items[0] self.current_track_playlist_index = 1 else: return False else: return False #pass the track path to load_track_method self.load_track(self.item_to_play) #notify gui that there is a song change self.gui.playlist__.playlist_selection_change(self.current_track_playlist_index - 1) #if everything went ok return TRUE return True
def create_store(self): store = Gtk.TreeStore(str, str) data_sections = configuration.get_sections() for section in data_sections: piter = store.append(None, [section, ""]) for option in configuration.get_options(section): store.append(piter, [option, str(configuration.get_conf(section, option, "string"))]) return store
def about_to_finish(self, player): print("about to finish") if not self.track_queue.empty(): self.current_track_playlist_index = self.track_queue.get() self.music_items = self.playlist_instance.get_items_from_playlist(self.playlist_instance.playlist) if not bool(configuration.get_conf("player", "repeat")): self.current_track_playlist_index += 1 self.load_track_from_playlist(self.playlist_instance.playlist, self.current_track_playlist_index)
def pause_track(self, data=None): logging.debug("pausing the track") if bool(configuration.get_conf("effects", "pause_fade")): self.vol.fade_effect_out(self.player, self.volume_show_track(), 0.5, 100) self.player.set_state(Gst.State.PAUSED) self.is_playing = False self.is_paused = True
def show_hide_filechooser(self): self.explorer = configuration.get_conf("player", "show_explorer", "bool") if not (self.explorer): self.file_box.hide() self.file_chooser__.folder = self.file_chooser__.file_.get_current_folder() return self.file_box.show() self.file_chooser__.file_.set_current_folder(self.file_chooser__.folder) self.file_chooser__.file_.grab_focus()
def show_hide(self, flag=False): self.show_flag = bool(configuration.get_conf("player", "show_console", "bool")) if self.show_flag and flag: self.box.show() self.is_visible = True else: self.textbox.set_text("") self.box.hide() self.is_visible = False
def get_keybindings(self): logging.debug("getting the keybindings from config file") self.play_keystr = str(configuration.get_conf("keybindings", "play", "string")) self.pause_keystr = str(configuration.get_conf("keybindings", "pause", "string")) self.next_keystr = str(configuration.get_conf("keybindings", "next", "string")) self.prev_keystr = str(configuration.get_conf("keybindings", "prev", "string")) self.volup_upkeystr = str(configuration.get_conf("keybindings", "volup", "string")) self.voldown_keystr = str(configuration.get_conf("keybindings", "voldown", "string")) self.file_keystr = str(configuration.get_conf("keybindings", "file_show", "string"))
def textbox_callback(self, widget, entry): if bool(configuration.get_conf("player", "show_console", "bool")): if self.comm_flag: self.show_hide() self.comm_flag = False return text = widget.get_text() result = self.evaluate(text) if (result): self.output("Unknown command") else: self.show_hide()
def __init__(self, playlist, playlist_class): self.playlist = playlist self.store = playlist_class.store self.playlist_class_ = playlist_class self.sel_array = [[''], ['']] self.count = 0 self.file_filter = Gtk.FileFilter() self.file_filter.set_name("Audio") self.file_filter.add_mime_type("audio/mpeg") self.file_filter.add_mime_type("audio/ogg") self.file_filter.add_pattern("*.mp3") self.file_filter.add_pattern("*.flac") self.file_ = None self.all_filter = Gtk.FileFilter() self.all_filter.set_name("Everything") self.all_filter.add_pattern("*") self.folder = configuration.get_conf("file_chooser", "default_load_path", "string")
def file_chooser_box2(self): box = Gtk.HBox(False, 0) file_ = Gtk.FileChooserWidget() file_.add_filter(self.file_filter) file_.add_filter(self.all_filter) file_.set_filter(self.file_filter) file_.set_action(Gtk.FileChooserAction.OPEN) # implement a check here!! file_.set_current_folder(configuration.get_conf("file_chooser", "default_load_path", "string")) file_.set_show_hidden(False) file_.set_select_multiple(True) file_.set_property("has-focus", False) #used for the enter key hacks file_tree = \ file_.get_children()[0].get_children()[1].get_children()[1].get_children()[0].get_children()[0].get_children()[ 0] #.get_children()[0] #file_tree.hide() file_tree_selection = file_tree.get_selection() file_tree_selection.connect("changed", self.selection_changed, file_) file_.connect("key-press-event", self.on_key_press_event, 0) file_.connect("file-activated", self.on_key_press_event, None, 1) file_.connect("current-folder-changed", self.current_folder_changed) self.file_ = file_ self.file_chooser_places_show_hide() box.pack_start(file_, True, True, 0) file_.show() box.show() return box
def __init__(self, parent): self.parent = parent self.is_visible = False self.box = None self.show_flag = bool(configuration.get_conf("player", "show_console", "bool")) self.comm_flag = False
def player_controls(self): # make a box to pack the buttons in box = Gtk.HBox(False, 5) box.set_border_width(5) spacer1 = Gtk.VSeparator() spacer2 = Gtk.VSeparator() #declare images image_play = Gtk.Image() image_pause = Gtk.Image() image_prev = Gtk.Image() image_next = Gtk.Image() image_repeat = Gtk.Image() image_pref = Gtk.Image() #set images image_play.set_from_stock(Gtk.STOCK_MEDIA_PLAY, Gtk.IconSize.BUTTON) image_pause.set_from_stock(Gtk.STOCK_MEDIA_PAUSE, Gtk.IconSize.BUTTON) image_prev.set_from_stock(Gtk.STOCK_MEDIA_PREVIOUS, Gtk.IconSize.BUTTON) image_next.set_from_stock(Gtk.STOCK_MEDIA_NEXT, Gtk.IconSize.BUTTON) image_repeat.set_from_stock(Gtk.STOCK_REFRESH, Gtk.IconSize.BUTTON) image_pref.set_from_stock(Gtk.STOCK_PREFERENCES, Gtk.IconSize.BUTTON) #declare buttons self.play_button = Gtk.Button() self.play_button.set_image(image_play) self.play_button.props.relief = Gtk.ReliefStyle.NONE self.play_button.set_focus_on_click(False) self.pause_button = Gtk.Button() self.pause_button.set_image(image_pause) self.pause_button.props.relief = Gtk.ReliefStyle.NONE self.pause_button.set_focus_on_click(False) self.prev_button = Gtk.Button() self.prev_button.set_image(image_prev) self.prev_button.props.relief = Gtk.ReliefStyle.NONE self.prev_button.set_focus_on_click(False) self.next_button = Gtk.Button() self.next_button.set_image(image_next) self.next_button.props.relief = Gtk.ReliefStyle.NONE self.next_button.set_focus_on_click(False) self.repeat_button = Gtk.ToggleButton() self.repeat_button.set_image(image_repeat) self.repeat_button.props.relief = Gtk.ReliefStyle.NONE self.repeat_button.set_focus_on_click(False) state = configuration.get_conf("player", "repeat") if bool(state): self.repeat_button.set_active(True) self.pref_button = Gtk.Button() self.pref_button.set_image(image_pref) self.pref_button.props.relief = Gtk.ReliefStyle.NONE self.pref_button.set_focus_on_click(False) #initalize volume self.volume_button = Gtk.VolumeButton() self.volume_button.set_value(float(configuration.get_conf("player", "volume", "int")) / 100) self.volume_button.connect("value-changed", self.volume_value_changed) self.player.volume_track(self.volume_button.get_value() * 100) #self.seek_bar_ = self.seek_bar() self.seek_bar__ = seekbar_gui.seek_bar_(self.player) self.seek_bar_ = self.seek_bar__.seek_bar() #pack the buttons box.pack_start(self.play_button, False, True, 0) box.pack_start(self.pause_button, False, True, 0) box.pack_start(self.prev_button, False, True, 0) box.pack_start(self.next_button, False, True, 0) box.pack_start(spacer1, False, True, 10) box.pack_start(self.repeat_button, False, True, 0) box.pack_start(spacer2, False, True, 10) box.pack_start(self.seek_bar_, True, True, 0) box.pack_start(self.volume_button, False, True, 0) box.pack_start(self.pref_button, False, False, 10) #show everything spacer1.show() spacer2.show() self.play_button.show() self.pause_button.show() self.prev_button.show() self.next_button.show() self.repeat_button.show() self.pref_button.show() self.volume_button.show() box.show() return box
#! usr/bin/env python import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GObject from mothmusicplayer3 import configuration from mothmusicplayer3 import seekbar_gui from mothmusicplayer3 import settings_gui import logging logging.basicConfig(format=str(configuration.get_conf("logger", "format", "string")), level=logging.DEBUG) class player_controls_: def __init__(self, parent_class): self.parent = parent_class self.player = self.parent.player self.timer = self.parent.timer self.settings = settings_gui.preferences_gui(self) def volume_value_changed(self, volumebutton, value): self.player.volume_track(value * 100) def update_volume_slider(self): logging.debug("updating the volume slider") self.volume_button.set_value(self.player.volume_show_track() / 100) def player_controls(self): # make a box to pack the buttons in
def file_chooser_places_show_hide(self): file_box = self.file_.get_children()[0].get_children()[1].get_children()[0] # .get_children()[1] if configuration.get_conf("file_chooser", "show_places"): file_box.show() else: file_box.hide()
def show_hide(self): state = configuration.get_conf("player", "show_infobar", "bool") if state: self.box.show() else: self.box.hide()
def evaluate(self, text): tokens = self.get_tokens(text) if tokens[0] == ":set": if tokens[1] == "repeat": state = tokens[2] in ["true", "True", "TRUE", "1", "t"] configuration.set_conf("player", "repeat", bool(state)) return False if tokens[1] == "repeat_all": state = tokens[2] in ["true", "True", "TRUE", "1", "t"] configuration.set_conf("player", "repeat_all", bool(state)) return False if tokens[1] == "show_places": if configuration.get_conf("player", "show_explorer", "bool"): state = tokens[2] in ["true", "True", "TRUE", "1", "t"] configuration.set_conf("file_chooser", "show_places", state) self.parent.file_chooser__.file_chooser_places_show_hide() return False if tokens[1] == "show_explorer": state = tokens[2] in ["true", "True", "TRUE", "1", "t"] configuration.set_conf("player", "show_explorer", state) self.parent.show_hide_filechooser() return False if tokens[1] == "vol": self.parent.player.volume_track(float(tokens[2])) return False elif tokens[0] == ":r": configuration.set_conf("player", "repeat", not configuration.get_conf("player", "repeat", "bool")) return False elif tokens[0] == ":ra": configuration.set_conf("player", "repeat_all", not configuration.get_conf("player", "repeat_all", "bool")) return False elif tokens[0] == ":e": state = configuration.get_conf("player", "show_explorer", "bool") configuration.set_conf("player", "show_explorer", not state) self.parent.show_hide_filechooser() return False elif tokens[0] == ":i": state = configuration.get_conf("player", "show_infobar", "bool") configuration.set_conf("player", "show_infobar", not state) self.parent.infobar.show_hide() return False elif tokens[0] == ":s" or tokens[0] == ":settings": self.parent.player_controls__.settings.show_settings_window() elif tokens[0] == ":vol" or tokens[0] == ":v": if len(tokens) == 3: if tokens[1] == "up" or tokens[1] == "u": self.parent.player.volume_track_by(int(tokens[2]), "up") if tokens[2] == "down" or tokens[1] == "d": self.parent.player.volume_track_by(int(tokens[2]), "down") elif len(tokens) == 2: self.parent.player.volume_track(float(tokens[1])) return False elif tokens[0] == ":pause" or tokens[0] == ":pa": self.parent.player.pause_track() return False elif tokens[0] == ":play" or tokens[0] == ":pl" or tokens[0] == ":p": if len(tokens) == 1: self.parent.player_controls__.play_button_pressed() else: if int(tokens[1]) < len(self.parent.playlist__.store): self.parent.playlist__.playlist_selection_change(int(tokens[1])) self.parent.player_controls__.play_button_pressed() return False elif len(tokens) == 1 and (tokens[0][1:].isdigit()): if int(tokens[0][1:]) < len(self.parent.playlist__.store): self.parent.playlist__.playlist_selection_change(int(tokens[0][1:])) self.parent.player_controls__.play_button_pressed() return False elif tokens[0] == ":next" or tokens[0] == ":ne": self.parent.player.start_next_track_from_playlist() return False elif tokens[0] == ":prev" or tokens[0] == ":pr": self.parent.player.start_previous_track_from_playlist() return False elif tokens[0] == ":q": self.parent.destroy(None) return False elif tokens[0] == ":que": for x in range(1, len(tokens)): self.parent.player.enque(int(tokens[x])) self.parent.playlist__.update_queue() return False elif tokens[0] == ":qe": self.parent.player.empty_queue() self.parent.playlist__.update_queue() return False elif tokens[0] == ":d": if len(tokens) == 1: self.parent.playlist__.remove_selected(None, self.parent.playlist__.treeView) return False elif tokens[0] == ":da": self.parent.playlist__.select_all(None, self.parent.playlist__.treeView) self.parent.playlist__.remove_selected(None, self.parent.playlist__.treeView) return False return True
def cmd_input(self): while 1: self.cmdInput = input(self.color.OKBLUE + ":." + self.color.ENDC) if self.cmdInput == "load": load_path = input(" <path:") self._player.load_track(load_path) elif self.cmdInput == "load-from-playlist": # Display the playlist items = self.pp.get_items_from_playlist(self.pp.playlist, "") x = 1 print(self.color.OKGREEN + "\n <Playlist:\n" + self.color.ENDC) for item in items: print( " <" + str(x) + ". " + self.color.OKBLUE + self.mediaInfo.track_get_title(item) + self.color.ENDC + " - " + self.mediaInfo.track_get_artist(item) + "\n path: " + item[0:30] + "..." ) x = x + 1 print("\n") num = input(" <index of the track to load: ") if num > 0: self._player.load_track_from_playlist(self.pp.playlist, int(num)) else: print(self.color.FAIL + " <ERROR: index doesn't exist!" + self.color.ENDC) elif self.cmdInput == "load-into-playlist": path = input(" <path: ") self.pp.put_item_into_playlist(self.pp.playlist, path) elif self.cmdInput == "copy-into-internal-playlist": if self.pp.playlist == self.pp.internal_playlist: print(self.color.ERROR + " <do you really want to duplicate?!" + self.color.ENDC) else: self.pp.load_external_playlist_into_internal(self.pp.playlist, "a") self._player.load_track_from_playlist(self.pp.playlist, 1) elif self.cmdInput == "load-playlist": path = input(" <path:") self.pp.load_external_playlist(path) elif self.cmdInput == "load-internal-playlist": self.pp.load_internal_playlist() elif self.cmdInput == "playlist-search": input_ = input(" <query:") result_items = self.pp.search_playlist(input_) if len(result_items) == 0: print(" <no match") else: x = 1 print(self.color.OKGREEN + "\n <Search Reults:\n" + self.color.ENDC) for item in result_items: print( " <" + str(x) + ". " + self.color.OKBLUE + self.mediaInfo.track_get_title(item[0]) + self.color.ENDC + " - " + self.mediaInfo.track_get_artist(item[0]) + "\n path: " + item[0][0:30] + "..." ) x = x + 1 print("\n") num = input(" <do you want to load a track? (index):") if num != "": if int(num) > 0: self._player.load_track_from_playlist( self.pp.playlist, int(result_items[int(num) - 1][1]) + 1 ) else: print(self.color.FAIL + " <ERROR: index doesn't exist!" + self.color.ENDC) elif self.cmdInput == "play": self._player.start_track() elif self.cmdInput == "play-next": self._player.start_next_track_from_playlist() elif self.cmdInput == "play-prev": self._player.start_previous_track_from_playlist() elif self.cmdInput == "stop": self._player.stop_track() elif self.cmdInput == "pause": self._player.pause_track() elif self.cmdInput == "volume-set": print( self.color.OKGREEN + "\n <current: " + str(int(self._player.volume_show_track())) + self.color.ENDC ) inp = input(" <set:") if inp != "": self._player.volume_track(float(inp)) print("\n") elif self.cmdInput == "info": print(self.color.OKGREEN + "\n <Track Info:\n" + self.color.ENDC) print( "\n < title: " + self.color.OKBLUE + self.mediaInfo.track_get_title(self._player._filepath) + self.color.ENDC ) print( " < artist: " + self.color.OKBLUE + self.mediaInfo.track_get_artist(self._player._filepath) + self.color.ENDC ) print( " < album: " + self.color.OKBLUE + self.mediaInfo.track_get_album(self._player._filepath) + self.color.ENDC ) print( " < year: " + self.color.OKBLUE + self.mediaInfo.track_get_year(self._player._filepath) + self.color.ENDC ) print( " < track: " + self.color.OKBLUE + self.mediaInfo.track_get_track(self._player._filepath) + self.color.ENDC ) print( " < genre: " + self.color.OKBLUE + self.mediaInfo.track_get_genre(self._player._filepath) + self.color.ENDC ) print( " < duration: " + self.color.OKBLUE + timeConverter.convert_time(self.mediaInfo.track_get_duration(self._player._filepath) * 1000000000) + self.color.ENDC ) print( " < bitrate: " + self.color.OKBLUE + self.mediaInfo.track_get_bitrate(self._player._filepath) + "\n" + self.color.ENDC ) elif self.cmdInput == "position-get": print( self.color.OKGREEN + "\n <current position: " + self.color.ENDC + str(self._player.get_current_position_track()) + "\n" ) elif self.cmdInput == "position-set": print("\n <input format: hh:mm:ss") inp = input(" <set:") if inp != "": self._player.set_position_track(timeConverter.convert_time_back(inp)) print("\n") elif self.cmdInput == "config": input_ = input(" <") if input_ == "repeat": print( " <" + self.color.OKBLUE + str(configuration.get_conf("player", "repeat")) + self.color.ENDC ) input_ = input(" <") if input_ != "": configuration.set_conf("player", "repeat", input_) elif input_ == "fade": print( " <" + self.color.OKBLUE + str(configuration.get_conf("effects", "pause_fade")) + self.color.ENDC ) input_ = input(" <") if input_ != "": configuration.set_conf("effects", "pause_fade", input_) elif input_ == "remember on exit": print( " <" + self.color.OKBLUE + str(configuration.get_conf("player", "remember_last_track")) + self.color.ENDC ) input_ = input(" <") if input_ != "": configuration.set_conf("player", "remember_last_track", input_) elif input_ == "load on startup": print( " <" + self.color.OKBLUE + str(configuration.get_conf("player", "load_from_playlist_on_startup")) + self.color.ENDC ) input_ = input(" <") if input_ != "": configuration.set_conf("player", "load_from_playlist_on_startup", input_) elif self.cmdInput == "path-get": print(" <path: " + self._player.filepath) elif self.cmdInput == "playlist-erase-all": self.pp.empty_playlist(self.pp.playlist) elif self.cmdInput == "playlist-erase": items = self.pp.get_items_from_playlist(self.pp.playlist, "") x = 1 for item in items: print( " <" + str(x) + ". " + self.color.OKBLUE + self.mediaInfo.track_get_title(item) + self.color.ENDC + " - " + self.mediaInfo.track_get_artist(item) + "\n path: " + item[0:30] + "..." ) x = x + 1 num = input(" <erase item with index: ") if num.isdigit(): if num > 0: if int(num) > int(len(items)): print(self.color.FAIL + " <ERROR: index is out of bound" + self.color.ENDC) else: self.pp.delete_item_by_number(self.pp.playlist, int(num)) else: print(self.color.FAIL + " <ERORR: index can't be < 0" + self.color.ENDC) else: print(self.color.FAIL + " <ERROR: invalid input!" + self.color.ENDC) elif self.cmdInput == "playlist-get": items = self.pp.get_items_from_playlist(self.pp.playlist, "") x = 1 print(self.color.OKGREEN + "\n <Playlist:\n" + self.color.ENDC) for item in items: print( " <" + str(x) + ". " + self.color.OKBLUE + self.mediaInfo.track_get_title(item) + self.color.ENDC + " - " + self.mediaInfo.track_get_artist(item) + "\n path: " + item[0:25] + "..." ) x = x + 1 print("\n") elif self.cmdInput == "eq-get": eq_values = self._player.eq_get() for x in range(1, 11): print(" <" + str(x) + ". band" + str(x - 1) + ": " + str(eq_values[x - 1])) elif self.cmdInput == "eq-set": print(self._player.eq_get()) input_band = input(" <band(1-10):") input_value = input(" <value(-24 - 12):") self._player.eq_set(input_band, int(input_value)) configuration.set_conf("eq", "band" + str(int(input_band) - 1), str(int(input_value))) elif self.cmdInput == "clear": os.system("clear") elif self.cmdInput == "exit": if bool(configuration.get_conf("player", "remember_last_track")): self.pp.empty_playlist("last_track_and_playlist") self.pp.put_item_into_playlist("last_track_and_playlist", self._player._filepath) self.pp.put_item_into_playlist("last_track_and_playlist", self.pp.playlist) self.pp.put_item_into_playlist("last_track_and_playlist", self._player.current_track_playlist_index) self.exit_cmd() elif not self.cmdInput == "exit": print(self.color.FAIL + " <ERROR: unknown command" + self.color.ENDC)