Exemple #1
0
    def playbackinfochanged(self, event):
        if event.playbackinfo.playerid == self.playerid:
            if self.song != event.playbackinfo.song and event.playbackinfo.song and self.songchangecommand:
                os.system(event.playbackinfo.song.format(self.songchangecommand, safe=True))
            self.song = event.playbackinfo.song
            self.paused = event.playbackinfo.ispaused()
            self.stopped = event.playbackinfo.isstopped()
            if self.song:
                self.settitle(u"%s%s" % (event.playbackinfo.iscrossfading() and "-> " or "", self.song.format(self.songformat)))
            else:
                self.settitle(_("Playback Info"))
            self.time = event.playbackinfo.time
            self.update()

            # update player info file, if configured
            if self.playerinfofd:
                try:
                    self.playerinfofd.seek(0)
                    if self.song:
                        info = "%s - %s (%s/%s)\n"  % ( self.song.artist,
                                                        self.song.title,
                                                        formattime(self.time),
                                                        formattime(self.song.length))
                    else:
                        info = _("Not playing") + "\n"
                    info = encoding.encode(info)
                    self.playerinfofd.write(info)
                    self.playerinfofd.truncate(len(info))
                except IOError, e:
                    log.error(_("error '%s' occured during write to playerinfofile") % e)
                    self.playerinfofd = None
Exemple #2
0
    def update(self):
        if self.playlist.autoplaymode == "repeat":
            autoplaymode = " [%s]" % _("Repeat")
        elif self.playlist.autoplaymode == "random":
            autoplaymode = " [%s]" % _("Random")
        else:
            autoplaymode = ""
        self.settitle("%s (-%s/%s)%s" %
                      (_("Playlist"),
                       formattime((self.playlist.ttime - self.playlist.ptime)),
                       formattime(self.playlist.ttime), autoplaymode))

        window.window.update(self)
        if self.hasfocus():
            self.updatestatusbar()

        for i in range(self.playlist.top, self.playlist.top + self.ih):
            attr = curses.A_NORMAL

            if i < len(self.playlist):
                item = self.playlist[i]
                if item.playstarttime is not None:
                    h, m, s = time.localtime(item.playstarttime)[3:6]
                else:
                    h = m = s = 0
                adddict = {
                    "playstarthours": h,
                    "playstartminutes": m,
                    "playstartseconds": s
                }
                name = encoding.encode(
                    item.song.format(self.songformat, adddict=adddict))
                if self.playlist.playingitem and item is self.playlist.playingitem:
                    if self.playlist.selected == i and self.hasfocus():
                        attr = self.colors.selected_playingsong
                    else:
                        attr = self.colors.playingsong
                elif item.hasbeenplayed():
                    if i == self.playlist.selected and self.hasfocus():
                        attr = self.colors.selected_playedsong
                    else:
                        attr = self.colors.playedsong
                else:
                    if i == self.playlist.selected and self.hasfocus():
                        attr = self.colors.selected_unplayedsong
                    else:
                        attr = self.colors.unplayedsong
            else:
                name = ""
            self.addnstr(i - self.playlist.top + self.iy, self.ix,
                         name.ljust(self.iw)[:self.iw], self.iw, attr)

        self.updatescrollbar()

        # move cursor to the right position in order to make it more
        # easy for users of Braille displays to track the current
        # position/selection
        if self.hasfocus() and self.playlist.selected is not None:
            self.win.move(self.playlist.selected - self.playlist.top + 1, 1)
Exemple #3
0
    def update(self):
        if self.playlist.autoplaymode == "repeat":
            autoplaymode = " [%s]" % _("Repeat")
        elif self.playlist.autoplaymode == "random":
            autoplaymode = " [%s]" % _("Random")
        else:
            autoplaymode = ""
        self.settitle("%s (-%s/%s)%s" % ( _("Playlist"),
                                        formattime((self.playlist.ttime-
                                                    self.playlist.ptime)),
                                        formattime(self.playlist.ttime),
                                        autoplaymode))

        window.window.update(self)
        if self.hasfocus():
            self.updatestatusbar()

        for i in range(self.playlist.top, self.playlist.top+self.ih):
            attr = curses.A_NORMAL

            if i<len(self.playlist):
                item = self.playlist[i]
                if item.playstarttime is not None:
                    h, m, s = time.localtime(item.playstarttime)[3:6]
                else:
                    h = m = s = 0
                adddict = {"playstarthours":   h,
                           "playstartminutes": m,
                           "playstartseconds": s}
                name = encoding.encode(item.song.format(self.songformat, adddict=adddict))
                if self.playlist.playingitem and item is self.playlist.playingitem:
                    if self.playlist.selected==i and self.hasfocus():
                        attr = self.colors.selected_playingsong
                    else:
                        attr = self.colors.playingsong
                elif item.hasbeenplayed():
                    if i==self.playlist.selected and self.hasfocus():
                        attr = self.colors.selected_playedsong
                    else:
                        attr = self.colors.playedsong
                else:
                    if i==self.playlist.selected and self.hasfocus():
                        attr = self.colors.selected_unplayedsong
                    else:
                        attr = self.colors.unplayedsong
            else:
                name = ""
            self.addnstr(i-self.playlist.top+self.iy, self.ix, name.ljust(self.iw)[:self.iw], self.iw, attr)

        self.updatescrollbar()

        # move cursor to the right position in order to make it more
        # easy for users of Braille displays to track the current
        # position/selection
        if self.hasfocus() and self.playlist.selected is not None:
            self.win.move(self.playlist.selected-self.playlist.top+1, 1)
