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