diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d1502b0..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -vendor/ -composer.lock diff --git a/README.md b/README.md index f9be2b2..28bbc28 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ This prorgam downloads a new image from [Unsplash][1]. It checks whether the scr ## Dependencies -+ [PHP][2] - Available in repositories of most popular distributions. -+ [Composer][3] - Available in repositories of most popular distributions. ++ [jq][2] - Needed for parsing JSON. ++ [curl][3] - Available in most software repositories. Also, most probably installed already. + [Imagemagick][4] - Specifically, the `convert` command. + [i3lock-color][5] - Available in AUR (For Arch users). Fork of i3lock with more features. Do not use i3lock since this program utilizes the features of i3lock-color. + [bash][6] - Most probably will be installed already. @@ -49,8 +49,8 @@ The lock screen customization has been made easier using `~/.config/lock_prefere [1]: https://unsplash.com -[2]: https://php.net -[3]: https://getcomposer.org +[2]: https://stedolan.github.io/jq/ +[3]: https://curl.haxx.se [4]: https://imagemagick.org [5]: https://github.com/PandorasFox/i3lock-color [6]: https://www.gnu.org/software/bash/ diff --git a/composer.json b/composer.json deleted file mode 100644 index 11acbd8..0000000 --- a/composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require": { - "crewlabs/unsplash": "^2.4" - } -} diff --git a/download_daemon b/download_daemon index af99835..a6a7cf9 100755 --- a/download_daemon +++ b/download_daemon @@ -11,7 +11,7 @@ while : ; do # If no, wait 300 secs and check again. [[ `< $HOME/.config/lock_screen.sta` -eq 0 ]] && sleep 300 && continue # Download the new image - $HOME/i3lock-delta/downloader.php + $HOME/i3lock-delta/downloader.sh if [[ $? -eq 0 ]]; then name_photographer="`< /tmp/name_photographer`" diff --git a/downloader.php b/downloader.php deleted file mode 100755 index 6639774..0000000 --- a/downloader.php +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env php - file_get_contents(getenv('HOME').'/i3lock-delta/api_key'), - 'utmSource' => 'i3lock-Delta' -]); - -# Get custom search queries -$queries_file_name = getenv('HOME') . '/.config/lock_preferences'; -$queries = file($queries_file_name); - -# Create the random photo limitations -if (count($queries) == 0){ - $filters = [ - 'featured' => false, - 'orientation' => 'landscape' - ]; -} -else { - $filters = [ - 'featured' => false, - 'query' => $queries[rand(0,count($queries) - 1)], - 'orientation' => 'landscape' - ]; -} - -# Get the random photo -$img = Crew\Unsplash\Photo::random($filters); - -# Download the photo -$url = $img->download(); -$output = file_get_contents($url); - -# Write image to a file -$image_filename =getenv('HOME') . '/.rand_bg'; -$image_file = fopen($image_filename, 'w'); -fwrite($image_file, $output); -fclose($image_file); - -# Write author's name to a file -$name_file = fopen('/tmp/name_photographer', 'w'); -fwrite($name_file, $img->{'user'}['name']); -fclose($name_file); diff --git a/downloader.sh b/downloader.sh new file mode 100755 index 0000000..da97d8e --- /dev/null +++ b/downloader.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Get the api key +key=$(cat ~/i3lock-delta/api_key) +# Get the queries +queries=$(cat ~/.config/lock_preferences | xargs) +# Construct the base url +url="https://api.unsplash.com/photos/random?client_id=$key&orientation=landscape&featured=false" + +# Check if there are any queries +if [ -n "$queries" ]; then + url="$url&query=$(shuf -n 1 ~/.config/lock_preferences)" +fi + +# make API call and check if curl fails +if ! json=$(curl -s $url); then + exit 1 +fi + +# Get image location from json +image_download_url=$(echo $json | jq -r ".links.download_location") +image_download_url="$image_download_url?client_id=$key" +image_url=$(curl -s $image_download_url | jq -r .url) +if [[ $? -ne 0 ]] ; then exit 1; fi + +# Download image and check if curl fails +curl $image_url > ~/.rand_bg +if [[ $? -ne 0 ]] ; then exit 1; fi + +# Write author's name to file +user_name=$(echo $json | jq -r ".user.name") +echo "$user_name" > /tmp/name_photographer diff --git a/install b/install index 83d2102..80c78bf 100755 --- a/install +++ b/install @@ -17,8 +17,8 @@ function check_exec() { echo -e "${blue}Checking Dependencies $reset" -check_exec php PHP -check_exec composer Composer +check_exec jq jq +check_exec curl curl check_exec i3lock i3lock-color check_exec convert Imagemagick @@ -33,16 +33,6 @@ else echo "OK" fi echo -e "${blue}Checked repository location $reset \n" -echo -e "${blue}Installing Libraries $reset" -sleep 1 -composer install -if [[ $? -ne 0 ]]; then - echo -e "$red Unable to install libraries. Check your internet connection" - echo -e "If the problem persists, open an issue at https://github.com/Ceda-EI/i3lock-delta/issues" - echo -e "$reset" -fi - -echo -e "${blue}Finished Installing Libraries $reset \n" echo -e "${blue}Creating Required Files$reset"