Exemple #4
0
def importannounce(lang):
    page = int(request.args.get('page', 0))
    f = request.files['data']
    f.save('uploads/announcements.csv')
    with open('data/' + lang + '/announcements/timelog.txt') as f:
        line = f.readline()
        if len(line) > 0:
            firstTime = datetime.strptime(line, '%m/%d/%Y %H:%M:%S')
        else:
            firstTime = datetime.min
    with open('uploads/announcements.csv') as f:
        data = list(csv.reader(f, delimiter=","))[1:]
    for line in data:
        nextFileName = next_element(lang, 'announcements')
        content = {'message': line[1], 'teacher': line[2]}
        currenttime = datetime.strptime(line[0], '%m/%d/%Y %H:%M:%S')
        if currenttime <= firstTime:
            continue
        content['date'] = "{}/{}/{}".format(currenttime.month, currenttime.day,
                                            currenttime.year)
        content['time'] = formattime(currenttime)
        with open('data/' + lang + '/announcements/' + nextFileName, "w") as f:
            json.dump(content, f)
        update_log('data/' + lang + '/announcements', nextFileName)
    with open('data/' + lang + '/announcements/timelog.txt', "w") as timelog:
        timelog.write(data[-1][0])
    return redirect(url_for('ui.announcements', lang=lang, page=page))
Exemple #5
0
    def getinfo(self):
        l = [["", "", "", ""]] * 4
        # if we are unable to fetch the title, the song has been deleted in the meantime
        if self.title is None:
            return l
        l[0] = [_("Title:"), self.title]
        if self.tracknumber:
            l[0] += [
                _("Nr:"),
                _formatnumbertotal(self.tracknumber, self.trackcount)
            ]
        else:
            l[0] += ["", ""]
        if self.album:
            l[1] = [_("Album:"), self.album]
        else:
            l[1] = [_("URL:"), self.url]

        if self.year:
            l[1] += [_("Year:"), str(self.year)]
        else:
            l[1] += ["", ""]

        if self.artist:
            l[2] = [_("Artist:"), self.artist]
        else:
            l[2] = ["", ""]
        if self.length:
            l[2] += [_("Time:"), helper.formattime(self.length)]
        else:
            l[2] += ["", ""]
        if self.tags:
            l[3] = [_("Tags:"), " | ".join(self.tags)]

        if self.getplayingtime() is not None:
            seconds = int((time.time() - self.getplayingtime()) / 60)
            days, rest = divmod(seconds, 24 * 60)
            hours, minutes = divmod(rest, 60)
            if days >= 10:
                played = "%dd" % days
            elif days > 0:
                played = "%dd %dh" % (days, hours)
            elif hours > 0:
                played = "%dh %dm" % (hours, minutes)
            else:
                played = "%dm" % minutes
            if self.rating:
                played = played + " (%s)" % ("*" * self.rating)
            l[3] += [_("Played:"), _("#%d, %s ago") % (self.playcount, played)]
        else:
            if self.rating:
                l[3] += [_("Rating:"), "*" * self.rating]
            else:
                l[3] += ["", ""]
        return l
Exemple #6
0
    def getinfo(self):
        l = [["", "", "", ""]]*4
        # if we are unable to fetch the title, the song has been deleted in the meantime
        if self.title is None:
            return l
        l[0] = [_("Title:"), self.title]
        if self.tracknumber:
            l[0] += [_("Nr:"), _formatnumbertotal(self.tracknumber, self.trackcount)]
        else:
            l[0] += ["", ""]
        if self.album:
             l[1] = [_("Album:"),  self.album]
        else:
             l[1] = [_("URL:"), self.url]

        if self.year:
            l[1] += [_("Year:"), str(self.year)]
        else:
            l[1] += ["", ""]

        if self.artist:
            l[2] = [_("Artist:"), self.artist]
        else:
            l[2] = ["", ""]
        if self.length:
            l[2] += [_("Time:"), helper.formattime(self.length)]
        else:
            l[2] += ["", ""]
        if self.tags:
            l[3] = [_("Tags:"), u" | ".join(self.tags)]

        if self.getplayingtime() is not None:
            seconds = int((time.time()-self.getplayingtime())/60)
            days, rest = divmod(seconds, 24*60)
            hours, minutes = divmod(rest, 60)
            if days>=10:
                played = "%dd" % days
            elif days>0:
                played = "%dd %dh" % (days, hours)
            elif hours>0:
                played = "%dh %dm" % (hours, minutes)
            else:
                played = "%dm" % minutes
            if self.rating:
                played = played + " (%s)" % ("*"*self.rating)
            l[3] += [_("Played:"),
                   _("#%d, %s ago") % (self.playcount, played)]
        else:
            if self.rating:
                l[3] += [_("Rating:"), "*" * self.rating]
            else:
                l[3] += ["", ""]
        return l
