├── LICENSE
├── README.md
└── ipic
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Dr. Drang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ipic #
2 |
3 | Python script for searching and downloading images from the iTunes, App, and Mac App Stores.
4 |
5 | ## Dependencies ##
6 |
7 | * [requests][1] for handling communication with the [iTunes Search API][2].
8 | * [docopt][3] for handling the command line switches.
9 |
10 | ## Usage ##
11 |
12 | ipic (-i | -m | -a | -f | -t | -b | -n | -h) SEARCHTERM
13 |
14 | Generate and open a web page of thumbnail images and links to larger images
15 | for items in the iTunes/App/Mac App Stores.
16 |
17 | The switches are
18 |
19 | * -i: iOS app
20 | * -m: Mac app
21 | * -a: album
22 | * -f: movie (mnemonic: film)
23 | * -t: TV show
24 | * -b: book
25 | * -n: audiobook (mnemonic: narration)
26 | * -h: show this help message
27 |
28 | Only one switch is allowed. The HTML file for the generated web page is
29 | saved on your Desktop.
30 |
31 | Because the API usually returns several hits, `ipic` creates and opens a web page of thumbnail images that let you choose the one you want visually. Here's an example:
32 |
33 |
34 |
35 | Each thumbnail is a link to a full-sized version of the image, 512×512 for apps and 600×600 otherwise. Hovering over a thumbnail will show the name of the item.
36 |
37 |
38 | [1]: https://github.com/kennethreitz/requests
39 | [2]: https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/
40 | [3]: http://docopt.org/
41 |
--------------------------------------------------------------------------------
/ipic:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 |
4 | import requests
5 | import docopt
6 | import os
7 | import subprocess
8 |
9 | # You may want to change these.
10 | myDir = os.environ['HOME'] + '/Desktop/' # directory for HTML file
11 | browser = 'com.apple.Safari' # browser bundle identifier
12 |
13 | usage = '''Usage: ipic (-i | -m | -a | -f | -t | -b | -n | -h) SEARCHTERM
14 |
15 | Generate and open a web page of thumbnail images and links to larger images
16 | for items in the iTunes/App/Mac App Stores.
17 |
18 | Options:
19 | -i iOS app
20 | -m Mac app
21 | -a album
22 | -f movie (film)
23 | -t TV show
24 | -b book
25 | -n audiobook (narration)
26 | -h show this help message
27 |
28 | Only one option is allowed. The HTML file for the generated web page is
29 | saved on your Desktop.'''
30 |
31 | # Handle the command line.
32 | args = docopt.docopt(usage)
33 | searchterm = args['SEARCHTERM']
34 | if args['-i']:
35 | size = 512
36 | media = 'software'
37 | entity = 'software'
38 | name = 'trackName'
39 | elif args['-m']:
40 | size = 512
41 | media = 'software'
42 | entity = 'macSoftware'
43 | name = 'trackName'
44 | elif args['-a']:
45 | size = 600
46 | media = 'music'
47 | entity = 'album'
48 | name = 'collectionName'
49 | elif args['-f']:
50 | size = 600
51 | media = 'movie'
52 | entity = 'movie'
53 | name = 'trackName'
54 | elif args['-t']:
55 | size = 600
56 | media = 'tvShow'
57 | entity = 'tvSeason'
58 | name = 'collectionName'
59 | elif args['-b']:
60 | size = 600
61 | media = 'ebook'
62 | entity = 'ebook'
63 | name = 'trackName'
64 | elif args['-n']:
65 | size = 600
66 | media = 'audiobook'
67 | entity = 'audiobook'
68 | name = 'collectionName'
69 | else:
70 | size = 600
71 | media = ''
72 | entity = ''
73 | name = ''
74 |
75 | # Make the iTunes search call and collect the thumbnail and large image URLs.
76 | iURL = 'https://itunes.apple.com/search'
77 | parameters = {'term': searchterm, 'media': media, 'entity': entity}
78 | r = requests.get(iURL, params=parameters)
79 | results = r.json()['results']
80 | turls = [ x['artworkUrl100'] for x in results ]
81 | burls = [ x.replace('100x100', '{0}x{0}'.format(size)) for x in turls ]
82 | names = [ x[name] for x in results ]
83 |
84 | # Construct the HTML.
85 | linkFmt = ''
86 | links = [linkFmt.format(x, y, z.encode('utf8'))
87 | for x, y, z in zip(turls, burls, names) ]
88 | html = '''