Editorial Workflows

iTunes Link

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Queries the iTunes Store API to search for a media item and returns a markdown link. If text is already selected, it is used as the link title.

Searchable media includes Music (by artist, album, or track), Movies, TV Shows, Apps (iPhone, iPad, Mac), Podcast, and eBooks.

Thanks to @viticci for the base framework for this workflow!

Shared by: @realburch

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Selected Text ?
Entire Line(s)
OFF
Empty Selection Output
  • No Output
  • All Text
  • Closest Word
Folded Text
  • Include
  • Replace with:
If Nothing is Selected... ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Request Text Input ?
Title
Search String
Initial Text
  • Single Line
  • Multiple Lines
Keyboard Options:
…End If
Set Variable ?
Variable Name
term
Value
Input
URL Escape Search Term ?
Choose Media Type ?
Title
Media Type
List (Lines)
Music music Movie movie TV Show tvShow App software Podcast podcast Book ebook
Multiple Selection
OFF
Show in Popover
ON
Set Variable ?
Variable Name
media
Value
Input
If Music... ?
Run the block if
media
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
music
Choose Music Search Type ?
Title
Music Search Type
List (Lines)
Artist musicArtist Album album Song musicTrack
Multiple Selection
OFF
Show in Popover
ON
…End If
If App... ?
Run the block if
media
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
software
Choose App Type ?
Title
App Type
List (Lines)
iPhone software iPad iPadSoftware Mac macSoftware
Multiple Selection
OFF
Show in Popover
ON
…End If
Set Variable ?
Variable Name
entity
Value
Input
Run Python Script ?
Source Code
import requests
import workflow
import console

# Given a proper iTunes Search URL, returns a list of results that is passed to the next action with relevant info.

term = workflow.get_variable('term')
media = workflow.get_variable('media')
entity = workflow.get_variable('entity')
listName = workflow.get_variable('listName')

# Set list name and URL
if media == 'music' and entity == 'musicArtist':
	listName = 'Artist'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=' + entity

elif media == 'music' and entity == 'album':	
	listName = 'Album - Artist'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=' + entity

elif media == 'music' and entity == 'musicTrack':
	listName = 'Song - Artist'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=' + entity

elif media == 'movie':
	listName = 'Movie - Director'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=movie'
	
elif media == 'tvShow':
	listName = 'TV Show'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=tvShow'

elif media == 'software' and entity == 'software':
	listName = 'iPhone App'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=' + entity

elif media == 'software' and entity == 'iPadSoftware':
	listName = 'iPad App'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=' + entity
	
elif media == 'software' and entity == 'macSoftware':
	listName = 'Mac App'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=' + entity
	
elif media == 'podcast':
	listName = 'Podcast'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=podcast'

elif media == 'ebook':
	listName = 'Book - Author'
	URL = 'http://itunes.apple.com/search?term=' + term + '&country=us&media=' + media + '&entity=ebook'

workflow.set_variable('listName', listName)
             
j = requests.get(URL)
# print j.json()['results']
s = []

if j.status_code != 200:
	
	print 'Could not fetch items.\n', j.text
    
elif j.status_code == 200:
	
	# Music - Artist
	if media == 'music' and entity == 'musicArtist':
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['artistName'] + '	' + item['artistLinkUrl'])
			output = '\n'.join(s)
			workflow.set_output(output);
	
	# Music - Album
	elif media == 'music' and entity == 'album':	
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['collectionName'] + ' - ' + item['artistName'] + '	' + item['collectionViewUrl'])
			output = '\n'.join(s)
			workflow.set_output(output);
	
	# Music - Song	
	elif media == 'music' and entity == 'musicTrack':
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['trackName'] + ' - ' + item['artistName'] + '	' + item['trackViewUrl'])
			output = '\n'.join(s)
			workflow.set_output(output);
			
	# Movie
	elif media == 'movie':
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['trackName'] + ' - ' + item['artistName'] + '	' + item['trackViewUrl'])
			output = '\n'.join(s)
			workflow.set_output(output);
			
	# TV Show
	elif media == 'tvShow':
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['artistName'] + '	' + item['artistLinkUrl'])
			output = '\n'.join(s)
			workflow.set_output(output);
			
	# App - iPhone
	elif media == 'software' and entity == 'software':
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['trackName'] + ' - ' + item['formattedPrice'] + '	' + item['trackViewUrl'])
			output = '\n'.join(s)
			workflow.set_output(output);
			
	# App - iPad
	elif media == 'software' and entity == 'iPadSoftware':
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['trackName'] + ' - ' + item['formattedPrice'] + '	' + item['trackViewUrl'])
			output = '\n'.join(s)
			workflow.set_output(output);
			
	# App - Mac
	elif media == 'software' and entity == 'macSoftware':
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['trackName'] + ' - ' + item['formattedPrice'] + '	' + item['trackViewUrl'])
			output = '\n'.join(s)
			workflow.set_output(output);
			
	# Podcast
	elif media == 'podcast':
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['collectionName'] + '	' + item['collectionViewUrl'])
			output = '\n'.join(s)
			workflow.set_output(output)
			
	# Book
	elif media == 'ebook':
		for item in j.json()['results']:
			console.show_activity('Building list...')
			s.append(item['trackName'] + ' - ' + item['artistName'] + '	' + item['trackViewUrl'])
			output = '\n'.join(s)
			workflow.set_output(output)
Select from List ?
Title
%var:listName
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
ON
Replace Selected Text ?
Replacement Text
[term](Input "term")