Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
katsuma committed Jun 12, 2012
0 parents commit 8812a90
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
.idea
5 changes: 5 additions & 0 deletions Gemfile
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'slop'
gem 'nokogiri'
gem 'growl'
14 changes: 14 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,14 @@
GEM
remote: https://rubygems.org/
specs:
growl (1.0.3)
nokogiri (1.5.0)
slop (2.1.0)

PLATFORMS
ruby

DEPENDENCIES
growl
nokogiri
slop
9 changes: 9 additions & 0 deletions README.md
@@ -0,0 +1,9 @@
# pop-zap

pop-zap is auto zapping TV tool with iRemocon.

## usage

```ruby
ruby -Ilib bin/app.rb
```
24 changes: 24 additions & 0 deletions bin/app.rb
@@ -0,0 +1,24 @@
require 'bundler/setup'

require 'slop'
require 'socket'
require 'open-uri'
require 'nokogiri'
require 'pop-zap'
require 'growl'

opts = Slop.parse do
banner "ruby -Ilib bin/app.rb [options]"
on :c, '--conf', 'Set configuration path', :as => :string
on :h, '--help', 'Print this message'
end

if opts.help?
puts opts.help
exit 1
end

conf = opts[:conf] || 'conf'

pop_zap = PopZap::App.new(conf)
pop_zap.start
2 changes: 2 additions & 0 deletions conf/iremocon.conf
@@ -0,0 +1,2 @@
ip: 192.168.0.9
port: 51013
7 changes: 7 additions & 0 deletions conf/tv.conf
@@ -0,0 +1,7 @@
NHK総合: 1201
NHK教育: 1202
日本テレビ: 1204
テレビ朝日: 1205
TBSテレビ: 1206
テレビ東京: 1207
フジテレビ: 1208
2 changes: 2 additions & 0 deletions lib/pop-zap.rb
@@ -0,0 +1,2 @@
require 'pop-zap/version'
require 'pop-zap/app'
59 changes: 59 additions & 0 deletions lib/pop-zap/app.rb
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
module PopZap
class App
LIVE_URL = 'http://tv2ch.nukos.net/tvres.html'
IGNORE_KEYWORDS = ['BS実況', 'スカパー', '番組']

def initialize(conf)
@conf = conf
@tv_conf = YAML.parse_file("#{conf}/tv.conf").transform
@iremocon_conf = YAML.parse_file("#{conf}/iremocon.conf").transform
end

def start
prev_channel = ''
loop do
popular_channel = popular_channels.first
unless prev_channel == popular_channel
Growl.notify "#{popular_channel[:program]} - #{popular_channel[:channel]}"
show popular_channel[:channel]
prev_channel = popular_channel
end

sleep 300
end
end

def popular_channels
channels = []

doc = Nokogiri::HTML(open(LIVE_URL))
trs = doc.css('table.table3 tr')
trs.each do |tr|
tds = tr.css('td')
next unless tds.size > 0

channel = tds[0].inner_text.gsub("\n", '').gsub('の勢い', '')
rate = tds[1].inner_text.gsub("\n", '').gsub('res/分', '').to_i
program = tds[3].inner_text

matches = channel.match(/#{IGNORE_KEYWORDS.join('|')}/)
next unless matches.nil?

channels << { :channel => channel, :rate => rate, :program => program }
end

channels.sort {|a, b| a[:rate] <=> b[:rate] }.reverse
end

def show(channel)
channel_id = @tv_conf[channel]
raise if channel_id.nil?
sock = TCPSocket.new @iremocon_conf['ip'], @iremocon_conf['port']

sock.write "*is;#{channel_id}\r\n"
sock.close
end

end
end
3 changes: 3 additions & 0 deletions lib/pop-zap/version.rb
@@ -0,0 +1,3 @@
module PopZap
VERSION = "0.0.1"
end

0 comments on commit 8812a90

Please sign in to comment.