Exemple #7
0
    def update(self):
        window.window.update(self)
        self.updatestatusbar()
        self.addstr(1, self.ix, " "*self.iw)
        if self.song:
            self.move(1, self.ix)
            s1 = _("Time:")
            s2 = " %s/%s " % (formattime(self.time), formattime(self.song.length))
            self.addstr(s1, self.colors.description)
            self.addstr(s2, self.colors.content)

            if not self.paused:
                barlen = self.iw-len(s1)-len(s2)
                try:
                    percentplayed = int(barlen*self.time/self.song.length)
                except ZeroDivisionError:
                    percentplayed = 0
                self.addstr("#"*(percentplayed), self.colors.progressbarhigh)
                self.addstr("#"*(barlen-percentplayed), self.colors.progressbar)
            else:
                self.addstr(_("paused"), self.colors.description)
Exemple #8
0
def addannounce(lang):
    page = int(request.args.get('page', 0))
    name = next_element(lang, 'announcements')
    requestform = request.form.to_dict()
    currenttime = datetime.now()
    requestform['date'] = "{}/{}/{}".format(currenttime.month, currenttime.day,
                                            currenttime.year)
    requestform['time'] = formattime(currenttime)
    content = json.dumps(requestform)
    with open('data/' + lang + '/announcements/' + name, 'w') as f:
        f.write(content)
    update_log('data/' + lang + '/announcements', name)
    return redirect(url_for('ui.announcements', lang=lang, page=page))
Exemple #9
0
    def update(self):
        window.window.update(self)
        self.updatestatusbar()
        self.addstr(1, self.ix, " " * self.iw)
        if self.song:
            self.move(1, self.ix)
            s1 = _("Time:")
            s2 = " %s/%s " % (formattime(
                self.time), formattime(self.song.length))
            self.addstr(s1, self.colors.description)
            self.addstr(s2, self.colors.content)

            if not self.paused:
                barlen = self.iw - len(s1) - len(s2)
                try:
                    percentplayed = int(barlen * self.time / self.song.length)
                except ZeroDivisionError:
                    percentplayed = 0
                self.addstr("#" * (percentplayed), self.colors.progressbarhigh)
                self.addstr("#" * (barlen - percentplayed),
                            self.colors.progressbar)
            else:
                self.addstr(_("paused"), self.colors.description)
Exemple #10
0
    def playbackinfochanged(self, event):
        if event.playbackinfo.playerid == self.playerid:
            if self.song != event.playbackinfo.song and event.playbackinfo.song and self.songchangecommand:
                os.system(
                    event.playbackinfo.song.format(self.songchangecommand,
                                                   safe=True))
            self.song = event.playbackinfo.song
            self.paused = event.playbackinfo.ispaused()
            self.stopped = event.playbackinfo.isstopped()
            if self.song:
                self.settitle(u"%s%s" %
                              (event.playbackinfo.iscrossfading() and "-> "
                               or "", self.song.format(self.songformat)))
            else:
                self.settitle(_("Playback Info"))
            self.time = event.playbackinfo.time
            self.update()

            # update player info file, if configured
            if self.playerinfofd:
                try:
                    self.playerinfofd.seek(0)
                    if self.song:
                        info = "%s - %s (%s/%s)\n" % (
                            self.song.artist, self.song.title,
                            formattime(self.time), formattime(
                                self.song.length))
                    else:
                        info = _("Not playing") + "\n"
                    info = encoding.encode(info)
                    self.playerinfofd.write(info)
                    self.playerinfofd.truncate(len(info))
                except IOError, e:
                    log.error(
                        _("error '%s' occured during write to playerinfofile")
                        % e)
                    self.playerinfofd = None
Exemple #11
0
    elif args[0]=="playlistdeleteplayedsongs":
        channel.notify(events.playlistdeleteplayedsongs())
    elif args[0]=="playlistreplay":
        channel.notify(events.playlistreplay())
    elif args[0]=="playlistshuffle":
        channel.notify(events.playlistshuffle())
    elif args[0]=="getplayerinfo":
        playbackinfo = channel.request(requests.getplaybackinfo("main"))
        if playbackinfo.song:
            # we have to manually request the song metadata because there the main event and request hub is not correctly
            # initialized
            song_metadata = channel.request(requests.getsong_metadata(playbackinfo.song.songdbid, playbackinfo.song.id))
           
            s="%s - %s (%s/%s)" % (song_metadata.artist,
                                    song_metadata.title,
                                    helper.formattime(playbackinfo.time),
                                    helper.formattime(song_metadata.length))
            print(s)
    else:
        usage()
        sys.exit(2)
else:
    if args[0]=="playerratecurrentsong" and len(args)==2:
        try:
            rating = int(args[1])
            if not 1<=rating<=5:
                raise
        except:
            usage()
            sys.exit(2)
        channel.notify(events.playerratecurrentsong("main", rating))