Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions bingwallpaper-nowatermark
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash
# author: Whizzzkid (me@nishantarora.in)
# no-watermark version (a small fix by pizzadude)

# Base URL.
bing="http://www.bing.com"

# API end point.
api="/HPImageArchive.aspx?"

# Response Format (json|xml).
format="&format=js"

# For day (0=current; 1=yesterday... so on).
day="&idx=0"

# Market for image.
market="&mkt=en-US"

# API Constant (fetch how many).
const="&n=1"

# Image extension.
extn=".jpg"

# Size.
size="1920x1080"

# Collection Path.
path="$HOME/Pictures/Bing/"

# Make it run just once (useful to run as a cron)
run_once=false
while getopts "1" opt; do
case $opt in
1 )
run_once=true
;;
\? )
echo "Invalid option! usage: \"$0 -1\", to run once and exit"
exit 1
;;
esac
done

########################################################################
#### DO NOT EDIT BELOW THIS LINE #######################################
########################################################################

# Required Image Uri.
reqImg=$bing$api$format$day$market$const

while [ 1 ]
do

# Logging.
echo "Pinging Bing API..."

# Fetching API response.
apiResp=$(curl -s $reqImg)
if [ $? -gt 0 ]; then
echo "Ping failed!"
exit 1
fi

# Default image URL in case the required is not available.
defImgURL=$bing$(echo $apiResp | grep -oP "url\":\"[^\"]*" | cut -d "\"" -f 3)

# Req image url (raw).
reqImgURL=$bing$(echo $apiResp | grep -oP "urlbase\":\"[^\"]*" | cut -d "\"" -f 3)"_"$size$extn

# Checking if reqImgURL exists.
if ! wget --quiet --spider $reqImgURL; then
reqImgURL=$defImgURL
fi

# Logging.
echo "Bing Image of the day: $reqImgURL"

# Getting Image Name.
imgName=${reqImgURL##*/}

# Create Path Dir.
mkdir -p $path

# Saving Image to collection.
curl -s -o $path$imgName $reqImgURL

# Logging.
echo "Saving image to $path$imgName"

if [ "$XDG_CURRENT_DESKTOP" = "XFCE" ]
then
xres=($(echo $(xfconf-query --channel xfce4-desktop --list | grep last-image)))
for x in "${xres[@]}"
do
xfconf-query --channel xfce4-desktop --property $x --set $path$imgName
done
# Set the wallpaper for unity, gnome3, cinnamon.
elif gsettings set org.gnome.desktop.background picture-uri "file://$path$imgName"; then
#Logging
# Set the view to zoom,
gsettings set org.gnome.desktop.background picture-options "zoom"
else
"$XDG_CURRENT_DESKTOP not supported."
break
fi

echo "New wallpaper set successfully for $XDG_CURRENT_DESKTOP."

# If -1 option was passed just run once
if [ $run_once == true ];then
break
fi

# Re-checks for updates every 3 hours.
sleep 10800
done
37 changes: 27 additions & 10 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
#!/bin/sh
#!/bin/bash

# Stop on errors.
set -e

# Creating Startup Link.
echo $HOME
echo "Registering as startup application..."
echo ""
echo "Do you want no watermarks on your wallpapers? Type Y if you hate them. Type any other key if you love them."
read input
if [[ $input == "Y" || $input == "y" ]]; then
# This should prevent the double entry.
echo "[Desktop Entry]" > "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Type=Application" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Exec=sh /usr/bin/bingwallpaper-nowatermark" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Hidden=false" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "NoDisplay=false" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "X-GNOME-Autostart-enabled=true" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Name=Bing Wallpaper" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Comment=Bing Pic of the day as wallpaper." >> "$HOME/.config/autostart/bingwallpaper.desktop"

else
# This should prevent the double entry.
echo "[Desktop Entry]" > "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Type=Application" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Exec=sh /usr/bin/bingwallpaper" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Hidden=false" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "NoDisplay=false" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "X-GNOME-Autostart-enabled=true" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Name=Bing Wallpaper" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Comment=Bing Pic of the day as wallpaper." >> "$HOME/.config/autostart/bingwallpaper.desktop"
fi

# This should prevent the double entry.
echo "[Desktop Entry]" > "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Type=Application" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Exec=/usr/bin/bingwallpaper" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Hidden=false" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "NoDisplay=false" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "X-GNOME-Autostart-enabled=true" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Name=Bing Wallpaper" >> "$HOME/.config/autostart/bingwallpaper.desktop"
echo "Comment=Bing Pic of the day as wallpaper." >> "$HOME/.config/autostart/bingwallpaper.desktop"

# Misc Info.
echo "All the images will eventually be available at: $HOME/Pictures/Bing/"
echo "Bing wallpaper will be updated on next reboot."
echo "Run \"bingwallpaper\" to update wallpaper now."
echo "Run \"bingwallpaper-nowatermark\" for the no watermark version."

#DEBHELPER#