lyrics-ebook 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/LICENSE +340 -0
  2. data/README +46 -0
  3. data/bin/lyrics-ebook +47 -0
  4. data/lib/eeepub/LICENSE +20 -0
  5. data/lib/eeepub/README.md +77 -0
  6. data/lib/eeepub/Rakefile +49 -0
  7. data/lib/eeepub/VERSION +1 -0
  8. data/lib/eeepub/examples/files/bar.html +42 -0
  9. data/lib/eeepub/examples/files/foo.html +42 -0
  10. data/lib/eeepub/examples/simple_epub.rb +25 -0
  11. data/lib/eeepub/lib/eeepub.rb +17 -0
  12. data/lib/eeepub/lib/eeepub/container_item.rb +108 -0
  13. data/lib/eeepub/lib/eeepub/easy.rb +100 -0
  14. data/lib/eeepub/lib/eeepub/maker.rb +127 -0
  15. data/lib/eeepub/lib/eeepub/ncx.rb +68 -0
  16. data/lib/eeepub/lib/eeepub/ocf.rb +112 -0
  17. data/lib/eeepub/lib/eeepub/opf.rb +148 -0
  18. data/lib/eeepub/spec/eeepub/easy_spec.rb +66 -0
  19. data/lib/eeepub/spec/eeepub/maker_spec.rb +124 -0
  20. data/lib/eeepub/spec/eeepub/ncx_spec.rb +80 -0
  21. data/lib/eeepub/spec/eeepub/ocf_spec.rb +43 -0
  22. data/lib/eeepub/spec/eeepub/opf_spec.rb +262 -0
  23. data/lib/eeepub/spec/eeepub_spec.rb +4 -0
  24. data/lib/eeepub/spec/spec_helper.rb +12 -0
  25. data/lib/lyrics_ebook.rb +71 -0
  26. data/lib/lyrics_ebook/cache2html.rb +33 -0
  27. data/lib/lyrics_ebook/cache_manager.rb +77 -0
  28. data/lib/lyrics_ebook/lyric.rb +32 -0
  29. data/lib/lyrics_ebook/lyric_download.rb +50 -0
  30. data/lib/lyrics_ebook/lyrics2html.rb +106 -0
  31. data/lib/lyrics_ebook/mini_lyrics_parser.rb +26 -0
  32. data/lib/lyrics_ebook/mp3_parser.rb +37 -0
  33. data/lib/wiki_lyrics/amarok/COPYING +340 -0
  34. data/lib/wiki_lyrics/amarok/README +51 -0
  35. data/lib/wiki_lyrics/amarok/amarok.rb +355 -0
  36. data/lib/wiki_lyrics/amarok/pluginadapter.rb +113 -0
  37. data/lib/wiki_lyrics/amarok/plugins.rb +95 -0
  38. data/lib/wiki_lyrics/amarok/wikilyrics.rb +578 -0
  39. data/lib/wiki_lyrics/amarok/wikilyrics.spec +4 -0
  40. data/lib/wiki_lyrics/amarok/wikipluginadapter.rb +392 -0
  41. data/lib/wiki_lyrics/cli/optionsparser.rb +228 -0
  42. data/lib/wiki_lyrics/cli/pluginadapter.rb +56 -0
  43. data/lib/wiki_lyrics/cli/plugins.rb +79 -0
  44. data/lib/wiki_lyrics/cli/wikilyrics.rb +178 -0
  45. data/lib/wiki_lyrics/cli/wikipluginadapter.rb +140 -0
  46. data/lib/wiki_lyrics/docs/COPYING +340 -0
  47. data/lib/wiki_lyrics/docs/ChangeLog +293 -0
  48. data/lib/wiki_lyrics/docs/HOWTO.pdf +0 -0
  49. data/lib/wiki_lyrics/docs/HOWTO.tex +151 -0
  50. data/lib/wiki_lyrics/docs/HOWTO.txt +139 -0
  51. data/lib/wiki_lyrics/docs/README +45 -0
  52. data/lib/wiki_lyrics/docs/TODO +12 -0
  53. data/lib/wiki_lyrics/gui/gui-gtk.rb +945 -0
  54. data/lib/wiki_lyrics/gui/gui-qt3.rb +785 -0
  55. data/lib/wiki_lyrics/gui/gui-qt4.rb +845 -0
  56. data/lib/wiki_lyrics/gui/gui-tk.rb +1104 -0
  57. data/lib/wiki_lyrics/gui/gui.rb +268 -0
  58. data/lib/wiki_lyrics/gui/test.rb +74 -0
  59. data/lib/wiki_lyrics/i18n/README +1 -0
  60. data/lib/wiki_lyrics/i18n/en.rb +181 -0
  61. data/lib/wiki_lyrics/i18n/es.rb +181 -0
  62. data/lib/wiki_lyrics/i18n/i18n.rb +126 -0
  63. data/lib/wiki_lyrics/i18n/sk.rb +174 -0
  64. data/lib/wiki_lyrics/itrans/COPYRIGHT +31 -0
  65. data/lib/wiki_lyrics/itrans/itrans +0 -0
  66. data/lib/wiki_lyrics/itrans/itrans.txt +8 -0
  67. data/lib/wiki_lyrics/itrans/lyric.txt +23 -0
  68. data/lib/wiki_lyrics/itrans/udvng.ifm +206 -0
  69. data/lib/wiki_lyrics/lyrics.rb +567 -0
  70. data/lib/wiki_lyrics/lyrics_AZLyrics.rb +113 -0
  71. data/lib/wiki_lyrics/lyrics_DarkLyrics.rb +124 -0
  72. data/lib/wiki_lyrics/lyrics_Giitaayan.rb +124 -0
  73. data/lib/wiki_lyrics/lyrics_Jamendo.rb +166 -0
  74. data/lib/wiki_lyrics/lyrics_LeosLyrics.rb +142 -0
  75. data/lib/wiki_lyrics/lyrics_LoudSongs.rb +135 -0
  76. data/lib/wiki_lyrics/lyrics_LyricWiki.rb +329 -0
  77. data/lib/wiki_lyrics/lyrics_LyricsDownload.rb +118 -0
  78. data/lib/wiki_lyrics/lyrics_LyricsMania.rb +141 -0
  79. data/lib/wiki_lyrics/lyrics_Lyriki.rb +287 -0
  80. data/lib/wiki_lyrics/lyrics_SeekLyrics.rb +108 -0
  81. data/lib/wiki_lyrics/lyrics_Sing365.rb +103 -0
  82. data/lib/wiki_lyrics/lyrics_TerraLetras.rb +126 -0
  83. data/lib/wiki_lyrics/mediawikilyrics.rb +1464 -0
  84. data/lib/wiki_lyrics/tests/plugin_tests.rb +161 -0
  85. data/lib/wiki_lyrics/tests/tests.rb +74 -0
  86. data/lib/wiki_lyrics/utils/formdata.rb +56 -0
  87. data/lib/wiki_lyrics/utils/htmlentities.rb +291 -0
  88. data/lib/wiki_lyrics/utils/http.rb +198 -0
  89. data/lib/wiki_lyrics/utils/itrans.rb +160 -0
  90. data/lib/wiki_lyrics/utils/kde.rb +88 -0
  91. data/lib/wiki_lyrics/utils/logger.rb +123 -0
  92. data/lib/wiki_lyrics/utils/strings.rb +378 -0
  93. data/lib/wiki_lyrics/utils/xmlhash.rb +111 -0
  94. data/lib/wiki_lyrics/wikilyrics.kdevelop +152 -0
  95. data/lib/wiki_lyrics/wikilyrics.kdevses +18 -0
  96. data/lib/wiki_lyrics/win/gtk_fix.bat +3 -0
  97. data/lib/wiki_lyrics/win/tk_fix.bat +3 -0
  98. data/lib/wiki_lyrics/win/wikilyrics.bat +4 -0
  99. data/lib/wiki_lyrics/win/win_fix.rb +52 -0
  100. data/templates/art_.erb.xhtml +29 -0
  101. data/templates/artists.erb.xhtml +19 -0
  102. data/templates/cover.erb.xhtml +22 -0
  103. data/test/cache_manager_test.rb +73 -0
  104. data/test/data/artist name/title name.lyric +6 -0
  105. data/test/lyric_test.rb +41 -0
  106. metadata +194 -0
