Last active
March 29, 2022 10:27
-
-
Save moxmlb/a66f1592fb145ff5517d6028bc697880 to your computer and use it in GitHub Desktop.
Scriptable iOS widget that shows the current price of your favorite movie on iTunes Store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let movieId, country, quality | |
if (country == null && movieId == null && quality == null) { | |
country = 'de' | |
movieId = 991367195 //example id for Minions movie | |
quality = 'hd' | |
} | |
// api link | |
let link = 'https://itunes.apple.com/lookup?' | |
let widgetInputRAW = args.widgetParameter; | |
let widgetInput = null; | |
// get widget input, seperated by | | |
if (widgetInputRAW !== null) { | |
[movieId, country, quality] = widgetInputRAW.toString().split("|"); | |
} | |
var backgroundColor, textColor | |
if (Device.isUsingDarkAppearance()) { | |
backgroundColor = Color.black() | |
textColor = Color.white() | |
} else { | |
backgroundColor = Color.white() | |
textColor = Color.black() | |
} | |
const widget = new ListWidget() | |
const result = await fetchiTunesInfo() | |
await createWidget() | |
if (!config.runsInWidget) { | |
Safari.open(result.results[0].trackViewUrl.toString()) | |
await widget.presentSmall() | |
} | |
Script.setWidget(widget) | |
Script.complete() | |
async function createWidget() { | |
widget.addSpacer(4) | |
widget.setPadding(10, 10, 10, 10) | |
let titleText = widget.addText(result.results[0].trackName) | |
titleText.textColor = textColor | |
titleText.font = Font.boldSystemFont(20) | |
titleText.minimumScaleFactor = 0.5 | |
titleText.centerAlignText() | |
widget.addSpacer() | |
const artwork = await getImage('movieArtwork.jpg') | |
let image = widget.addImage(artwork) | |
image.centerAlignImage() | |
widget.addSpacer() | |
var priceBuyText = '' | |
if (quality == 'sd') { | |
priceBuyText = widget.addText(result.results[0].trackPrice.toString() + " " + result.results[0].currency.toString()) | |
} | |
else { | |
priceBuyText = widget.addText(result.results[0].trackHdPrice.toString() + " " + result.results[0].currency.toString()) | |
} | |
priceBuyText.font = Font.mediumRoundedSystemFont(13) | |
priceBuyText.textColor = textColor | |
priceBuyText.centerAlignText() | |
} | |
async function fetchiTunesInfo() { | |
let url | |
var price = 0.0 | |
url = link + 'country=' + country + '&id=' + movieId | |
const req = new Request(url) | |
const apiResult = await req.loadJSON() | |
return apiResult | |
} | |
async function getImage(image) { | |
let imageUrl = result.results[0].artworkUrl100.replace('100x100', '1000x1000') | |
let movieImage = await loadImage(imageUrl) | |
return movieImage | |
} | |
async function loadImage(imgUrl) { | |
const req = new Request(imgUrl) | |
return await req.loadImage() | |
} |
The indicator of the promotion Wednesday film would be great.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Intro
The iTunes movie widget displays your favorite movie and its price. The movie ID, store country and quality can be set by parameters.
It is a widget for the iOS 14 home screen, powered by iTunes Store API.
Requirements
movie ID: Go to the iTunes Store and search for your favorite movie. On detail page press the share button and select copy link. Paste the link everywhere you want to get the id. At the end of the link you see the word id with different numbers. The numbers after the id is your movie ID.
country: Your two digits country code, like "de" for Germany.
quality: "sd" or "hd" for your favorite quality
Installation
Disclaimer
It is a fun project developed by myself, not an official product of the iTunes Store. I have no relationship to iTunes Store and get neither commission.
Result