-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathget-bing-wallpaper
executable file
·67 lines (52 loc) · 1.91 KB
/
get-bing-wallpaper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# export {http,https,ftp}_proxy=http://127.0.0.1:7777
# The market, can be "en-US" "zh-CN" "ja-JP" "en-AU" "en-UK" "de-DE" "en-NZ" "en-CA"
mkt="en-US"
bing="www.bing.com"
# The idx parameter determines where to start from. 0 is the current day,
# 1 the previous day, etc.
idx="0"
# $xmlURL is needed to get the xml data
xmlURL="http://www.bing.com/HPImageArchive.aspx?format=xml&idx=$idx&n=1&mkt=$mkt"
# $saveDir is used to set the location where Bing pics of the day are stored.
saveDir=$HOME'/Pictures/Bing/'
# Create saveDir if it does not already exist
mkdir -p $saveDir
# Extract the relative URL of the Bing pic of the day
xml=$(curl "$bing/HPImageArchive.aspx?format=rss&idx=$idx&n=1&mkt=$mkt")
picUrl=$bing$( \
echo $xml\
| xmllint --xpath "/rss/channel/item/link/text()" - \
| sed 's/1366x768/1920x1080/g' \
)
# Get title, remove copyright notice and html entities
picTitle=$( \
echo $xml\
| xmllint --xpath "/rss/channel/item/title/text()" - \
| sed s/'([^)]*)'/''/g \
| perl -MHTML::Entities -e 'while(<>) {print decode_entities($_);}'\
)
picName="${picUrl##*/}"
# Download the Bing pic of the day
cd $saveDir && curl -O $picUrl
# Test if download was successful.
downloadResult=$?
if [[ $downloadResult -ge 1 ]]; then
rm -rf $saveDir$picName
echo "Couldn't download any picture."
exit 1;
fi
# Test if it's a pic
file --mime-type -b $saveDir$picName | grep "^image/" > /dev/null
downloadResult=$?
if [[ $downloadResult -ge 1 ]]; then
rm -rf $saveDir$picName
echo "Downloaded file is not an image."
exit 1;
fi
# Add title to image
width=$(identify -format %w $saveDir$picName)
height=$(identify -format %h $saveDir$picName)
convert -background '#0008' -fill white -gravity center -size $(($width/4))x$(($height/6)) -font Ubuntu \
caption:"$picTitle" \
$saveDir$picName +swap -gravity east -composite $saveDir$picName