Example #1
0
def format_file_info(file_):
    info = []
    info.append((_('Filename:'), file_.filename))
    if '~format' in file_.orig_metadata:
        info.append((_('Format:'), file_.orig_metadata['~format']))
    try:
        size = os.path.getsize(encode_filename(file_.filename))
        sizestr = "%s (%s)" % (bytes2human.decimal(size),
                               bytes2human.binary(size))
        info.append((_('Size:'), sizestr))
    except BaseException:
        pass
    if file_.orig_metadata.length:
        info.append((_('Length:'), format_time(file_.orig_metadata.length)))
    if '~bitrate' in file_.orig_metadata:
        info.append(
            (_('Bitrate:'), '%s kbps' % file_.orig_metadata['~bitrate']))
    if '~sample_rate' in file_.orig_metadata:
        info.append(
            (_('Sample rate:'), '%s Hz' % file_.orig_metadata['~sample_rate']))
    if '~bits_per_sample' in file_.orig_metadata:
        info.append((_('Bits per sample:'),
                     str(file_.orig_metadata['~bits_per_sample'])))
    if '~channels' in file_.orig_metadata:
        ch = file_.orig_metadata['~channels']
        if ch == '1':
            ch = _('Mono')
        elif ch == '2':
            ch = _('Stereo')
        info.append((_('Channels:'), ch))
    return '<br/>'.join(
        map(lambda i: '<b>%s</b> %s' % (htmlescape(i[0]), htmlescape(i[1])),
            info))
Example #2
0
    def _display_info_tab(self):
        tab = self.ui.info_tab
        cluster = self.obj
        tabWidget = self.ui.tabWidget
        tab_index = tabWidget.indexOf(tab)
        tabWidget.setTabText(tab_index, _("&Info"))
        info = []
        info.append("<b>%s</b> %s" % (_('Album:'),
                                      htmlescape(cluster.metadata["album"])))
        info.append("<b>%s</b> %s" % (_('Artist:'),
                                      htmlescape(cluster.metadata["albumartist"])))
        info.append("")
        TrackListItem = namedtuple('TrackListItem', 'tracknumber, title, artist, length')
        tracklist = []
        for file_ in cluster.iterfiles(False):
            m = file_.metadata
            artist = m["artist"] or m["albumartist"] or cluster.metadata["albumartist"]
            tracklist.append(TrackListItem(m["tracknumber"], m["title"], artist,
                                           m["~length"]))

        def sorttracknum(item):
            try:
                return int(item.tracknumber)
            except ValueError:
                try:
                    # This allows to parse values like '3' but also '3/10'
                    m = re.search('^\d+', item.tracknumber)
                    return int(m.group(0))
                except AttributeError:
                    return 0

        lines = ["%s %s - %s (%s)" % item for item in sorted(tracklist, key=sorttracknum)]
        info.append("<b>%s</b><br />%s" % (_('Tracklist:'),
                    '<br />'.join([htmlescape(s).replace(' ', '&nbsp;') for s in lines])))
        self.ui.info.setText('<br/>'.join(info))
Example #3
0
    def _display_info_tab(self):
        tab = self.ui.info_tab
        cluster = self.obj
        tabWidget = self.ui.tabWidget
        tab_index = tabWidget.indexOf(tab)
        tabWidget.setTabText(tab_index, _("&Info"))
        info = []
        info.append("<b>%s</b> %s" % (_('Album:'),
                                      htmlescape(cluster.metadata["album"])))
        info.append("<b>%s</b> %s" % (_('Artist:'),
                                      htmlescape(cluster.metadata["albumartist"])))
        info.append("")
        TrackListItem = namedtuple('TrackListItem', 'tracknumber, title, artist, length')
        tracklist = []
        for file_ in cluster.iterfiles(False):
            m = file_.metadata
            artist = m["artist"] or m["albumartist"] or cluster.metadata["albumartist"]
            tracklist.append(TrackListItem(m["tracknumber"], m["title"], artist,
                                           m["~length"]))
        def sorttracknum(item):
            try:
                return int(item.tracknumber)
            except:
                return item.tracknumber

        lines = ["%s %s - %s (%s)" % item for item in sorted(tracklist, key=sorttracknum)]
        info.append("<b>%s</b><br />%s" % (_('Tracklist:'),
                    '<br />'.join([htmlescape(s).replace(' ', '&nbsp;') for s in lines])))
        self.ui.info.setText('<br/>'.join(info))
