Android YouTube Image Wallpaper

 Android YouTube Image Wallpaper


Why

I've been using a live view of the beautiful Charles River in Boston as my Android wallpaper and lockscreen image for about a year now. Beside being beautiful, this gives me an idea of the weather when I'm not near a window. Up until yesterday, I was using the great app HelloMundo. HelloMundo periodically grabs any image (not video) from the web and uses that as the Android wallpaper and lockscreen image. Yesterday, HelloMundo stopped working. It could be that the image source I was using from the Museum of Science went away to be replaced by a live streaming YouTube video. I figured there must be some combination of open source tools plus Tasker that I could use to replace this functionality.

How

Parts List





Credits

This entire project is based on this excellent post.

Get a Single Frame from a YouTube Video

This is done with a combination of youtube-dl and ffmpeg. youtube-dl gets the video and ffmpeg saves one frame as an image at the timestamp you specify. For a live streaming video like mine, the timestamp is alway 0:00.

ffmpeg -ss "0:00" -i $(youtube-dl -f 95 --get-url \
 "https://www.youtube.com/watch?v=6NztDtxqbLI") \
 -vframes 1 -q:v 2 -y "/usr/local/ampps/www/MOS.jpg"

(I placed a few escaped newlines, "\", in that command for the post. Feel free to remove them.)

The -ss is followed by the video timestamp, the -f is which quality video to download (use -F to list all possible qualities), the -vframes is how many frames to save and the -y is to where to save the frame. I save the frame to the DocumentRoot of my Apache web server on the same machine. MOS is short for Museum of Science as that is where the webcam is located. BTW, this command takes 4 minutes to run regardless of video quality.

Add a Timestamp Watermark to the Image

I wanted to know how current the image is that ends up being my "Weather Conditions Wallpaper". I found that Imagemagick can add anything as a watermark, so I used Imagemagick to add the current date and time to the image.

convert /usr/local/ampps/www/MOS.jpg -fill white -pointsize 20 \
 -annotate +10+670  "`date`" /usr/local/ampps/www/MOS_Date.jpg
 
Pretty self-explanatory command. Add the current date and time in white at position 10,670 to the image resulting in a new image.

Create a Shell Script and Run Every 30 Minutes

I added those two commands to a shell script I named get_mos_frame.sh and added a cron entry to run every 30 minutes. You use the crontab -e command to add an entry to cron.

# Pull a frame from the MOS live stream every 30 minutes and drop in web root for Tasker
*/30 * * * * /bin/bash /home/dennis/get_mos_frame.sh > /dev/null 2>&1

Create Task and Profile in Tasker to Get and Use the Image



This is pretty standard if you have used Tasker before. I have included the full Tasker XML export below for you to import into your copy of Tasker. Just change the task to reflect the IP/FQDN of your web server. 

  • Create a Tasker HTTP Request Task that gets the image from your webserver, updates wallpaper, updates lockscreen
  • Create a Tasker Profile to run this task every N minutes. I set my profile to run every 15 minutes as I was not sure if I would miss the 30 minute cron job by one minute and be 59 minutes behind. 

Tasker XML for Import

<TaskerData sr="" dvi="1" tv="5.10.1">
<Profile sr="prof6" ve="2">
<cdate>1605990887932</cdate>
<clp>true</clp>
<edate>1605991283130</edate>
<flags>8</flags>
<id>6</id>
<mid0>5</mid0>
<nme>Wallpaper 15 Minutes</nme>
<Time sr="con0">
<fh>5</fh>
<fm>0</fm>
<rep>2</rep>
<repval>15</repval>
<th>22</th>
<tm>0</tm>
</Time>
</Profile>
<Task sr="task5">
<cdate>1605964424125</cdate>
<edate>1605994753024</edate>
<id>5</id>
<nme>Wallpaper</nme>
<pri>6</pri>
<Action sr="act0" ve="7">
<code>339</code>
<Bundle sr="arg0">
<Vals sr="val">
<net.dinglisch.android.tasker.RELEVANT_VARIABLES>&lt;StringArray sr=""&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;%http_file_output
File Output
Will always contain the file's full path even if you specified a directory as the File to save.&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;%http_response_code
Response Code
The HTTP Code the server responded&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;%http_cookies
Cookies
The cookies the server sent in the response in the Cookie:COOKIE_VALUE format. You can use this directly in the 'Headers' field of the HTTP Request action&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3&gt;%http_headers()
Response Headers
The HTTP Headers the server sent in the response. Each header is in the 'key:value' format&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES4&gt;%http_response_length
Response Length
The size of the response in bytes&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES4&gt;&lt;/StringArray&gt;</net.dinglisch.android.tasker.RELEVANT_VARIABLES>
<net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>[Ljava.lang.String;</net.dinglisch.android.tasker.RELEVANT_VARIABLES-type>
</Vals>
</Bundle>
<Int sr="arg1" val="0"/>
<Int sr="arg10" val="0"/>
<Int sr="arg11" val="0"/>
<Str sr="arg2" ve="3">http://[IP-OF-YOUR-WEBSERVER]/MOS_Date.jpg</Str>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3">Pictures/Wallpapers</Str>
<Int sr="arg8" val="30"/>
<Int sr="arg9" val="0"/>
</Action>
<Action sr="act1" ve="7">
<code>109</code>
<Int sr="arg0" val="0"/>
<Str sr="arg1" ve="3">Pictures/Wallpapers/MOS_Date.jpg</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act2" ve="7">
<code>109</code>
<Int sr="arg0" val="1"/>
<Str sr="arg1" ve="3">Pictures/Wallpapers/MOS_Date.jpg</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
</Task>
</TaskerData>

Thank You

That's it. Not earth-shattering, but I thought writing this down might help someone else. Thank you for taking the time to read this post and I welcome your feedback.

Comments