Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8812a90
Showing
10 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'slop' | ||
gem 'nokogiri' | ||
gem 'growl' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# pop-zap | ||
|
||
pop-zap is auto zapping TV tool with iRemocon. | ||
|
||
## usage | ||
|
||
```ruby | ||
ruby -Ilib bin/app.rb | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ip: 192.168.0.9 | ||
port: 51013 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
NHK総合: 1201 | ||
NHK教育: 1202 | ||
日本テレビ: 1204 | ||
テレビ朝日: 1205 | ||
TBSテレビ: 1206 | ||
テレビ東京: 1207 | ||
フジテレビ: 1208 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'pop-zap/version' | ||
require 'pop-zap/app' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module PopZap | ||
VERSION = "0.0.1" | ||
end |