enklawa 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/enklawa/api/episode.rb +0 -12
- data/lib/enklawa/api/request.rb +45 -7
- data/lib/enklawa/api/response.rb +1 -0
- data/lib/enklawa/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjU0N2YyZjE0ZTM0NDA3Yjg4MjVjNGE1YzE3MjJlYTM0MjVmY2IzZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTUyZWE4YzU1MWRlN2U2ODBlZDkzYTA2OWIzZGFmMTZhMjdmMzE1Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWU4YmFkNGVmYmM0YmI1Mjg3NmY1OTg3MGQ5NTU5ZGFiOGY3ZmNlYjliMGFi
|
10
|
+
Mzg1YTg5NGMwNTkzODk3NWY5NWEyNDEwODFjMGFhZjdkZWZiMzg4Y2QyNTk5
|
11
|
+
MGJhN2NiNWFhMzI0NWZiYTc0OTdiMjdiNDY4YTI5YmI3Zjc3YzU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzUzNGM3OWQxM2JhNzIwNGViNjE2ZDU2NmEyOGE0ZDU1ODgyNzY2YTAzMGQ1
|
14
|
+
NDczMzIzYmNiNDMwZTdjZDhjMzU1MDBlODYzOTc1NzI5MDQyNDBjMzNjM2M2
|
15
|
+
ZTkwY2U5OTBjYTU3ZjlkNTUzMGRiZmE4YTU1ZDNlM2YwOWUwYWQ=
|
data/lib/enklawa/api/episode.rb
CHANGED
@@ -5,18 +5,6 @@ module Enklawa
|
|
5
5
|
module Api
|
6
6
|
class Episode < Struct.new(:id, :name, :description, :mp3, :pub_date, :link, :duration, :image)
|
7
7
|
|
8
|
-
def check_if_image_exists_or_use_from_program(program)
|
9
|
-
self.image = "http://www.enklawa.net/images/episodes/#{id}.jpg"
|
10
|
-
|
11
|
-
uri = URI(image)
|
12
|
-
|
13
|
-
request = Net::HTTP.new uri.host
|
14
|
-
response = request.request_head uri.path
|
15
|
-
unless response.code.to_i == 200
|
16
|
-
self.image = program.image
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
8
|
def to_h
|
21
9
|
{
|
22
10
|
id: id.to_i,
|
data/lib/enklawa/api/request.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
require "feedjira"
|
2
2
|
require "sanitize"
|
3
|
-
|
3
|
+
require "yaml"
|
4
4
|
module Enklawa
|
5
5
|
module Api
|
6
6
|
class Request
|
7
|
-
INFO_XML_URL
|
8
|
-
MAIN_PAGE_URL
|
9
|
-
FORUM_FEED_URL
|
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'
|
10
11
|
def initialize
|
11
|
-
|
12
|
+
@cache = YAML::load_file(ENKLAWA_CACHE_FILE) if File.exists?(ENKLAWA_CACHE_FILE)
|
13
|
+
@cache ||= {
|
14
|
+
'images' => {},
|
15
|
+
'durations' => {}
|
16
|
+
}
|
12
17
|
end
|
13
18
|
|
14
19
|
def get!
|
@@ -19,6 +24,8 @@ module Enklawa
|
|
19
24
|
get_programs!
|
20
25
|
get_episodes!
|
21
26
|
|
27
|
+
File.open(ENKLAWA_CACHE_FILE, 'w') {|f| f.write @cache.to_yaml }
|
28
|
+
|
22
29
|
@response
|
23
30
|
end
|
24
31
|
|
@@ -87,6 +94,37 @@ module Enklawa
|
|
87
94
|
end
|
88
95
|
end
|
89
96
|
|
97
|
+
def check_if_image_exists_or_use_from_program(program, episode)
|
98
|
+
return @cache['images'][episode.id] if @cache['images'].key?(episode.id)
|
99
|
+
image = "http://www.enklawa.net/images/episodes/#{episode.id}.jpg"
|
100
|
+
|
101
|
+
uri = URI(image)
|
102
|
+
|
103
|
+
request = Net::HTTP.new uri.host
|
104
|
+
response = request.request_head uri.path
|
105
|
+
unless response.code.to_i == 200
|
106
|
+
image = program.image
|
107
|
+
end
|
108
|
+
|
109
|
+
@cache['images'][episode.id] = image
|
110
|
+
|
111
|
+
return image
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_duration(episode)
|
115
|
+
return @cache['durations'][episode.id] if @cache['durations'].key?(episode.id)
|
116
|
+
|
117
|
+
duration = nil
|
118
|
+
temp_output_file_name = "/tmp/episode_metadata.txt"
|
119
|
+
`ffmpeg2theora #{episode.mp3} > #{temp_output_file_name} 2>&1`
|
120
|
+
if open(temp_output_file_name).read.match(/.+Duration:\s+(\d{2}):(\d{2}):(\d{2}).+/i)
|
121
|
+
duration = ($3.to_i * 1000) + ($2.to_i * 60 * 1000) + ($1.to_i * 3600 * 1000)
|
122
|
+
@cache['durations'][episode.id] = duration
|
123
|
+
end
|
124
|
+
|
125
|
+
return duration
|
126
|
+
end
|
127
|
+
|
90
128
|
def build_episode_from_entry(entry, program)
|
91
129
|
episode = Episode.new
|
92
130
|
episode.id = entry.id
|
@@ -100,8 +138,8 @@ module Enklawa
|
|
100
138
|
temp_output_file_name = "/tmp/episode_metadata_#{episode.id}.txt"
|
101
139
|
`ffmpeg2theora #{episode.mp3} > #{temp_output_file_name} 2>&1` unless File.exists?(temp_output_file_name)
|
102
140
|
if open(temp_output_file_name).read.match(/.+Duration:\s+(\d{2}):(\d{2}):(\d{2}).+/i)
|
103
|
-
episode.duration =
|
104
|
-
episode.check_if_image_exists_or_use_from_program(program)
|
141
|
+
episode.duration =
|
142
|
+
episode.image = check_if_image_exists_or_use_from_program(program, episode)
|
105
143
|
program << episode
|
106
144
|
end
|
107
145
|
end
|
data/lib/enklawa/api/response.rb
CHANGED
data/lib/enklawa/api/version.rb
CHANGED
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
|
+
version: 0.1.3
|
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-
|
11
|
+
date: 2014-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|