惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
Webroot Blog
Webroot Blog
MongoDB | Blog
MongoDB | Blog
AI
AI
WordPress大学
WordPress大学
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
L
LINUX DO - 最新话题
T
Troy Hunt's Blog
J
Java Code Geeks
F
Fortinet All Blogs
The Cloudflare Blog
Cisco Talos Blog
Cisco Talos Blog
S
SegmentFault 最新的问题
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
M
MIT News - Artificial intelligence
The Hacker News
The Hacker News
G
GRAHAM CLULEY
H
Hacker News: Front Page
V
Vulnerabilities – Threatpost
L
Lohrmann on Cybersecurity
P
Privacy International News Feed
N
News and Events Feed by Topic
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
T
Threatpost
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
S
Securelist
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Project Zero
Project Zero
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Tailwind CSS Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
A
About on SuperTechFans
Simon Willison's Weblog
Simon Willison's Weblog

K.I.S.S

身在 Kimi 的 800 天 写在 Kimi K2 发布之后:再也不仅仅是 ChatBot macOS 按域名切换 DNS 解析 | K.I.S.S 为什么说 GPT 是无损压缩 | K.I.S.S 握着你的手训一个类GPT语言模型 (二) | K.I.S.S 握着你的手训一个类GPT语言模型 (一) | K.I.S.S Rosetta in Linux Virtual Machine on Apple Silicon Fit an Overfit with MegEngine 把 CUPS 扔进 docker 里 ASUS Chromebook Flip | K.I.S.S GPG 与 SSH Agent 转发 使用 dnsmasq 和 ipset 的策略路由 YubiKey 4 简介与配置 | K.I.S.S 定制GH60机械键盘 | K.I.S.S Debian 网络安装内核参数 | K.I.S.S 我的 Vim 配置 | K.I.S.S Libinput 与 Udev | K.I.S.S 给妹子看的 Arch Linux 桌面日常安装 | K.I.S.S 修复GTK3 CSD外观 | K.I.S.S 握着你的手教你画哀女王 | K.I.S.S R.I.P Google Reader | K.I.S.S Richard Stallman仍然是对的 | K.I.S.S Scala 自定义控制结构 | K.I.S.S 入手Wacom Bamboo CTL470 | K.I.S.S 转个型? | K.I.S.S Wish List | K.I.S.S pulseaudio音量问题 | K.I.S.S 入手yubikey,一点小心得 | K.I.S.S 迁移到Octopress | K.I.S.S 自动更新DNSPod记录 | K.I.S.S Linux 用作 IPv6 网关 | K.I.S.S 我和Linus大学时那些事儿 | K.I.S.S Micro$oft依然是那副老德行 | K.I.S.S 用PulseAudio TCP Forwarding实现网络传声 | K.I.S.S 利用tmpfs加速gnome-shell overview模式Applications索引 | K.I.S.S 新的短网址 | K.I.S.S 紧张的一个月 | K.I.S.S 5月11日活动有感 | K.I.S.S 西电开源社区2011年Tee 最终版 | K.I.S.S 多头多尾的Linux | K.I.S.S Linux的中文名称怎么翻译呢? | K.I.S.S iPhone使用OpenVPN | K.I.S.S 我的人人网敏感词 | K.I.S.S 纪念钱立生老师 | K.I.S.S twitter键盘控:Twittperator | K.I.S.S 天生的暴力倾向? | K.I.S.S The Open Source Spirit | K.I.S.S Libreoffice | K.I.S.S Hello world! | K.I.S.S Python 调用gnuplot的例子 | K.I.S.S The Beginning | K.I.S.S About Me | K.I.S.S
Conky从豆瓣获取MPD专辑封面 | K.I.S.S
2011-10-03 · via K.I.S.S

昨天回到Openbox了,GNOME 3.2 扩展不兼容让我这个不搞定不舒服司机的人实在太难受,又不想再去学gjs,所以干脆眼不见为净了。

过去在OB下最爱折腾的东西莫过于conky,昨天除了恢复了一下过去的conky配置,就是further折腾… 看conky-colors又出新版本,的确很炫,所以也想把自己的改改,不过实际需求上,估计也就是比较想要一个音乐的CoverArt。

我用的MPD,conky-colors里貌似不带mpd的cover脚本,google之,发现mpd的也已经有人发明过啦~

不过有一点不爽,这个脚本是从albumart下载封面,对中文支持有限,所以想从豆瓣获取封面,所以参考这个脚本做了一些更改。

折腾控是不会喜欢压缩文件的,所以……直接贴代码吧

cover.py:获取封面

#!/usr/bin/python2
# -*- encoding:utf8 -*-

import os
import shutil
import commands
import urllib
import re
import sys
urlread = lambda url: urllib.urlopen(url).read()

