program-tv 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/program-tv +5 -1
- data/channels.yml +2 -2
- data/lib/program-tv/parser.rb +5 -1
- data/lib/program-tv/writer.rb +33 -11
- data/lib/program-tv.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11ad4f25b58b9672f4774ca2521d46f01cf81f15
|
4
|
+
data.tar.gz: 6fb5c11984c2096528e30e2c2347226c0df554a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7682ef5601e90399f4a30277b720bfd56d59dcb7aef2f298f6a279323d33d41b41d433218d6bc96539919ec1052c3a728b46171ae49e7bc22996bda20a597caf
|
7
|
+
data.tar.gz: d6d3cb6c68020b8a1f3d8864cca328ad79e8e69e0bd2c19191cb591e5a9b384675ecc141b9d6b3cba9d06b8536da260bc5c2a3072b4c379ac23a28f766e74ced
|
data/bin/program-tv
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.push File.expand_path("../lib", File.dirname(__FILE__)) # add library
|
|
5
5
|
require 'program-tv'
|
6
6
|
require 'optparse'
|
7
7
|
|
8
|
-
options = {}
|
8
|
+
options = { :destination => '/home/hosting/tvo/epg/' }
|
9
9
|
OptionParser.new do |op|
|
10
10
|
op.banner = <<-eos
|
11
11
|
#{ProgramTV::DESCRIPTION}
|
@@ -27,6 +27,10 @@ OptionParser.new do |op|
|
|
27
27
|
op.on("-c", "--channel-list PATH", "path to yml channel list") do |path|
|
28
28
|
options[:channel_list] = path
|
29
29
|
end
|
30
|
+
|
31
|
+
op.on("-d", "--destination PATH", "directory with EPG XML files") do |path|
|
32
|
+
options[:destination] = path
|
33
|
+
end
|
30
34
|
end.parse!
|
31
35
|
|
32
36
|
begin
|
data/channels.yml
CHANGED
@@ -19,11 +19,11 @@ polsat-biznes : polsatbiznes
|
|
19
19
|
jim-jam-polsat : polsatjimjam
|
20
20
|
polsat-sport : polsatsport
|
21
21
|
polsat-sport-news : polsatsportnews
|
22
|
-
puls : puls
|
22
|
+
tv-puls : puls
|
23
23
|
puls-2 : puls2
|
24
24
|
rbl.tv : rbltv
|
25
25
|
russia-today : russiatoday
|
26
|
-
stars
|
26
|
+
stars.tv : starstv
|
27
27
|
tele-5 : tele5
|
28
28
|
ttv : ttv
|
29
29
|
tv-4 : tv4
|
data/lib/program-tv/parser.rb
CHANGED
@@ -10,7 +10,7 @@ module ProgramTV
|
|
10
10
|
def run
|
11
11
|
ProgramTV.selected_channels.map do |url_name, epg_name|
|
12
12
|
schedule(epg_name, "http://www.cyfrowypolsat.pl/program-tv/#{url_name}")
|
13
|
-
end
|
13
|
+
end.compact
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -24,6 +24,10 @@ module ProgramTV
|
|
24
24
|
title: e.css('.name').text
|
25
25
|
}
|
26
26
|
end
|
27
|
+
if data.empty?
|
28
|
+
puts "Missing schedule for channel #{epg_name}"
|
29
|
+
return
|
30
|
+
end
|
27
31
|
data[0..-2].each_with_index{ |element, i| element[:end] = data[i+1][:start] }
|
28
32
|
data.pop
|
29
33
|
data
|
data/lib/program-tv/writer.rb
CHANGED
@@ -1,24 +1,46 @@
|
|
1
1
|
require 'builder'
|
2
|
+
require 'pry'
|
3
|
+
require_relative 'hash_helper'
|
2
4
|
|
3
5
|
module ProgramTV
|
4
6
|
class Writer
|
5
7
|
|
6
|
-
def initialize(data)
|
8
|
+
def initialize(data, destination)
|
7
9
|
@data = data
|
8
|
-
@
|
9
|
-
@xml.instruct! :xml, :encoding => "UTF-8"
|
10
|
+
@destination = destination
|
10
11
|
end
|
11
12
|
|
12
|
-
# Runs dynamic-sprites command.
|
13
|
-
#
|
14
13
|
def run
|
15
|
-
@
|
16
|
-
|
14
|
+
@data.each do |schedule|
|
15
|
+
today_schedule = []
|
16
|
+
if File.exist?(xml_path(schedule))
|
17
|
+
File.open(xml_path(schedule), "r+") do |file|
|
18
|
+
today_schedule = Hash.from_xml(file.read)[:tv][:programme]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
File.open(xml_path(schedule), "w+") do |file|
|
22
|
+
file.write(build_xml(today_schedule + schedule))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def xml_path(schedule)
|
30
|
+
File.join(@destination, "#{schedule.first[:channel]}.xml")
|
31
|
+
end
|
32
|
+
|
33
|
+
# Builds XML data from schedule Hash
|
34
|
+
def build_xml(schedule)
|
35
|
+
xml_builder = Builder::XmlMarkup.new( :indent => 2 )
|
36
|
+
xml_builder.instruct! :xml, :encoding => "UTF-8"
|
37
|
+
xml_builder.tv do |tv|
|
38
|
+
schedule.each do |program|
|
17
39
|
tv.programme do |p|
|
18
|
-
p.title
|
19
|
-
p.channel
|
20
|
-
p.start
|
21
|
-
p.end
|
40
|
+
p.title program[:title]
|
41
|
+
p.channel program[:channel]
|
42
|
+
p.start program[:start]
|
43
|
+
p.end program[:end]
|
22
44
|
end
|
23
45
|
end
|
24
46
|
end
|
data/lib/program-tv.rb
CHANGED
@@ -2,7 +2,7 @@ module ProgramTV
|
|
2
2
|
|
3
3
|
#----------------------------------------------------------------------------
|
4
4
|
|
5
|
-
VERSION = "0.0.
|
5
|
+
VERSION = "0.0.4"
|
6
6
|
SUMMARY = "TV Channel parser"
|
7
7
|
DESCRIPTION = "Downloads TV channel list in XML format"
|
8
8
|
|
@@ -18,7 +18,7 @@ module ProgramTV
|
|
18
18
|
def self.run!(options = {})
|
19
19
|
@@options = options
|
20
20
|
data = Parser.new.run
|
21
|
-
|
21
|
+
Writer.new(data, @@options[:destination]).run
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|