Last active 1670063512

Python and PHP scripts for getting Now Playing from ocr.rainwave.cc. MIT license

Revision b1ba46820c9bd91a02b592cb8b41cd8d0625a0da

OCRrainwaveNP.php Raw
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/");
6preg_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();
25foreach($songinfo["artists"] as $item) {
26 $artists[] = $item["artist_name"];
27}
28print sprintf("%s - %s (from %s) %s",
29 implode(", ", $artists),
30 $songinfo["song_title"],
31 $songinfo["album_name"],
32 $songinfo["song_url"]);
33
OCRrainwaveNP.py Raw
1from urllib2 import urlopen
2from urllib import urlencode
3from json import loads
4
5
6def 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
23if __name__ == "__main__":
24 main()
25