def copycover(currentalbum, src, dest, defaultfile):
    _doubanSearchApi    = 'http://www.douban.com/search?search_text={0}'
    _doubanCoverPattern = '<img src="http://img[0-9].douban.com/spic/s(\d+).jpg"'
    _doubanConverAddr   = 'http://img3.douban.com/lpic/s{0}.jpg'
    searchstring = urllib.quote(currentalbum)
    
    if not os.path.exists(src):
        request = _doubanSearchApi.format(searchstring)
        result = urlread(request)
        match = re.compile(_doubanCoverPattern, re.IGNORECASE).search(result)
        if match:
            image = _doubanConverAddr.format(match.groups()[0])
            urllib.urlretrieve(image, src)
    
    if os.path.exists(src):
        shutil.copy(src, dest)
    elif os.path.exists(defaultfile):
        shutil.copy(defaultfile, dest)
    else:
        print ""

def escape(cmd):
    ''' escape bash special chars '''
    p=re.compile(r'([\$\(\)\ \;\'"`{}])')
    cmd = p.sub('XXXXX\g<1>',cmd)
    p=re.compile(r'XXXXX')
    esc_cmd = p.sub(r'\\\',cmd)
    return esc_cmd

def notify(cover):
    raw = commands.getoutput("mpc --format %title%---%artist%---%album% | head -n 1")
    raw = escape(raw)
    #print >> sys.stderr, raw
    title,artist,alb = raw.split( '---' )
    cmd="notify-send -i %s %s \"%s\\n%s\" " % (cover,title,artist,alb)
    #print >> sys.stderr, cmd
    os.system( cmd ) 

# Path where the images are saved
imgpath = os.getenv("HOME") + "/.covers/"

# image displayed when no image found
noimg = imgpath + "nocover.png"

# Cover displayed by conky
cover = "/tmp/cover"

# Name of current album
album = commands.getoutput("mpc --format %artist%-%album% | head -n 1")
title = commands.getoutput("mpc --format %title%|head -n 1")
# If tags are empty, use noimg.
if album == "":
    if os.path.exists(cover):
        os.remove(cover)
    if os.path.exists(noimg):
        shutil.copy(noimg, cover)
    else:
        print ""
else:

    filename = imgpath + album + ".jpg"
    if os.path.exists("/tmp/nowplaying") and os.path.exists("/tmp/cover"):
        nowplaying = open("/tmp/nowplaying").read()
        if nowplaying == album:
            open("/tmp/change","w").write('0')
            pass
        else:
            copycover(album, filename, cover, noimg)
            open("/tmp/change","w").write('1')
            open("/tmp/nowplaying", "w").write(album)
    else:
        copycover(album, filename, cover, noimg)
        open("/tmp/change","w").write('1')
        open("/tmp/nowplaying", "w").write(album)
    
    if os.path.exists("/tmp/nowsong"):
        nowsong = open("/tmp/nowsong").read()
        if nowsong != title:
            if(sys.argv[1]=="-n"):
                notify(cover)
            open("/tmp/nowsong","wc").write(title)
    else:
        if(sys.argv[1]=="-n"):
            notify(cover)
        open("/tmp/nowsong","wc").write(title)

conkyVinyl.sh:用imagemagick对图片做些修改

#!/bin/bash
#
# Album art with cd theme in conky
# by helmuthdu

player="/tmp/cover"
cover="/tmp/conkyCover.png"

picture_aspect=$(($(identify -format %w "$cover")-$(identify -format %h "$cover")))

if [ ! -f "$player" ]; then
	convert ~/.conky/Vinyl/base.png ~/.conky/Vinyl/top.png -geometry +0+0 -composite "$cover"
else
	cp "$player" "$cover"
	if [ "$picture_aspect" = "0" ]; then
		convert "$cover"  -thumbnail 86x86 "$cover"
	elif [ "$picture_aspect" -gt "0" ]; then
		convert "$cover"  -thumbnail 300x86 "$cover"
		convert "$cover" -crop 86x86+$(( ($(identify -format %w "$cover") - 86) / 2))+0  +repage "$cover"
	else
		convert "$cover"  -thumbnail 86x500 "$cover"
		convert "$cover" -crop 86x86+0+$(( ($(identify -format %h "$cover") - 86) / 2))  +repage "$cover"
	fi
	convert ~/.conky/Vinyl/base.png "$cover" -geometry +4+3 -composite ~/.conky/Vinyl/top.png -geometry +0+0 -composite "$cover"
fi

exit 0

使用的时候,在conky里加入

#禁用图片缓存,这句加在conky的"TEXT"之前
imlib_cache_size 0
#这句插入到需要的地方
${texeci 10 ~/.conky/cover.py && ~/.conky/conkyVinyl.sh}${image /tmp/conkyCover.png -p 40,395}

写到这里突然想起来有两个二进制文件(图片素材),好吧,我还是把压缩包发上来把…… conky_mpd.zip