Skip to content

Instantly share code, notes, and snippets.

Avatar

Håkan Nylén confact

View GitHub Profile
@confact
confact / ICY_support.rb
Created Jun 21, 2018
how i added support for ICY in Ruby
View ICY_support.rb
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 Sep 23, 2017
Getting current playing songs from html pages
View get_song.rb
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 Sep 23, 2017
get url for *cast server
View get_song_page.rb
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 Feb 4, 2017
This make Net::HTTP work with old Shoutcast servers that write ICY 200 OK instead of standardized HTTP statuses.
View net_http_icy_shoutcast.rb
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 Dec 11, 2015
Dirble AIR API script for SAM
View dirble.PAL
{
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 Mar 11, 2015
Elasticsearch codeigniter advancedquery example
View example.php
$esquery = '{
"fields" : ["name", "bitrate", "genres","urlid","country", "country_name"],
"query":
{
"query_string": {
"query":"'.$query.'"
}
}
}';
echo json_encode(($this->elasticsearch->advancedquery("station",$esquery)));
View opensearch.xml
<?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>
View 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 Aug 29, 2015
Websocket-rails sidekiq problem
View gemfile
gem 'websocket-rails', github: 'moaa/websocket-rails', branch: 'threadsocket-rails'
gem 'websocket-rails-js', github: 'websocket-rails/websocket-rails-js', branch: 'sub_protocols'
You can’t perform that action at this time.