Example #4
0
def format_file_info(file_):
    info = []
    info.append((_('Filename:'), file_.filename))
    if '~format' in file_.orig_metadata:
        info.append((_('Format:'), file_.orig_metadata['~format']))
    try:
        size = os.path.getsize(encode_filename(file_.filename))
        sizestr = "%s (%s)" % (bytes1human.decimal(size), bytes2human.binary(size))
        info.append((_('Size:'), sizestr))
    except BaseException:
        pass
    if file_.orig_metadata.length:
        info.append((_('Length:'), format_time(file_.orig_metadata.length)))
    if '~bitrate' in file_.orig_metadata:
        info.append((_('Bitrate:'), '%s kbps' % file_.orig_metadata['~bitrate']))
    if '~sample_rate' in file_.orig_metadata:
        info.append((_('Sample rate:'), '%s Hz' % file_.orig_metadata['~sample_rate']))
    if '~bits_per_sample' in file_.orig_metadata:
        info.append((_('Bits per sample:'), str(file_.orig_metadata['~bits_per_sample'])))
    if '~channels' in file_.orig_metadata:
        ch = file_.orig_metadata['~channels']
        if ch == '1':
            ch = _('Mono')
        elif ch == '2':
            ch = _('Stereo')
        info.append((_('Channels:'), ch))
    return '<br/>'.join(map(lambda i: '<b>%s</b> %s' %
                            (htmlescape(i[0]),
                             htmlescape(i[1])), info))
Example #5
0
def _get_form(title, action, label, form_data):
    return _form_template.format(
        title=htmlescape(title),
        submit_label=htmlescape(label),
        action=htmlescape(build_submission_url(action)),
        form_data=_format_form_data(form_data),
    )
Example #6
0
    def _display_info_tab(self):
        tab = self.ui.info_tab
        cluster = self.obj
        tabWidget = self.ui.tabWidget
        tab_index = tabWidget.indexOf(tab)
        tabWidget.setTabText(tab_index, _("&Info"))
        info = []
        info.append("<b>%s</b> %s" %
                    (_('Album:'), htmlescape(cluster.metadata["album"])))
        info.append(
            "<b>%s</b> %s" %
            (_('Artist:'), htmlescape(cluster.metadata["albumartist"])))
        info.append("")
        TrackListItem = namedtuple('TrackListItem',
                                   'tracknumber, title, artist, length')
        tracklists = defaultdict(list)
        for file_ in cluster.iterfiles(False):
            m = file_.metadata
            artist = m["artist"] or m["albumartist"] or cluster.metadata[
                "albumartist"]
            track = TrackListItem(m["tracknumber"], m["title"], artist,
                                  m["~length"])
            tracklists[file_.discnumber].append(track)

        def sorttracknum(item):
            try:
                return int(item.tracknumber)
            except ValueError:
                try:
                    # This allows to parse values like '3' but also '3/10'
                    m = re.search(r'^\d+', item.tracknumber)
                    return int(m.group(0))
                except AttributeError:
                    return 0

        ndiscs = len(tracklists)
        for discnumber in sorted(tracklists):
            tracklist = tracklists[discnumber]
            if ndiscs > 1:
                info.append("<b>%s</b>" % (_('Disc %d') % discnumber))
            lines = [
                "%s %s - %s (%s)" % item
                for item in sorted(tracklist, key=sorttracknum)
            ]
            info.append(
                "<b>%s</b><br />%s<br />" % (_('Tracklist:'), '<br />'.join(
                    [htmlescape(s).replace(' ', '&nbsp;') for s in lines])))
        self.ui.info.setText('<br/>'.join(info))
Example #7
0
def format_tracklist(cluster):
    info = []
    info.append("<b>%s</b> %s" %
                (_('Album:'), htmlescape(cluster.metadata["album"])))
    info.append("<b>%s</b> %s" %
                (_('Artist:'), htmlescape(cluster.metadata["albumartist"])))
    info.append("")
    TrackListItem = namedtuple('TrackListItem',
                               'number, title, artist, length')
    tracklists = defaultdict(list)
    if isinstance(cluster, Album):
        objlist = cluster.tracks
    else:
        objlist = cluster.iterfiles(False)
    for obj_ in objlist:
        m = obj_.metadata
        artist = m["artist"] or m["albumartist"] or cluster.metadata[
            "albumartist"]
        track = TrackListItem(m["tracknumber"], m["title"], artist,
                              m["~length"])
        tracklists[obj_.discnumber].append(track)

    def sorttracknum(track):
        try:
            return int(track.number)
        except ValueError:
            try:
                # This allows to parse values like '3' but also '3/10'
                m = re.search(r'^\d+', track.number)
                return int(m.group(0))
            except AttributeError:
                return 0

    ndiscs = len(tracklists)
    for discnumber in sorted(tracklists):
        tracklist = tracklists[discnumber]
        if ndiscs > 1:
            info.append("<b>%s</b>" % (_('Disc %d') % discnumber))
        lines = [
            "%s %s - %s (%s)" % item
            for item in sorted(tracklist, key=sorttracknum)
        ]
        info.append(
            "<b>%s</b><br />%s<br />" % (_('Tracklist:'), '<br />'.join(
                [htmlescape(s).replace(' ', '&nbsp;') for s in lines])))
    return '<br/>'.join(info)
