Skip to content

Instantly share code, notes, and snippets.

View confact's full-sized avatar

Håkan Nylén confact

View GitHub Profile
@confact
confact / ICY_support.rb
Created June 21, 2018 22:14
how i added support for ICY in Ruby
Net::HTTPResponse.instance_eval do
attr_reader :socket
def read_status_line(sock)
str = sock.readline
m = /\A(?:HTTP|ICY)(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) || raise(Net::HTTPBadResponse, "wrong status line: #{str.dump}")
m.captures
end
end
@confact
confact / get_song.rb
Created September 23, 2017 12:49
Getting current playing songs from html pages
def get_song
@get_song ||= if @server == 'SHOUTcast'
if Gem::Version.new(@version) > Gem::Version.new('2.0')
data = hash_get_song_page
data['SHOUTCASTSERVER']['SONGTITLE'] || ''
else
get_song_page.split(',').last.gsub('</body></html>', '')
end
elsif @server == 'Icecast'
data = hash_get_song_page
@confact
confact / get_song_page.rb
Last active September 23, 2017 09:54
get url for *cast server
def song_page
url_string = "#{@url.scheme}://#{@url.host}:#{@url.port}"
if %(SHOUTcast).include? @server
if Gem::Version.new(@version) > Gem::Version.new('2.0')
return "#{url_string}/stats?sid=1"
else
return "#{url_string}/7.html"
end
elsif %(Icecast).include? @server
return false if @url.to_s.include? 'dirble'
@confact
confact / net_http_icy_shoutcast.rb
Last active February 4, 2017 23:22
This make Net::HTTP work with old Shoutcast servers that write ICY 200 OK instead of standardized HTTP statuses.
Net::HTTPResponse.instance_eval do
attr_reader :socket
def read_status_line(sock)
str = sock.readline
m = /\A(?:HTTP|ICY)(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) || raise(Net::HTTPBadResponse, "wrong status line: #{str.dump}")
m.captures
end
end
@confact
confact / dirble.PAL
Last active December 11, 2015 10:27
Dirble AIR API script for SAM
{
Script to submit song info to the Dirble AIR API (https://dirble.com/broadcasters/providers).
The stationId & airKey values need to be set for this to work.
}
const STATION_ID = '';
const AIRKEY = '';
var player : TPlayer;
var song : TSongInfo;
@confact
confact / example.php
Created March 11, 2015 20:51
Elasticsearch codeigniter advancedquery example
$esquery = '{
"fields" : ["name", "bitrate", "genres","urlid","country", "country_name"],
"query":
{
"query_string": {
"query":"'.$query.'"
}
}
}';
echo json_encode(($this->elasticsearch->advancedquery("station",$esquery)));
@confact
confact / opensearch.xml
Created March 2, 2015 09:04
opensearch test
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Opensearch</ShortName>
<InputEncoding>UTF-8</InputEncoding>
<Description>Opensearch to search in your browser.</Description>
<Contact>opensearch@test.org</Contact>
<Url type="text/html" method="get" template="http://localhost:3000/search?q={searchTerms}"/>
<moz:SearchForm>http://localhost:3000/</moz:SearchForm>
</OpenSearchDescription>
@confact
confact / station.js
Created January 3, 2015 14:24
station.js
var dispatcher = new WebSocketRails('localhost/websocket');
dispatcher.on_open = function(data) {
console.log('connected!');
var stationid = $('#songhistorylist').data("id");
var stationname = 'station' + String(stationid);
var channel = dispatcher.subscribe(stationname);
channel.bind('new_song', function (song) {
@confact
confact / gemfile
Last active August 29, 2015 14:12
Websocket-rails sidekiq problem
gem 'websocket-rails', github: 'moaa/websocket-rails', branch: 'threadsocket-rails'
gem 'websocket-rails-js', github: 'websocket-rails/websocket-rails-js', branch: 'sub_protocols'