Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scriptable iOS widget that shows the current price of your favorite movie on iTunes Store
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()
}
@moxmlb

This comment has been minimized.

Copy link
Owner Author

@moxmlb moxmlb commented Oct 25, 2020

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

  • iOS 14
  • Scriptable App Version 1.5 or newer
  • Parameter
    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

  • Copy the code above
  • Go to Scriptable App and create a new script
  • Paste the code to the script
  • Save the script with pressing the done button
  • Go to your iOS home screen and press anywhere to enter "wiggle mode" (which also allows you to arrange the app icons)
  • Press the "+" symbol in the top left corner, then scroll down to "Scriptable", select the widget size you want and press "Add Widget" at the bottom
  • Press the widget to edit its settings (optionally press and hold if the wiggle mode is already closed)
  • Under "Script" select the one you created above
  • Enter the parameters like the following: movieID|country|quality (example: 991367195|de|hd)
    IMG_36C26785AC0A-1

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

IMG_CD70116DFF93-1

@Leibinger015

This comment has been minimized.

Copy link

@Leibinger015 Leibinger015 commented Nov 15, 2020

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