enklawa 0.1.4 → 0.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjRjYmQ1NDZmMDEzZjJiYmQwYTk3OTUyZjgwYTBjNGViZTFmZTEzYg==
4
+ MDA1MDcyOTVhNmEzMWQ0Nzg2YTFhN2MyMDBkNTVkZTIyODhhMDU1Yw==
5
5
  data.tar.gz: !binary |-
6
- YWY3Y2FjOTE3ZmQxYTU4Yjc5NjYzZmQ0Y2YzMWM3MmYxMTJkYzA5YQ==
6
+ Yjc2MmEwMGEzNDEyZTdmNjMxMjY1YzMwMDdiNDE3OGYxNzYyZTM5Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODUyYWE3OGQ0MjdjMzAxOGM2MDdlNWZhNDYyMTQ5ZjdmMjg0ODU4YjY4ZmZi
10
- ZTIxNjZiZmJlOTA2ZjlhM2NlNGIzNTJjZGFlMTQwZWI3Zjc0NmYyZWExMDVi
11
- NTkzZGJhN2E0MmQ2YjQyN2VjMTQ5NzBlMDhiZDAxMDlhYTYxMzY=
9
+ YTI1YzZlNWYzYTg0NDk4MTJiODQ1MDVjZDljNzJkYmE0YmRmMDgxOWVhOTA0
10
+ YzQ0MmVjNjcxNjM5NTdmMzRiYzkxY2JhMjJkNjU0ZmJhZDI5MDhkMTIzYWQx
11
+ N2RkOTJiMTZjNDNiMzY0MzA0YTRhYWE2OGJlM2JjZDlhMDZiZTM=
12
12
  data.tar.gz: !binary |-
13
- ZDViYmE2MzNhZmQ5NzNmZDQ4MzcyMjg4OGFiNjhlNjIyMTgzMGY4YmRmY2Ri
14
- YzJmOTc4OTU5Nzc0YTRjNGYzMzIzMDMzZGIwODE4YjNkMzViZTRkNmU3NjI2
15
- ODJkZDZiNjgxOTkyNzM1MDZlYWVhYjA3ZWY2Yjc0M2UzYzkyY2E=
13
+ ZTZjZGM4YjhkMjlhOGE4ZWI2NDYwY2M4MTAxZTU0ZGQ3MTM4MDZmMWVmY2Rh
14
+ YzViODAzMmM3MWRmMjNmMDQ4ODMwMzZjMDI4MzkzNzAzNGM0MTY2OTkwOTMx
15
+ ZDM5NjQxMTdlNzg5MzhmNzQzMzNjNGI1N2U2ODE5ZjRiMWI4YWY=
data/.gitignore CHANGED
@@ -20,3 +20,5 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ *.json
24
+ *.yml
@@ -12,8 +12,8 @@ require "cgi"
12
12
  module Enklawa
13
13
  module Api
14
14
 
15
- def self.fetch
16
- request = Request.new
15
+ def self.fetch(url)
16
+ request = Request.new(url)
17
17
  request.get!
18
18
  end
19
19
 
@@ -1,14 +1,18 @@
1
1
  module Enklawa
2
2
  module Api
3
3
  class Program < Struct.new(:id, :name, :description, :author, :live, :category_id)
4
- attr_accessor :episodes
4
+ attr_accessor :episodes, :base_url
5
5
 
6
6
  def initialize
7
7
  self.episodes = []
8
8
  end
9
9
 
10
10
  def image
11
- "http://www.enklawa.net/images/programs/#{id}.jpg"
11
+ if base_url.match("enklawa")
12
+ File.join([base_url, "/images/programs/#{id}.jpg"])
13
+ else
14
+ File.join([base_url, "/images/programs/240/#{id}.jpg"])
15
+ end
12
16
  end
13
17
 
14
18
  def <<(episode)
@@ -16,7 +20,7 @@ module Enklawa
16
20
  end
17
21
 
18
22
  def feed_url
19
- "http://www.enklawa.net/program#{self.id}.xml"
23
+ File.join([base_url, "/program#{self.id}.xml"])
20
24
  end
21
25
 
22
26
  def to_h
@@ -4,12 +4,11 @@ require "yaml"
4
4
  module Enklawa
5
5
  module Api
6
6
  class Request
