def row(self): """ 歌曲摘要信息,列出搜索歌曲时使用PrettyTable """ keywords = re.split(";|,|\s|\*", config.get("keyword")) def highlight(s, k): return s.replace(k, colorize(k, "xiami")).replace( k.title(), colorize(k.title(), "xiami")) ht_singer = self.singer if len( self.singer) < 30 else self.singer[:30] + "..." ht_title = self.title if len( self.title) < 30 else self.title[:30] + "..." ht_album = self.album if len( self.album) < 20 else self.album[:20] + "..." for k in keywords: if not k: continue ht_singer = highlight(ht_singer, k) ht_title = highlight(ht_title, k) ht_album = highlight(ht_album, k) size = "%sMB" % self.size ht_size = size if int(self.size) < 8 else colorize(size, "flac") return [ colorize(self.idx, "baidu"), ht_singer, ht_title, ht_size, self.duration, ht_album, self.source.upper(), ]
def test_color(): if platform.system() == "Windows": assert utils.colorize("music-dl", "qq") == "music-dl" assert utils.colorize(1234, "qq") == "1234" else: assert utils.colorize("music-dl", "qq") == "\033[92mmusic-dl\033[0m" assert utils.colorize(1234, "xiami") == "\033[93m1234\033[0m" assert utils.colorize("music-dl", "fsadfasdg") == "music-dl"
def __str__(self): """ 在打印详情时调用 """ idx = colorize("[ %s ] " % self.idx, "cyan") source = colorize("%s" % self.source.upper(), self.source) return "\n ------------ \n" + _(" -> 来源: {idx}{source} #{id}\n" " -> 歌曲: {title}\n" " -> 歌手: {singer}\n" " -> 专辑: {album}\n" " -> 时长: {duration}\n" " -> 大小: {size}MB\n" " -> 比特率: {rate}\n" " -> URL: {url} \n").format( idx=idx, source=source, id=self.id, title=self.title, singer=self.singer, album=self.album, duration=self.duration, size=self.size, rate=self.rate, url=self.url, )
def info(self): """ 歌曲摘要信息,列出搜索歌曲时使用 """ idx = colorize(" [ %2s ] " % self.idx, "cyan") source = colorize("%7s" % self.source.upper(), self.source) size = colorize("%5sMB" % self.size, "yellow") title = colorize(self.title, "yellow") v = colorize(" | ", self.source) h = colorize(" - ", self.source) return (idx + source + v + self.duration + h + size + h + self.singer + h + title + h + self.album)
def highlight(s, k): return s.replace(k, colorize(k, "xiami")).replace( k.title(), colorize(k.title(), "xiami"))