def __check_entry(self, add, time, name): try: util.parse_time(time.get_text(), None) except: add.set_sensitive(False) else: add.set_sensitive(bool(name.get_text()))
def _seek(self, time, library, window, player): seek_to = player.get_position() if time[0] == "+": seek_to += util.parse_time(time[1:]) * 1000 elif time[0] == "-": seek_to -= util.parse_time(time[1:]) * 1000 else: seek_to = util.parse_time(time) * 1000 seek_to = min(player.song.get("~#length", 0) * 1000 -1, max(0, seek_to)) player.seek(seek_to)
def _seek(app, time): player = app.player if not player.song: return seek_to = player.get_position() if time[0] == "+": seek_to += util.parse_time(time[1:]) * 1000 elif time[0] == "-": seek_to -= util.parse_time(time[1:]) * 1000 else: seek_to = util.parse_time(time) * 1000 seek_to = min(player.song.get("~#length", 0) * 1000 - 1, max(0, seek_to)) player.seek(seek_to)
def bookmarks(self): """Parse and return song position bookmarks, or set them. Accessing this returns a copy, so song.bookmarks.append(...) will not work; you need to do marks = song.bookmarks marks.append(...) song.bookmarks = marks """ marks = [] invalid = [] for line in self.list("~bookmark"): try: time, mark = line.split(" ", 1) except: invalid.append((-1, line)) else: try: time = util.parse_time(time, None) except: invalid.append((-1, line)) else: if time >= 0: marks.append((time, mark)) else: invalid.append((-1, line)) marks.sort() marks.extend(invalid) return marks
def __add(self, model, time, name): try: time = util.parse_time(time.get_text(), None) except: pass else: model.append([time, name.get_text()])
def __edit_time(self, render, path, new, model): try: time = util.parse_time(new, None) except: pass else: model[path][0] = time
def __fill_af(feed, af): try: af["title"] = feed.title or _("Unknown") except: af["title"] = _("Unknown") try: af["date"] = "%04d-%02d-%02d" % feed.modified_parsed[:3] except (AttributeError, TypeError): pass for songkey, feedkey in [ ("website", "link"), ("description", "tagline"), ("language", "language"), ("copyright", "copyright"), ("organization", "publisher"), ("license", "license")]: try: value = getattr(feed, feedkey) except: pass else: if value and value not in af.list(songkey): af.add(songkey, value) try: author = feed.author_detail except AttributeError: try: author = feed.author except AttributeError: pass else: if author and author not in af.list("artist"): af.add('artist', author) else: try: if author.email and author.email not in af.list("contact"): af.add("contact", author.email) except AttributeError: pass try: if author.name and author.name not in af.list("artist"): af.add("artist", author.name) except AttributeError: pass try: values = feed.contributors except AttributeError: pass else: for value in values: try: value = value.name except AttributeError: pass else: if value and value not in af.list("performer"): af.add("performer", value) try: af["~#length"] = util.parse_time(feed.itunes_duration) except (AttributeError, ValueError): pass try: values = dict(feed.categories).values() except AttributeError: pass else: for value in values: if value and value not in af.list("genre"): af.add("genre", value)
def __get_bookmarks(self): marks = [] invalid = [] for line in self.list("~bookmark"): try: time, mark = line.split(" ", 1) except: invalid.append((-1, line)) else: try: time = util.parse_time(time, None) except: invalid.append((-1, line)) else: if time >= 0: marks.append((time, mark)) else: invalid.append((-1, line)) marks.sort() marks.extend(invalid) return marks
def test_negative(self): self.failUnlessEqual(util.parse_time("-2:04"), -124)
def test_roundtrip(self): # The values are the ones tested for Tformat_time, so we know they # will be formatted correctly. They're also representative of # all the major patterns. for i in [0, 59, 60, 60 * 59 + 59, 60 * 60, 60 * 60 + 60 * 59 + 59]: self.failUnlessEqual(util.parse_time(util.format_time(i)), i)
def test_empty(self): self.failUnlessEqual(util.parse_time(""), 0)
def test_invalid(self): self.failUnlessEqual(util.parse_time("not a time"), 0)