7
- INFO_XML_URL = "http://www.enklawa.net/info.xml"
8
- MAIN_PAGE_URL = "http://enklawa.net"
9
- FORUM_FEED_URL = "http://forum.enklawa.net/feed.php"
10
- ENKLAWA_CACHE_FILE = '/tmp/enklawa_cache.yml'
11
- def initialize
12
- @cache = YAML::load_file(ENKLAWA_CACHE_FILE) if File.exists?(ENKLAWA_CACHE_FILE)
7
+ def initialize(url)
8
+ @info_xml_url = File.join([url, "info.xml"])
9
+ @main_page_url = url
10
+ @cache_key = url.gsub(/[^a-z]/i,"") + ".yml"
11
+ @cache = YAML::load_file(@cache_key) if File.exists?(@cache_key)
13
12
  @cache ||= {
14
13
  'images' => {},
15
14
  'durations' => {}
@@ -18,44 +17,32 @@ module Enklawa
18
17
 
19
18
  def get!
20
19
  @response = Response.new
21
- get_forum_feeds!
22
- get_categories!
23
20
  get_info!
24
21
  get_programs!
25
22
  get_episodes!
26
23
 
27
- File.open(ENKLAWA_CACHE_FILE, 'w') {|f| f.write @cache.to_yaml }
24
+ File.open(@cache_key, 'w') {|f| f.write @cache.to_yaml }
28
25
 
29
26
  @response
30
27
  end
31
28
 
32
29
  private
33
30
 
34
- def get_categories!
35
- doc = Nokogiri::HTML(open(MAIN_PAGE_URL))
36
-
37
- doc.search("select#ProgramsSelector option").each do |option|
38
- category = Category.new
39
- category.name = option.text
40
- category.id = option[:value].to_i
41
-
42
- @response.add_category(category)
43
- end
44
- end
45
-
46
31
  def get_info!
47
- @info_xml_doc = Nokogiri::XML(open(INFO_XML_URL).read)
32
+ @info_xml_doc = Nokogiri::XML(open(@info_xml_url).read)
48
33
 
49
34
  @response.skype = @info_xml_doc.search("settings call skype").text
50
35
  @response.phone = @info_xml_doc.search("settings call phone").text
51
36
 
52
- shoutcast_pls_url = "http:"+CGI.unescape(@info_xml_doc.search("settings listen shoutcast").text)
37
+ shoutcast_pls_url = CGI.unescape(@info_xml_doc.search("settings listen shoutcast").text)
38
+ shoutcast_pls_url = "http:"+ shoutcast_pls_url unless shoutcast_pls_url.match("http")
53
39
  @response.radio = open(shoutcast_pls_url).read.strip.split("\n")[-1].gsub("File1=","")
54
40
  end
55
41
 
56
42
  def get_programs!
57
43
  @info_xml_doc.search("programs p").each do |program_node|
58
44
  program = Program.new
45
+ program.base_url = @main_page_url
59
46
  program.id = program_node[:id].to_i
60
47
  program.name = program_node.search("name").text
61
48
  program.description = program_node.search("description").text
@@ -78,25 +65,9 @@ module Enklawa
78
65
  @response.programs.reject! { |program| program.episodes.empty? }
79
66
  end
80
67
 
81
- def get_forum_feeds!
82
- feed = Feedjira::Feed.fetch_and_parse(FORUM_FEED_URL)
83
- return if feed == 404
84
-
85
- feed.entries.each do |entry|
86
- thread = ForumThread.new
87
- thread.id = entry.id
88
- thread.title = entry.title
89
- thread.link = entry.url
90
- thread.content = entry.content
91
- thread.pub_date = entry.published
92
- thread.author = entry.author
93
- @response.add_thread(thread)
94
- end
95
- end
96
-
97
68
  def check_if_image_exists_or_use_from_program(program, episode)
98
69
  return @cache['images'][episode.id] if @cache['images'].key?(episode.id)
99
- image = "http://www.enklawa.net/images/episodes/#{episode.id}.jpg"
70
+ image = File.join([@main_page_url, "/images/episodes/#{episode.id}.jpg"])
100
71
 
101
72
  uri = URI(image)
102
73
 
@@ -1,5 +1,5 @@
1
1
  module Enklawa
2
2
  module Api
3
- VERSION = "0.1.4"
3
+ VERSION = "0.2"
4
4
  end
5
5
  end
@@ -10,8 +10,8 @@ module Enklawa
10
10
  end
11
11
 
12
12
  desc "save", "fetch and save episodes"
13
- def save(path)
14
- @response = Enklawa::Api.fetch
13
+ def save(url, path)
14
+ @response = Enklawa::Api.fetch(url)
15
15
  @response.save(path)
16
16
  end
17
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enklawa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkadiusz Buras
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-17 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json