Skip to content

Instantly share code, notes, and snippets.

@bcse
Last active December 24, 2015 05:19
Show Gist options
  • Save bcse/6749425 to your computer and use it in GitHub Desktop.
Save bcse/6749425 to your computer and use it in GitHub Desktop.
iTunes Festival London 2014 Download Link Generator

Usage

  1. Execute iftgen.py
  2. Insert artist name, e.g. 5 Seconds of Summer
  3. 5 Seconds of Summer.txt and 5 Seconds of Summer.ac3.txt will be generated
  4. Download video from 5 Seconds of Summer.txt and combine them with cat *.ts > combined.ts
  5. (Optional) If you want to download 5.1 channel AC-3 audio as well. Download them from 5 Seconds of Summer.ac3.txt and combine them with cat *.ac3 > combined.ac3
#!/usr/bin/env python
from __future__ import print_function
from __future__ import unicode_literals
import json
import os
import re
import socket
import sys
import urllib2
_opener = None
def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
global _opener
if _opener is None:
_opener = urllib2.build_opener()
# pretending to be an Apple TV
headers = {
'X-Apple-TV-Resolution': '1080',
'X-Apple-TV-Version': '6.2',
'User-Agent': 'iTunes-AppleTV/6.2 (3; 8GB; dt:12)'
}
request = urllib2.Request(url, data, headers)
return _opener.open(request, timeout=timeout)
if __name__ == '__main__':
data = None
try:
print('Load data from cache')
f = open('data.json', 'r')
data = json.load(f)
except Exception:
print('Load data from Internet')
f = open('data.json', 'w')
f.write(urlopen(r'https://appletv.itunesfestival.com/1b/en-GB/gb.json').read())
f.close()
f = open('data.json', 'r')
data = json.load(f)
if data is None:
print('Load data failed')
sys.exit(0)
video_dict = {unicode(data['video_dict'][k]['artist_name']): unicode(data['video_dict'][k]['url'])
for k in data['video_dict'].keys() if k.startswith('vod-')}
print('Artists:')
for artist in sorted(video_dict.keys(), key=unicode.lower):
print(' %s' % artist)
artist_name = raw_input('Please input artist name: ').decode(sys.stdout.encoding)
if artist_name not in video_dict:
print('Unknown Artist: %s' % artist_name)
sys.exit(0)
# get token
f = urlopen(r'http://itunes.apple.com/apps1b/authtoken/token.txt')
token = 'token=%s' % urllib2.quote(f.read().strip(), safe='')
f.close()
url = video_dict[artist_name]
_base, _path = url.rsplit('/', 1)
url = _base + '/8500_256/' + _path.replace('_atv', '')
if '?' in url:
url += '&' + token
else:
url += '?' + token
fin = urlopen(url)
fout = open(artist_name + '.txt', 'w')
fout2 = open(artist_name + '.ac3.txt', 'w')
for line in fin:
if '.ts' in line:
fname, fext = os.path.splitext(line)
fout.write(_base + '/8500_256/' + fname + '.ts' + '?' + token + '\n')
fout2.write(_base + '/448/' + fname + '.ac3' + '?' + token + '\n')
fin.close()
fout.close()
fout2.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment