By following this example you'll be able to get any subreddit's front page image links and use them as wallpapers with Muzei.
In this example we're going to be getting wallpapers from https://www.reddit.com/r/ImaginaryCastles/
Go directly to the last step to see how it looks in the end.
STEP 1 - CREATE TASK AND READ JSON FROM URL
You need to add /.json at the end of a reddit URL so that the data returned is in the JSON format and not a normal HTML page.
- Create a new Task called Reddit Muzei
- Add an AutoTools Json Read action
- Disable simple mode
- In the Json field write https://www.reddit.com/r/ImaginaryCastles/.json
Simple mode is used when reading Json objects in a very easy but more limited way.
In this example we want to read the urls, titles and comment links from the reddit feed.
This is a very simple version of the reddit feed to illustrate the example:
With Simple Mode we could simply set the fields to url,title,permalink and it would get the values. But since there are other fields in the reddit feed with that are named url (in the example above you can see that there is an images array with a source.url field in it) it would not work correctly because AutoTools would also get those fields and it would break the results.Code (Text):
"title": "Messenger Of Iron Islands by Uros Sljivic",
So, because of that, you have to use the "Non-Simple" version to read fields with their full path as seen below so that you get exactly the fields you want.
STEP 2 - SET FIELDS
Each field path has the () suffix so that the fields are returned as arrays. If the prefix hadn't been used, only the first value for each field would be returned.
- In the Fields field write data.children.data.url(),data.children.data.title(),data.children.data.permalink()
Check the Json example above and check out how the path of the field names specified here corresponds to the path in the Json structure.
STEP 3 - ONLY GET IMAGES
This will make AutoTools filter results based on the url field
- Tap Filter at the bottom
- Set the Filter Fields to data.children.data.url
This is a regex that matches any text that has .jpg or .png in it. This will effectively filter out anything that isn't an image with the jpg or png extension
- Set the Filter Value field to (\.jpg)|(\.png) and enable the Regex option
This will make the flash show how many elements the Json Read action returned as well as the first url, title and permalink.
- Go back to Tasker and add a Flash action
- Write %data_children_data_url(#),%data_children_data_url(1),%data_children_data_title(1),%data_children_data_permalink(1)
Notice how the permalink starts with /r/ and not with https://www.reddit.com. We want to get working links so we need to prefix all links with https://www.reddit.com to make them work correctly. We'll do that in the next step.
STEP 4 - ADD URL PREFIX
Notice how we used % in the Text field but not in the Variable Name field. That was because we want to use the contents of the %data_children_data_permalink() variable in the Text field, but we do NOT want to use the contents in the Variable Name field. We simply want to name the output variable with that name
- Add an AutoTools Text action
- Set the Text field to %data_children_data_permalink()
- Set the Variable Name field to data_children_data_permalink()
As you can see the permalink value now has the right url prefix.
- Set the Prefix field to https://www.reddit.com
- Go back to Tasker and move the Flash action to the end of the task
STEP 5 - SET MUZEI WALLPAPERS
If you don't enable Next Image the wallpaper won't be set right away but will only change on the next scheduled change.
- Add an AutoTools Muzei action
- Set the Images field to %data_children_data_url()
- Set the Titles field to %data_children_data_title()
- Set the View URLs field to %data_children_data_permalink()
- Enable the Next Image option
This will make the wallpaper change each 3600 seconds, which is an hour
- Set the Schedule field to 3600
STEP 6 - TEST
- Run the Task
- Go back to your home screen and notice how the wallpaper changes
- Open Muzei and change the wallpaper by tapping the forward arrow button
- Tap on the wallpaper title to go to the reddit comments page for the wallpaper
That's it! You can now run task once a day for example, and it'll get the latest wallpapers and set them as your Muzei wallpapers.
The task will get the image URLs, set them in Muzei (it will not download the files, but will use the URLs in Muzei directly. Muzei downloads the files when it needs them), and schedule automatic updates every hour. You only need to run the Task once when you want to get new images but the images will self-update in Muzei every hour automatically without any Tasker intervention.