Skip to content

Commit a87f9ad

Browse files
committed
Get images from flickr when in random mode
1 parent 1696be5 commit a87f9ad

File tree

2 files changed

+67
-16
lines changed

2 files changed

+67
-16
lines changed

debian/changelog

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
izulu (0.5) trusty; urgency=low
1+
izulu (0.6) trusty; urgency=low
22

33
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>
44

izulu

+66-15
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ setWallpaper() {
225225
if [[ -n "$random_image" ]];then
226226
setImage "$random_image" &
227227
fi
228+
osdNotify "$specific"
228229
return
229230
fi
230231

@@ -249,10 +250,8 @@ setWallpaper() {
249250
fi
250251
fi
251252
fi
252-
253-
if [ "$OSD" == "TRUE" ];then
254-
osdNotify "$specific"
255-
fi
253+
254+
osdNotify "$specific"
256255
}
257256

258257
# set the Wallpaper
@@ -393,15 +392,17 @@ contains() {
393392
#send onscreen-notfication if weather changed
394393
#$1: message, new weather-state
395394
osdNotify() {
396-
if [[ -z "$last_state" ]] || [ "$last_state" != "$1" ];then
397-
if command -v notify-send > /dev/null;then
398-
notify-send "izulu" "$(gettext "$1")"
399-
else
400-
echo "notify-send not installed, but osd via -o requested." \
401-
"Install libnotify-bin to use the osd."
395+
if [ "$OSD" == "TRUE" ];then
396+
if [[ -z "$last_state" ]] || [ "$last_state" != "$1" ];then
397+
if command -v notify-send > /dev/null;then
398+
notify-send "izulu" "$(gettext "$1")"
399+
else
400+
echo "notify-send not installed, but osd via -o requested." \
401+
"Install libnotify-bin to use the osd."
402+
fi
402403
fi
404+
last_state="$1"
403405
fi
404-
last_state="$1"
405406
}
406407

407408
#choose randomly a wallpaper
@@ -431,8 +432,13 @@ cycleWallpaper() {
431432
esac
432433

433434
if [[ -z "$randomdir" ]];then
434-
setWallpaper "$specific" "$generic" "TRUE"
435-
return 1
435+
flickrimg=$(getFlickrImage "$generic")
436+
if [[ -z "$flickrimg" ]];then
437+
setWallpaper "$specific" "$generic" "TRUE"
438+
return 1
439+
else
440+
echo "$flickrimg"
441+
fi
436442
fi
437443

438444

@@ -446,6 +452,51 @@ cycleWallpaper() {
446452
echo "${pictures[$chosen]}"
447453
}
448454

455+
getFlickrImage() {
456+
local generic="$1"
457+
# flickriver sorts the flickr groups images randomly for us
458+
local riverurl=""
459+
case "$generic" in
460+
"gen_sun")
461+
riverurl="http://www.flickriver.com/groups/982364@N21/pool/random/"
462+
;;
463+
"gen_cloud")
464+
riverurl="http://www.flickriver.com/groups/clouds-mildness/pool/random/"
465+
;;
466+
"gen_rain")
467+
riverurl="http://www.flickriver.com/groups/387174@N22/pool/random/"
468+
;;
469+
"gen_snow")
470+
riverurl="http://www.flickriver.com/groups/snow_pictures/pool/random/"
471+
;;
472+
"gen_wind")
473+
riverurl="http://www.flickriver.com/groups/1159117@N24/pool/random/"
474+
;;
475+
*)
476+
# misc, mainly fog
477+
riverurl="http://www.flickriver.com/groups/1040464@N23/pool/random/"
478+
;;
479+
esac
480+
local flickrpage=$(wget -O - --quiet $(wget -O - "$riverurl" --quiet | grep "class=\"noborder\" target=\"_blank\".*http://www.flickr.com/photos" | sed 's#.*href=\"\([^\"]*\)\".*#\1#g' | uniq | shuf -n 1))
481+
local imagesizes=$(echo -e "$flickrpage" | grep Y.photo.init | sed 's#.*Y.photo.init(\(.*\));#\1#g' | tr "}" "\n")
482+
for size in "Large 2048" "Original" "Large 1600" "Large\"";do
483+
# not all flickr images provide every size, so we try to get the best one
484+
# It is nicer to prefer a size with a specific width, that is why Original is not first
485+
local imageurl=$(echo -e "$imagesizes" | grep "$size" | sed -e 's#.*\(http[^"]*\).*"#\1#g' -e 's#\\##g')
486+
if [[ -n "$imageurl" ]];then
487+
break
488+
fi
489+
done
490+
if [[ -z "$imageurl" ]];then
491+
return 1
492+
fi
493+
if [[ -z "$FLICKRTMP" ]];then
494+
FLICKRTMP=$(mktemp)
495+
fi
496+
wget -O "$FLICKRTMP" "$imageurl" --quiet
497+
echo "$FLICKRTMP"
498+
}
499+
449500

450501
#get current time via the last_build_date, which is not necesseraly the
451502
#current time
@@ -747,7 +798,7 @@ while [[ $# -gt 0 ]] ; do
747798
-p, --preview
748799
Add images showing the weather forecast.
749800
-r, --random:
750-
Choose the wallpaper randomly, only works when the directory is named in the config.
801+
Choose the wallpaper randomly. If no directory is named in the config, it will try to get a fitting image from flickr.
751802
-rd [warning|radar] [warning|radar] [germany|swiss], --radar [warning|radar] [warning|radar] [germany|swiss]:
752803
Show a warning and/or a radarimage for a country. Wetteralarm (www.wetteralarm.ch) and Rain-Radar (meteoschweiz.admin.ch) for Switzerland, official warnings (http://www.dwd.de/) and a satellite-image (http://www.dlr.de/) for Germany.
753804
-sr, --swiss-radar
@@ -766,7 +817,7 @@ while [[ $# -gt 0 ]] ; do
766817
;;
767818

768819
--version)
769-
echo "izulu 0.5.0"
820+
echo "izulu 0.6.0"
770821
exit 0
771822
;;
772823
esac

0 commit comments

Comments
 (0)