@@ -0,0 +1,198 @@
1
+ # Copyright (C) 2006-2008 by Sergio Pistone
2
+ # sergio_pistone@yahoo.com.ar
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the
16
+ # Free Software Foundation, Inc.,
17
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
+
19
+ require File.expand_path( File.dirname( __FILE__ ) + "/formdata" )
20
+
21
+ require "net/http"
22
+ require "uri"
23
+
24
+ module HTTP
25
+
26
+ # @@user_agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2"
27
+ @@user_agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.9) Gecko/20071110 Firefox/2.0.0.9"
28
+ # @@user_agent = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.12) Gecko/20080218 Firefox/2.0.0.12"
29
+
30
+ @@proxy_url = nil
31
+ @@proxy_excluded_urls = []
32
+ @@proxy_reverse = false # if true, excluded_urls list becomes a list with the _only_ urls the proxy should be used for
33
+
34
+ def HTTP.normalize_url( url, protocol="http" )
35
+ url = url.strip()
36
+ protocol_regexp = /^ *([^: ]+):\/+/
37
+ md = protocol_regexp.match( url )
38
+ return nil if md && md[1] != protocol
39
+ url.gsub!( /\/+$/, "" ) # remove / at the end of the url
40
+ url.gsub!( protocol_regexp, "" ) # remove the protocol part if there was one
41
+ return "#{protocol}://#{url}" # reinsert protocol part assuring protocol:// form
42
+ end
43
+
44
+ def HTTP.set_proxy_settings( proxy_url, excluded_urls=[], reverse=false )
45
+ @@proxy_url = proxy_url ? HTTP.normalize_url( proxy_url, "http" ) : nil
46
+ @@proxy_reverse = @@proxy_url ? reverse : false
47
+ @@proxy_excluded_urls = []
48
+ if @@proxy_url
49
+ excluded_urls.each() do |url|
50
+ url = normalize_url( url, "http" )
51
+ @@proxy_excluded_urls.insert( -1, url ) if url && ! @@proxy_excluded_urls.include?( url )
52
+ end
53
+ end
54
+ end
55
+
56
+ def HTTP.get_proxy_settings()
57
+ ret = [@@proxy_url ? @@proxy_url.dup : nil, [], @@proxy_reverse]
58
+ @@proxy_excluded_urls.each() { |url| ret[1][ret[1].size] = url.dup }
59
+ return ret
60
+ end
61
+
62
+ # returns proxy_host, proxy_port, proxy_user, proxy_pass for given url
63
+ def HTTP.get_url_proxy_settings( url )
64
+
65
+ return nil, nil, nil, nil if ! @@proxy_url
66
+ proxy = HTTP.parse_uri( @@proxy_url )
67
+ return nil, nil, nil, nil if ! proxy.host
68
+ proxy.port = 80 if ! proxy.port
69
+
70
+ # check if given url should be treated specially
71
+ exception = false
72
+ @@proxy_excluded_urls.each() do |exception_url|
73
+ if url.index( exception_url ) == 0
74
+ exception = true
75
+ break
76
+ end
77
+ end
78
+
79
+ if exception && @@proxy_reverse || ! exception && ! @@proxy_reverse
80
+ return proxy.host, proxy.port, proxy.user, proxy.password
81
+ else
82
+ return nil, nil, nil, nil
83
+ end
84
+ end
85
+
86
+ def HTTP.parse_uri( uri )
87
+ begin
88
+ return URI.parse( uri )
89
+ rescue URI::InvalidURIError
90
+ return URI.parse( URI.escape( uri ) )
91
+ end
92
+ end
93
+
94
+ def HTTP.fetch_page_get( url, headers=nil, follow=10 )
95
+ begin
96
+
97
+ p_url = HTTP.parse_uri( url )
98
+ return nil, url if p_url.host == nil || p_url.port == nil || p_url.request_uri == nil
99
+ proxy_host, proxy_port, proxy_user, proxy_pass = HTTP.get_url_proxy_settings( url )
100
+
101
+ full_headers = {
102
+ "User-Agent" => @@user_agent,
103
+ "Referer" => "#{p_url.scheme}://#{p_url.host}",
104
+ }
105
+ full_headers.merge!( headers ) if headers
106
+
107
+ http = Net::HTTP.new( p_url.host, p_url.port, proxy_host, proxy_port, proxy_user, proxy_pass )
108
+ response = http.request_get( p_url.request_uri, full_headers )
109
+
110
+ case response
111
+ when Net::HTTPSuccess
112
+ when Net::HTTPRedirection, Net::HTTPFound
113
+ if follow == 0
114
+ response = nil
115
+ elsif follow > 0
116
+ response, url = HTTP.fetch_page_get( response["location"], nil, follow-1 )
117
+ end
118
+ else
119
+ response = nil
120
+ end
121
+
122
+ return response, url
123
+
124
+ rescue Errno::ETIMEDOUT, Errno::EBADF, EOFError => e
125
+ raise TimeoutError.new( e.to_s )
126
+ end
127
+ end
128
+
129
+ def HTTP.fetch_page_post( url, params, headers=nil, follow=10 )
130
+ begin
131
+ p_url = HTTP.parse_uri( url )
132
+ return nil, url if p_url.host == nil || p_url.port == nil || p_url.request_uri == nil
133
+ proxy_host, proxy_port, proxy_user, proxy_pass = HTTP.get_url_proxy_settings( url )
134
+
135
+ data, full_headers = URLEncodedFormData.prepare_query( params )
136
+ full_headers["User-Agent"] = @@user_agent
137
+ full_headers["Referer"] = "#{p_url.scheme}://#{p_url.host}"
138
+ full_headers.merge!( headers ) if headers
139
+
140
+ http = Net::HTTP.new( p_url.host, p_url.port, proxy_host, proxy_port, proxy_user, proxy_pass )
141
+ response = http.request_post( p_url.request_uri, data, full_headers )
142
+
143
+ case response
144
+ when Net::HTTPSuccess
145
+ when Net::HTTPRedirection, Net::HTTPFound
146
+ if follow == 0
147
+ response = nil
148
+ elsif follow > 0
149
+ response, url = HTTP.fetch_page_get( response["location"], nil, follow-1 )
150
+ end
151
+ else
152
+ response = nil
153
+ end
154
+
155
+ return response, url
156
+
157
+ rescue Errno::ETIMEDOUT, Errno::EBADF, EOFError => e
158
+ raise TimeoutError.new( e.to_s )
159
+ end
160
+ end
161
+
162
+ def HTTP.fetch_page_post_form_multipart( url, params, headers=nil, follow=10 )
163
+ begin
164
+
165
+ p_url = HTTP.parse_uri( url )
166
+ return nil, url if p_url.host == nil || p_url.port == nil || p_url.request_uri == nil
167
+ proxy_host, proxy_port, proxy_user, proxy_pass = HTTP.get_url_proxy_settings( url )
168
+
169
+ data, full_headers = MultipartFormData.prepare_query( params )
170
+ full_headers["User-Agent"] = @@user_agent
171
+ full_headers["Referer"] = "#{p_url.scheme}://#{p_url.host}"
172
+ full_headers.merge!( headers ) if headers
173
+
174
+ http = Net::HTTP.new( p_url.host, p_url.port, proxy_host, proxy_port, proxy_user, proxy_pass )
175
+ response = http.request_post( p_url.request_uri, data, full_headers )
176
+
177
+ case response
178
+ when Net::HTTPSuccess
179
+ when Net::HTTPRedirection, Net::HTTPFound
180
+ if follow == 0
181
+ response = nil
182
+ elsif follow > 0
183
+ response, url = HTTP.fetch_page_get( response["location"], nil, follow-1 )
184
+ end
185
+ else
186
+ response = nil
187
+ end
188
+
189
+ return response, url
190
+
191
+ rescue Errno::ETIMEDOUT, Errno::EBADF, EOFError => e
192
+ raise TimeoutError.new( e.to_s )
193
+ end
194
+ end
195
+
196
+ end
197
+
198
+
@@ -0,0 +1,160 @@
1
+ # Copyright (C) 2006-2008 by Sergio Pistone
2
+ # sergio_pistone@yahoo.com.ar
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the
16
+ # Free Software Foundation, Inc.,
17
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
+
19
+ require File.expand_path( File.dirname( __FILE__ ) + "/strings" )
20
+
21
+ module ITRANS
22
+
23
+ @@itrans_dir = File.dirname( File.expand_path(__FILE__) ) + "/../itrans"
24
+ @@null_dev = "/dev/null"
25
+
26
+ def ITRANS.normalize( text )
27
+ return ITRANS.from_devanagari!( ITRANS.to_devanagari( text ) )
28
+ end
29
+
30
+ def ITRANS.to_devanagari!( text )
31
+ text.replace( to_devanagari( text ) )
32
+ end
33
+
34
+ def ITRANS.to_devanagari( text )
35
+ orig_pwd = Dir.pwd()
36
+ Dir.chdir( @@itrans_dir )
37
+ trans = `echo #{Strings.shell_quote( "#indianifm=udvng.ifm\n #indian\n#{text}\n#endindian" )} | #{@@itrans_dir}/itrans -U 2>#{@@null_dev}`
38
+ Dir.chdir( orig_pwd )
39
+ trans.gsub!( /%[^\n]*/, "" ) # TODO search line
40
+ trans.strip!()
41
+ return trans
42
+ end
43
+
44
+ def ITRANS.from_devanagari!( text )
45
+ @@devanagari2itrans.each() do |devana, itrans|
46
+ text.gsub!( devana, itrans )
47
+ end
48
+ @@devanagari2itrans_consonants.each() do |devana, itrans|
49
+ # is the only symbol in the 'word' --> add an 'a' at the end:
50
+ text.gsub!( /(^|[ ""\.:;\(\[])#{devana}([,;:?!\)\]\s]|$)/, "\\1#{itrans}a\\2" )
51
+ # is not followed by a vocal --> add an 'a' at the end:
52
+ text.gsub!( /#{devana}([^aeiouAEIOU,;:?!\)\]\s])/, "#{itrans}a\\1" )
53
+ text.gsub!( devana, itrans )
54
+ end
55
+ return text
56
+ end
57
+
58
+ def ITRANS.from_devanagari( text )
59
+ return ITRANS.from_devanagari!( String.new( text ) )
60
+ end
61
+
62
+ def ITRANS.unicode( codepoint )
63
+ [codepoint].pack( "U*" )
64
+ end
65
+
66
+ @@devanagari2itrans = {
67
+ ITRANS.unicode( 0x0901 ) => "",
68
+
69
+ # vowels:
70
+ ITRANS.unicode( 0x0905 ) => "a",
71
+ ITRANS.unicode( 0x0906 ) => "aa", # /A
72
+ ITRANS.unicode( 0x093E ) => "aa", # /A
73
+ ITRANS.unicode( 0x0907 ) => "i",
74
+ ITRANS.unicode( 0x093F ) => "i",
75
+ ITRANS.unicode( 0x0908 ) => "ii", # /I
76
+ ITRANS.unicode( 0x0940 ) => "ii", # /I
77
+ ITRANS.unicode( 0x0909 ) => "u",
78
+ ITRANS.unicode( 0x0941 ) => "u",
79
+ ITRANS.unicode( 0x090A ) => "uu", # /U
80
+ ITRANS.unicode( 0x0942 ) => "uu", # /U
81
+ ITRANS.unicode( 0x090B ) => "RRi", # R^i
82
+ ITRANS.unicode( 0x0943 ) => "RRi", # R^i
83
+ ITRANS.unicode( 0x090C ) => "LLi", # L^i
84
+ ITRANS.unicode( 0x0944 ) => "LLi", # L^i
85
+ ITRANS.unicode( 0x090F ) => "e",
86
+ ITRANS.unicode( 0x0947 ) => "e",
87
+ ITRANS.unicode( 0x0910 ) => "ai",
88
+ ITRANS.unicode( 0x0948 ) => "ai",
89
+ ITRANS.unicode( 0x0913 ) => "o",
90
+ ITRANS.unicode( 0x094B ) => "o",
91
+ ITRANS.unicode( 0x0914 ) => "au",
92
+ ITRANS.unicode( 0x094C ) => "au",
93
+ # itrans irregular
94
+ "क्ष"=> "kSh", # x / kS
95
+ "त्र"=> "tr",
96
+ "ज्ञ"=> "j~n", # GY / dny
97
+ "श्र"=> "shr",
98
+ }
99
+
100
+ @@devanagari2itrans_consonants = {
101
+ # gutturals:
102
+ ITRANS.unicode( 0x0915 ) => "k",
103
+ ITRANS.unicode( 0x0916 ) => "kh",
104
+ # ITRANS.unicode( 0x0916 ) => ".Nkh",
105
+ ITRANS.unicode( 0x0917 ) => "g",
106
+ ITRANS.unicode( 0x0918 ) => "gh",
107
+ ITRANS.unicode( 0x0918 ) => "~N",
108
+ # palatals:
109
+ ITRANS.unicode( 0x091A ) => "ch",
110
+ ITRANS.unicode( 0x091B ) => "Ch",
111
+ ITRANS.unicode( 0x091C ) => "j",
112
+ ITRANS.unicode( 0x091D ) => "jh",
113
+ ITRANS.unicode( 0x091E ) => "~n", # JN
114
+ # retroflexes:
115
+ ITRANS.unicode( 0x091F ) => "T",
116
+ ITRANS.unicode( 0x0920 ) => "Th",
117
+ ITRANS.unicode( 0x0921 ) => "D",
118
+ ITRANS.unicode( 0x0922 ) => "Dh",
119
+ # ITRANS.unicode( 0x0922 ) => ".Dh", # Rh (valid?)
120
+ ITRANS.unicode( 0x0923 ) => "N",
121
+ # dentals:
122
+ ITRANS.unicode( 0x0924 ) => "t",
123
+ ITRANS.unicode( 0x0925 ) => "th",
124
+ ITRANS.unicode( 0x0926 ) => "d",
125
+ ITRANS.unicode( 0x0927 ) => "dh",
126
+ ITRANS.unicode( 0x0928 ) => "n",
127
+ # labials:
128
+ ITRANS.unicode( 0x092A ) => "p",
129
+ ITRANS.unicode( 0x092B ) => "ph",
130
+ ITRANS.unicode( 0x092C ) => "b",
131
+ ITRANS.unicode( 0x092D ) => "bh",
132
+ ITRANS.unicode( 0x092E ) => "m",
133
+ # semi-vowels:
134
+ ITRANS.unicode( 0x092F ) => "y",
135
+ ITRANS.unicode( 0x0930 ) => "r",
136
+ ITRANS.unicode( 0x0932 ) => "l",
137
+ ITRANS.unicode( 0x0935 ) => "v", # w
138
+ # sibilants:
139
+ ITRANS.unicode( 0x0936 ) => "sh",
140
+ ITRANS.unicode( 0x0937 ) => "Sh", # shh
141
+ ITRANS.unicode( 0x0938 ) => "s",
142
+ # miscellaneous:
143
+ ITRANS.unicode( 0x0939 ) => "h",
144
+ ITRANS.unicode( 0x0902 ) => ".n", # M / .m
145
+ ITRANS.unicode( 0x0903 ) => "H", # .h
146
+ ITRANS.unicode( 0x0950 ) => "OM", # AUM
147
+ # other consonants:
148
+ "क़" => "q",
149
+ ITRANS.unicode( 0x0958 ) => "q",
150
+ "ख़" => "Kh",
151
+ "ग़" => "G",
152
+ "ज़" => "z",
153
+ ITRANS.unicode( 0x095B ) => "z",
154
+ "फ़" => "f",
155
+ "ड़" => ".D", # R
156
+ ITRANS.unicode( 0x095C ) => ".D", # R (valid?)
157
+ "ढ़" => ".Dh", # Rh
158
+ }
159
+
160
+ end
@@ -0,0 +1,88 @@
1
+ # Copyright (C) 2006-2008 by Sergio Pistone
2
+ # sergio_pistone@yahoo.com.ar
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the
16
+ # Free Software Foundation, Inc.,
17
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
+
19
+ require File.expand_path( File.dirname( __FILE__ ) + "/http" )
20
+
21
+ module KDE
22
+
23
+ @@proxy_settings_file = "#{ENV["HOME"]}/.kde/share/config/kioslaverc"
24
+
25
+ @@cfg_type_regexp = /^ *ProxyType *= *([0-4]+) *$/
26
+ @@excluded_regexp = /^ *NoProxyFor *= *([^ ]+) *$/
27
+ @@reverse_regexp = /^ *ReversedException *= *([^ ]+) *$/
28
+ @@protocol_regexp = /^ *([^: ]+):\/+/
29
+
30
+ # returns proxy_url, excluded_urls, reverse
31
+ def KDE.get_proxy_settings( protocol="http" )
32
+
33
+ protocol = protocol.downcase()
34
+ raise ArgumentError( "Invalid protocol specified" ) if ! ["http", "https", "ftp"].include?( protocol )
35
+
36
+ proxy_regexp = /^ *#{protocol}Proxy *= *([^ ]+) *$/
37
+
38
+ cfg_type = proxy_url = excluded_urls = reverse = ""
39
+ begin
40
+ File.open( @@proxy_settings_file ).each() do |row|
41
+ row.chomp!()
42
+ md = @@cfg_type_regexp.match( row )
43
+ cfg_type = md[1] if md
44
+ md = proxy_regexp.match( row )
45
+ proxy_url = md[1] if md
46
+ md = @@excluded_regexp.match( row )
47
+ excluded_urls = md[1] if md
48
+ md = @@reverse_regexp.match( row )
49
+ reverse = md[1] if md
50
+ end
51
+ rescue Exception => e
52
+ puts "Error reading KDE proxy settings file: " + e.to_s()
53
+ return nil, [], false
54
+ end
55
+
56
+ # cfg_type == 0: connect directly to the internet
57
+ # cfg_type == 1: manual configuration
58
+ # cfg_type == 2: use proxy configuration url (can't do anything with this one)
59
+ # cfg_type == 3: detect automatically (can't do anything with this one either)
60
+ # cfg_type == 4: same as manual configuration but values are read from enviroment variables
61
+
62
+ if cfg_type != "1" && cfg_type != "4"
63
+ return nil, [], false
64
+ elsif cfg_type == "4"
65
+ proxy_url = ENV[proxy].to_s().strip()
66
+ excluded_urls = ENV[excluded_urls].to_s().strip()
67
+ end
68
+
69
+ return nil, [], false if proxy_url == ""
70
+
71
+ # verify proxy_url
72
+ proxy_url = HTTP.normalize_url( proxy_url, "http" )
73
+ return nil, [], false if proxy_url == nil
74
+
75
+ # parse excluded_urls list
76
+ excluded_urls_list = []
77
+ excluded_urls.split( "," ).each() do |url|
78
+ url = HTTP.normalize_url( url, "http" )
79
+ excluded_urls_list.insert( -1, url ) if url && !excluded_urls_list.include?( url )
80
+ end
81
+
82
+ reverse = reverse.strip().downcase() == "true"
83
+
84
+ return proxy_url, excluded_urls_list, reverse
85
+ end
86
+
87
+ end
88
+
@@ -0,0 +1,123 @@
1
+ # Copyright (C) 2006-2008 by Sergio Pistone
2
+ # sergio_pistone@yahoo.com.ar
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the
16
+ # Free Software Foundation, Inc.,
17
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
+
19
+ class Logger
20
+
21
+ def initialize( file_path, truncate_to_lines=-1 )
22
+ @file_path = file_path
23
+ @tabulation = nil
24
+ @tabulation_base = " ".freeze()
25
+ @tabulation_level = 0
26
+ @skip_first_line_tabulation = false
27
+ truncate( truncate_to_lines ) if truncate_to_lines >= 0
28
+ end
29
+
30
+ def finalize() # TODO revise implementation
31
+ end
32
+
33
+ def get_file_path()
34
+ return @file_path
35
+ end
36
+
37
+ def set_file_path( file_path )
38
+ if @file_path != file_path
39
+ File.delete( @file_path ) if File.exist?( @file_path ) && ! File.directory?( @file_path )
40
+ @file_path = file_path.clone().freeze()
41
+ end
42
+ end
43
+
44
+ def truncate( max_lines )
45
+ begin
46
+ file = File.new( @file_path, File::RDONLY )
47
+ rescue Errno::ENOENT
48
+ file = File.new( @file_path, File::CREAT|File::TRUNC )
49
+ end
50
+ lines = file.read().split( "\n" )
51
+ file.close()
52
+ offset = lines.size() - max_lines
53
+ if offset > 0
54
+ file = File.new( @file_path, File::CREAT|File::TRUNC|File::WRONLY )
55
+ max_lines.times() do |index|
56
+ line = lines[offset + index]
57
+ break if ! line
58
+ file.write( line )
59
+ file.write( "\n" )
60
+ end
61
+ file.close()
62
+ end
63
+ end
64
+
65
+ def reset()
66
+ output = File.new( @file_path, File::CREAT|File::TRUNC )
67
+ output.close()
68
+ end
69
+
70
+ def log( msg, new_lines=1 )
71
+ output = File.new( @file_path, File::CREAT|File::APPEND|File::WRONLY )
72
+ if @tabulation
73
+ output.write( @tabulation ) if ! @skip_first_line_tabulation
74
+ output.write( msg.gsub( "\n", "\n#{@tabulation}" ) )
75
+ @skip_first_line_tabulation = new_lines <= 0
76
+ else
77
+ output.write( msg )
78
+ end
79
+ new_lines.times() { output.write( "\n" ) }
80
+ output.close()
81
+ end
82
+
83
+ def get_tabulation_base()
84
+ return @tabulation_base
85
+ end
86
+
87
+ def set_tabulation_base( tabulation_base )
88
+ if @tabulation_base != tabulation_base
89
+ @tabulation_level = tabulation_base.clone().freeze()
90
+ if level <= 0
91
+ @tabulation = nil
92
+ else
93
+ @tabulation = ""
94
+ level.times() { @tabulation << @tabulation_base }
95
+ end
96
+ end
97
+ end
98
+
99
+ def get_tabulation_level()
100
+ return @tabulation_level
101
+ end
102
+
103
+ def set_tabulation_level( level )
104
+ if @tabulation_level != level
105
+ @tabulation_level = level
106
+ if level <= 0
107
+ @tabulation = nil
108
+ else
109
+ @tabulation = ""
110
+ level.times() { @tabulation << @tabulation_base }
111
+ end
112
+ end
113
+ end
114
+
115
+ def increase_tabulation_level()
116
+ set_tabulation_level( @tabulation_level + 1 )
117
+ end
118
+
119
+ def decrease_tabulation_level()
120
+ set_tabulation_level( @tabulation_level - 1 )
121
+ end
122
+
123
+ end