Steven Smith revised this gist . Go to revision
1 file changed, 2 insertions, 1 deletion
OCRrainwaveNP.php
| @@ -1,6 +1,7 @@ | |||
| 1 | 1 | <?php | |
| 2 | 2 | # Because sometimes it's easier to load up a web browser. | |
| 3 | - | # http://blha303.com.au/util/ocr.rainwave.cc.php | |
| 3 | + | # http://blha303.com.au/rainwave | |
| 4 | + | # https://github.com/blha303/Rainwave-NowPlaying | |
| 4 | 5 | ||
| 5 | 6 | header("Access-Control-Allow-Origin: *"); | |
| 6 | 7 | $pagecontent = file_get_contents("http://ocr.rainwave.cc/"); | |
Steven Smith revised this gist . Go to revision
1 file changed, 14 insertions, 5 deletions
OCRrainwaveNP.php
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | # Because sometimes it's easier to load up a web browser. | |
| 3 | 3 | # http://blha303.com.au/util/ocr.rainwave.cc.php | |
| 4 | 4 | ||
| 5 | + | header("Access-Control-Allow-Origin: *"); | |
| 5 | 6 | $pagecontent = file_get_contents("http://ocr.rainwave.cc/"); | |
| 6 | 7 | preg_match_all("/PRELOADED_APIKEY = '(.*?)'/", $pagecontent, $matches); | |
| 7 | 8 | $url = "http://ocr.rainwave.cc/sync/2/init"; | |
| @@ -25,8 +26,16 @@ $artists = array(); | |||
| 25 | 26 | foreach($songinfo["artists"] as $item) { | |
| 26 | 27 | $artists[] = $item["artist_name"]; | |
| 27 | 28 | } | |
| 28 | - | print sprintf("%s - %s (from %s) %s", | |
| 29 | - | implode(", ", $artists), | |
| 30 | - | $songinfo["song_title"], | |
| 31 | - | $songinfo["album_name"], | |
| 32 | - | $songinfo["song_url"]); | |
| 29 | + | $out = sprintf("%s - %s (from %s) %s", | |
| 30 | + | implode(", ", $artists), | |
| 31 | + | $songinfo["song_title"], | |
| 32 | + | $songinfo["album_name"], | |
| 33 | + | $songinfo["song_url"]); | |
| 34 | + | if(isset($_GET['callback'])){ | |
| 35 | + | header('Content-Type: text/javascript'); | |
| 36 | + | $callback = preg_replace('/\W+/', '', $_GET['callback']); #sanitize | |
| 37 | + | print $callback . "(" . json_encode($out) . ");"; | |
| 38 | + | } else { | |
| 39 | + | header("Content-Type: text/plain"); | |
| 40 | + | print $out; | |
| 41 | + | } | |
Steven Smith revised this gist . Go to revision
1 file changed, 3 insertions, 1 deletion
OCRrainwaveNP.py
| @@ -1,13 +1,15 @@ | |||
| 1 | 1 | from urllib2 import urlopen | |
| 2 | 2 | from urllib import urlencode | |
| 3 | 3 | from json import loads | |
| 4 | + | from re import search | |
| 4 | 5 | ||
| 5 | 6 | ||
| 6 | 7 | def main(): | |
| 8 | + | apikey = search("PRELOADED_APIKEY = '(.*?)'", urlopen("http://ocr.rainwave.cc").read()).group(1) | |
| 7 | 9 | data = loads(urlopen("http://ocr.rainwave.cc/sync/2/init", | |
| 8 | 10 | data=urlencode({'refresh': 'full', | |
| 9 | 11 | 'user_id': '1', | |
| 10 | - | 'key': 'd472aaf56b', | |
| 12 | + | 'key': apikey, | |
| 11 | 13 | 'in_order': 'true'} | |
| 12 | 14 | )).read()) | |
| 13 | 15 | songinfo = data[3]["sched_current"]["song_data"][0] | |
Steven Smith revised this gist . Go to revision
1 file changed, 32 insertions
OCRrainwaveNP.php(file created)
| @@ -0,0 +1,32 @@ | |||
| 1 | + | <?php | |
| 2 | + | # Because sometimes it's easier to load up a web browser. | |
| 3 | + | # http://blha303.com.au/util/ocr.rainwave.cc.php | |
| 4 | + | ||
| 5 | + | $pagecontent = file_get_contents("http://ocr.rainwave.cc/"); | |
| 6 | + | preg_match_all("/PRELOADED_APIKEY = '(.*?)'/", $pagecontent, $matches); | |
| 7 | + | $url = "http://ocr.rainwave.cc/sync/2/init"; | |
| 8 | + | $data = array('refresh' => 'full', | |
| 9 | + | 'user_id' => '1', | |
| 10 | + | 'key' => $matches[1][0], | |
| 11 | + | 'in_order' => 'true'); | |
| 12 | + | ||
| 13 | + | $options = array( | |
| 14 | + | 'http' => array( | |
| 15 | + | 'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
| 16 | + | 'method' => 'POST', | |
| 17 | + | 'content' => http_build_query($data), | |
| 18 | + | ), | |
| 19 | + | ); | |
| 20 | + | ||
| 21 | + | $context = stream_context_create($options); | |
| 22 | + | $result = json_decode(file_get_contents($url, false, $context), true); | |
| 23 | + | $songinfo = $result[3]["sched_current"]["song_data"][0]; | |
| 24 | + | $artists = array(); | |
| 25 | + | foreach($songinfo["artists"] as $item) { | |
| 26 | + | $artists[] = $item["artist_name"]; | |
| 27 | + | } | |
| 28 | + | print sprintf("%s - %s (from %s) %s", | |
| 29 | + | implode(", ", $artists), | |
| 30 | + | $songinfo["song_title"], | |
| 31 | + | $songinfo["album_name"], | |
| 32 | + | $songinfo["song_url"]); | |
Steven Smith revised this gist . Go to revision
1 file changed, 24 insertions
OCRrainwaveNP.py(file created)
| @@ -0,0 +1,24 @@ | |||
| 1 | + | from urllib2 import urlopen | |
| 2 | + | from urllib import urlencode | |
| 3 | + | from json import loads | |
| 4 | + | ||
| 5 | + | ||
| 6 | + | def main(): | |
| 7 | + | data = loads(urlopen("http://ocr.rainwave.cc/sync/2/init", | |
| 8 | + | data=urlencode({'refresh': 'full', | |
| 9 | + | 'user_id': '1', | |
| 10 | + | 'key': 'd472aaf56b', | |
| 11 | + | 'in_order': 'true'} | |
| 12 | + | )).read()) | |
| 13 | + | songinfo = data[3]["sched_current"]["song_data"][0] | |
| 14 | + | artists = [] | |
| 15 | + | for i in songinfo["artists"]: | |
| 16 | + | artists.append(i["artist_name"]) | |
| 17 | + | print "%s by %s (from %s) %s" % (songinfo["song_title"], | |
| 18 | + | ", ".join(artists), | |
| 19 | + | songinfo["album_name"], | |
| 20 | + | songinfo["song_url"]) | |
| 21 | + | ||
| 22 | + | ||
| 23 | + | if __name__ == "__main__": | |
| 24 | + | main() | |