Page MenuHomePhorge

No OneTemporary

diff --git a/check_track_availability.py b/check_track_availability.py
index 1afed70..e3c1320 100755
--- a/check_track_availability.py
+++ b/check_track_availability.py
@@ -1,29 +1,52 @@
#!/usr/bin/env python3
import sys
import tekore as tk
import pyml_config as config
# Set up Spotify connection using client token
conf = (config.client_id, config.client_secret)
token = tk.request_client_token(*conf)
spotify = tk.Spotify(token)
# Get track ID from first argument
trackarg = sys.argv[1]
#print(trackarg)
try:
#tk.from_url(trackarg)
#print("Looks like it's a track URL, we'll use that")
track = spotify.track(tk.from_url(trackarg)[1])
except:
#print("Looks like it's not a URL, maybe it's a URI?")
try:
track = spotify.track(trackarg)
except:
print("Still failed?!?")
#trackid = tk.from_url(trackarg)[1]
#track = spotify.track(trackid)
#print(track.asbuiltin())
-print(track.asbuiltin()['available_markets'])
+
+available_markets = track.asbuiltin()['available_markets']
+
+# Get the ISRC code to check for duplicate tracks that will be substituted automatically by Spotify if the submitted version isn't available in a jurisdiction
+isrc = track.asbuiltin()['external_ids']['isrc']
+
+# Now check for those additional versions, and append them to the available_markets array. Probably better ways to do this...
+search_results = spotify.search('isrc:{}'.format(isrc), types=('track',))
+for p in search_results:
+ if p.total > 1:
+ pagenum = 1
+ while pagenum <= p.total:
+ itemnum = pagenum - 1
+ available_markets += p.items[itemnum].asbuiltin()['available_markets']
+ pagenum = pagenum + 1
+ p.next
+
+# Clear out duplicates
+available_markets = list(dict.fromkeys(available_markets))
+# Order it
+available_markets.sort()
+
+
+print(available_markets)
diff --git a/spotify_track_availability.php b/spotify_track_availability.php
index 819792e..56151f3 100644
--- a/spotify_track_availability.php
+++ b/spotify_track_availability.php
@@ -1,30 +1,30 @@
<html>
<head>
<title>Spotify track availability checker</title>
</head>
<body>
<form action="" method="POST">
-<p><strong> Enter a Spotify track URL: <input name="URL" id="URL"></p>
+<p><strong>Enter a Spotify track URL:</strong> <input name="URL" id="URL"></p>
<p><button>Submit</button></p>
</form>
<?php
if($_POST['URL']) {
$url = $_POST['URL'];
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
die("Sorry, only valid URLs are currently supported. Take it up with Keith! He probably just forgot to make URIs work too. Or maybe what you pasted in isn't valid as either...");
}
$out = shell_exec("python3 check_track_availability.py $url");
print("Available markets list: $out");
}
?>
</body>
</html>

File Metadata

Mime Type
text/x-diff
Expires
Sat, Apr 26, 7:28 AM (12 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
152070
Default Alt Text
(2 KB)

Event Timeline