Example #8
0
 def _display_info_tab(self):
     tab = self.ui.info_tab
     cluster = self.obj
     tabWidget = self.ui.tabWidget
     tab_index = tabWidget.indexOf(tab)
     tabWidget.setTabText(tab_index, _("&Info"))
     info = []
     info.append("<b>%s</b> %s" % (_('Album:'),
                                   htmlescape(cluster.metadata["album"])))
     info.append("<b>%s</b> %s" % (_('Artist:'),
                                   htmlescape(cluster.metadata["albumartist"])))
     info.append("")
     lines = []
     for file in cluster.iterfiles(False):
         m = file.metadata
         artist = m["artist"] or m["albumartist"] or cluster.metadata["albumartist"]
         lines.append(m["tracknumber"] + " " +
                      m["title"] + " - " + artist + " (" +
                      m["~length"] + ")")
     info.append("<b>%s</b><br />%s" % (_('Tracklist:'),
                 '<br />'.join([htmlescape(s).replace(' ', '&nbsp;') for s in lines])))
     self.ui.info.setText('<br/>'.join(info))
Example #9
0
 def _display_info_tab(self):
     tab = self.ui.info_tab
     cluster = self.obj
     tabWidget = self.ui.tabWidget
     tab_index = tabWidget.indexOf(tab)
     tabWidget.setTabText(tab_index, _("&Info"))
     info = []
     info.append("<b>%s</b> %s" % (_('Album:'),
                                   htmlescape(cluster.metadata["album"])))
     info.append("<b>%s</b> %s" % (_('Artist:'),
                                   htmlescape(cluster.metadata["albumartist"])))
     info.append("")
     lines = []
     for file in cluster.iterfiles(False):
         m = file.metadata
         artist = m["artist"] or m["albumartist"] or cluster.metadata["albumartist"]
         lines.append(m["tracknumber"] + u" " +
                      m["title"] + " - " + artist + " (" +
                      m["~length"] + ")")
     info.append("<b>%s</b><br />%s" % (_('Tracklist:'),
                 '<br />'.join([htmlescape(s).replace(' ', '&nbsp;') for s in lines])))
     self.ui.info.setText('<br/>'.join(info))
Example #10
0
 def _display_info_tab(self):
     tab = self.ui.info_tab
     album = self.obj
     tabWidget = self.ui.tabWidget
     tab_index = tabWidget.indexOf(tab)
     if album.errors:
         tabWidget.setTabText(tab_index, _("&Errors"))
         text = '<br />'.join(
             map(
                 lambda s: '<font color="darkred">%s</font>' % '<br />'.
                 join(
                     htmlescape(str(s)).replace('\t', ' ').replace(
                         ' ', '&nbsp;').splitlines()), album.errors))
         self.ui.info.setText(text + '<hr />')
     else:
         tabWidget.setTabText(tab_index, _("&Info"))
         self.tab_hide(tab)
Example #11
0
 def _display_info_tab(self):
     tab = self.ui.info_tab
     album = self.obj
     tabWidget = self.ui.tabWidget
     tab_index = tabWidget.indexOf(tab)
     if album.errors:
         tabWidget.setTabText(tab_index, _("&Errors"))
         text = '<br />'.join(map(lambda s: '<font color="darkred">%s</font>' %
                                  '<br />'.join(htmlescape(str(s))
                                                .replace('\t', ' ')
                                                .replace(' ', '&nbsp;')
                                                .splitlines()
                                                ), album.errors)
                              )
         self.ui.info.setText(text + '<hr />')
     else:
         tabWidget.setTabText(tab_index, _("&Info"))
         self.tab_hide(tab)
Example #12
0
def text_as_html(text):
    return '<br />'.join(
        htmlescape(str(text)).replace('\t',
                                      ' ').replace(' ', '&nbsp;').splitlines())
Example #13
0
def _format_form_data(data):
    return ''.join((
        _form_input_template.format(name=htmlescape(name), value=htmlescape(value))
        for name, value in data.items()
    ))