/
index.html
95 lines (79 loc) · 2.71 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en-US">
<head>
<!-- Thank you to @author: Darian Moody <mail@djm.org.uk>
who developed the artistID to podcast feed URL backend
on Sun.22.Apr.2012 -->
</head>
<body>
<script>
var artist_id;
var userGeneratedURL;
var ITUNES_API = 'http://itunes.apple.com/lookup?id=';
function scrape_url() {
// Parses and assigns to variables artist_id and userGeneratedURL
var form = document.forms['getURL'];
userGeneratedURL = form.feed.value;
artist_id = retrieveArtistID(userGeneratedURL);
retrieveFeedFromAPI(artist_id);
}
function retrieveArtistID(url) {
// Extracts the artist ID from a given URL.
var re = /id=?([\d]+)/i;
var match = url.match(re);
if (match) {
return match[1];
} else {
return false;
}
}
function retrieveFeedFromAPI(artist_id) {
// Call's the iTunes API with the parsed
// artist_id and parses the returned JSON
// to extract the original podcast feed URL.
var xhReq = new XMLHttpRequest();
xhReq.open("GET", ITUNES_API+artist_id, false);
xhReq.send(null);
var response = xhReq.responseText;
parsed = JSON.parse(response);
if (parsed && parsed.resultCount > 0) {
return parsed.results[0].feedUrl;
} else {
return false;
}
}
if (artist_id) {
feed_url = retrieveFeedFromAPI(artist_id);
if (feed_url) {
// We blank the page and insert there as I don't want to update this script
// whenever Apple feels like re-designing the podcast page markup.
// Yes, we're abusing br tags for spacing. Humblest apologies.
document.body.innerHTML = '<br/><h1>Podcast RSS URL: <a href="'+feed_url+'">'+feed_url+'</a></h1>';
} else {
document.body.innerHTML = '<br/><h1>Failed to retrieve feed from the iTunes API</a></h1>';
}
} else {
document.body.children[6].children[2].text('<br/><h1>Failed to parse the Apple\'s Artist ID.</a></h1>');
}
</script>
<br>
<br>
<!-- This is where the iTunes URL is accepted -->
<form name="getURL">
<center>
<input type="text" id="feed" size="80" value="" onkeyup="scrape_url();" onchange="scrape_url();">
</center>
</form>
<br>
<br>
<!-- This is where the result is fed -->
<center>
<!-- <a id="extracted_podcast" href="http://picklemonkey.net/flipper/extractor.php" style="display: none">http://picklemonkey.net/flipper/extractor.php?feed=</a> -->
<label id="result">Your Requested Source Feed Will Appear Here</label>
<p>https://itunes.apple.com/us/podcast/love-affair-travel-podcast/id668329357</p>
<h3>the results should go here</h3>
</center>
<br>
<br>
</body>
</html>