Example #1
0
 def task(bean):
     if bean.artist and bean.title:
         try:
             bean.artist, bean.title = any2utf(bean.artist), any2utf(bean.title)
             if bean.album:
                 bean.album = any2utf(bean.album)
             self.get_scrobbler().scrobble(bean.artist, bean.title, start_time, "P", "", int(duration_sec), bean.album or "")
             logging.debug("Song Scrobbled " + str(bean.artist) + " " + str(bean.title) + " " + str(start_time) + " P: " + str(int(duration_sec)))
         except Exception, e:
             logging.error(str(e) + "Error reporting now playing last.fm " + str(bean.artist) + " " + str(bean.title) + " A: " + str(bean.album))
Example #2
0
    def _plain_append(self, bean, parent_iter):
        logging.debug("Plain append task: " + any2utf(bean.text) + " " + any2utf(bean.path))
        if not bean:
            return

        if bean.is_file:
            bean.font = "normal"
        else:
            bean.font = "bold"

        bean.visible = True
        beans = update_id3_wind_filtering([bean])
        for one in beans:
            one.update_uuid()
            row = self.get_row_from_bean(one)

            self.model.append(parent_iter, row)
Example #3
0
    def parse(self):
        try:
            if not self.m3u:
                return
            data = any2utf(self.m3u.read())
            data = data.replace('\r\n', '\n').lstrip('\xef\xbb\xbf').split('\n')

            paths = [os.path.normpath(line).strip('\r\n').strip() for line in data
                     if line.startswith("##") or not line.startswith("#")]
            dirname = os.path.dirname(self.path)

            full_paths = []
            paths = iter(paths)
            for path in paths:
                text = None
                if path.startswith("##"):
                    def task(path):
                        text = path[2 : ]
                        try:
                            next_path = paths.next()
                            path = next_path if not next_path.startswith("##") else None
                        except StopIteration:
                            path = None
                            next_path = None
                        if not path:
                            full_paths.append( [path, text.strip('\r\n')] )
                            if next_path:
                                path, text = task(next_path)

                        return path, text

                    path, text = task(path)
                    if not path:
                        break

                if text:
                    text = text.strip('\r\n')
                else:
                    new_text = path.rsplit('/', 1)[-1]
                    if path == new_text:
                        text = path.rsplit('\\', 1)[-1]
                    else:
                        text = new_text

                if (path in "\\/"):
                    full_paths.append( [path.replace("\\", "/"), text] )
                elif path.startswith('http'):
                    if not text:
                        text = path.rsplit('/', 1)[-1]
                    full_paths.append( [path.replace('/', '//', 1), text] )
                else:
                    full_paths.append([os.path.join(dirname, path).replace("\\", "/"), text] )
            return full_paths
        except IndexError:
            logging.warn("You try to load empty playlist")
Example #4
0
    def parse(self):
        if self.embedded_cue:
            data = self.embedded_cue
        else:
            file = open(self.cue_path, "r")
            data = file.read()

        data = any2utf(correct_encoding(data))

        #code = self.code_detecter(correct_encoding(data))
        data = data.replace('\r\n', '\n').split('\n')
        title = ""
        performer = ""
        index = "00:00:00"
        full_file = None

        self.cue_file.image = get_image_by_path(self.cue_path)

        self.files_count = 0

        for line in data:

            if not line:
                continue

            line = line.strip()

            if not self.is_valid and not line.startswith(FILE):
                continue
            else:
                self.is_valid = True

            if line.startswith(TITLE):
                title = self.get_line_value(line)
                if self.files_count == 0:
                    self.cue_file.title = title

            if line.startswith(PERFORMER):
                performer = self.get_line_value(line)
                if self.files_count == 0:
                    self.cue_file.performer = performer

            if line.startswith(FILE):
                self.files_count += 1
                file = self.get_line_value(line)
                file = os.path.basename(file)

                if "/" in file:
                    file = file[file.rfind("/")+1:]
                if "\\" in file:
                    file = file[file.rfind("\\")+1:]

                dir = os.path.dirname(self.cue_path)
                full_file = os.path.join(dir, file)
                logging.debug("CUE source" + full_file)
                exists = os.path.exists(full_file)
                """if there no source cue file"""

                if not exists:
                    """try to find other source"""
                    ext = file_utils.get_file_extension(full_file)
                    nor = full_file[:-len(ext)]
                    logging.info("Normalized path" + nor)

                    find_source = False
                    for support_ext in FC().audio_formats:
                        try_name = nor + support_ext
                        if os.path.exists(try_name):
                            full_file = try_name
                            logging.debug("Found source for cue file name" + try_name)
                            find_source = True
                            break;

                    if not find_source:
                        self.is_valid = False
                        self.files_count -= 1
                        logging.warn("Can't find source for " + line + "  Check source file name")
                        continue

                if self.files_count == 0:
                    self.cue_file.file = full_file

            if line.startswith(INDEX):
                index = self.get_line_value(line)

            if line.startswith("INDEX 01"):
                cue_track = CueTrack(title, performer, index, full_file)
                self.cue_file.append_track(cue_track)

        logging.debug("CUE file parsed " + str(self.cue_file.file))
        return self.normalize()
Example #5
0
    def on_message(self, bus, message):
        type = message.type
        struct = message.get_structure()

        if type == Gst.MessageType.BUFFERING:
            percent = message.parse_buffering()
            if percent < 100:
                if not self.buffering:
                    logging.debug("Pausing...")
                    self.buffering = True
                    self.player.set_state(Gst.State.PAUSED)
                logging.debug("Buffering... %d" % percent)
            else:
                if self.buffering:
                    logging.debug("Playing...")
                    self.buffering = False
                    self.player.set_state(Gst.State.PLAYING)

            return

        if type == Gst.MessageType.ERROR:
            err, debug = message.parse_error()
            logging.warn("Error: " + str(err) + str(debug) + str(err.domain) + str(err.code))

            if self.error_counter > 1 and err.code != 1:
                self.notify_error(str(err))
                self.error_counter = 0
                self.state_stop()
            else:
                logging.warning("Error ocured, retry")
                self.error_counter += 1
                self.play(self.bean)

        elif type in [Gst.MessageType.STATE_CHANGED, Gst.MessageType.STREAM_STATUS]:
            if (
                self.bean
                and self.bean.type == FTYPE_RADIO
                and struct.has_field("new-state")
                and struct.get_enum("old-state", Gst.State) == Gst.State.READY
                and struct.get_enum("new-state", Gst.State) == Gst.State.NULL
            ):
                logging.info("Reconnect")
                self.play(self.bean)
                return

        if type == Gst.MessageType.TAG and message.parse_tag():
            self.error_counter = 0

            if struct.has_field("taglist"):
                taglist = struct.get_value("taglist")
                title = taglist.get_string("title")[1]
                if not title:
                    title = ""
                title = correct_encoding(title)
                text = title

                if taglist.get_string("artist")[0]:
                    artist = taglist.get_string("artist")[1]
                    artist = correct_encoding(artist)
                    text = artist + " - " + text
                if not text:
                    text = self.bean.path
                text = any2utf(text)
                if self._is_remote() and taglist.get_string("audio-codec")[0]:
                    text = text + " || " + taglist.get_string("audio-codec")[1]
                if self._is_remote() and taglist.get_uint("bitrate")[0]:
                    text = text + " || " + str(taglist.get_uint("bitrate")[1] / 1000) + _("kbps")
                    self.emit("bitrate-changed", taglist.get_uint("bitrate")[1])

                self.notify_title(text)

        elif type == Gst.MessageType.EOS:
            self.error_counter = 0
            logging.info("MESSAGE_EOS")
            self.notify_eos()
Example #6
0
 def write_string(file, string):
     string = any2utf(string).strip()
     file.write('##\n' + string + '\n')