Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/rss
File: itunes.rb
# frozen_string_literal: false
[0] Fix | Delete
require 'rss/2.0'
[1] Fix | Delete
[2] Fix | Delete
module RSS
[3] Fix | Delete
# The prefix for the iTunes XML namespace.
[4] Fix | Delete
ITUNES_PREFIX = 'itunes'
[5] Fix | Delete
# The URI of the iTunes specification.
[6] Fix | Delete
ITUNES_URI = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
[7] Fix | Delete
[8] Fix | Delete
Rss.install_ns(ITUNES_PREFIX, ITUNES_URI)
[9] Fix | Delete
[10] Fix | Delete
module ITunesModelUtils
[11] Fix | Delete
include Utils
[12] Fix | Delete
[13] Fix | Delete
def def_class_accessor(klass, name, type, *args)
[14] Fix | Delete
normalized_name = name.gsub(/-/, "_")
[15] Fix | Delete
full_name = "#{ITUNES_PREFIX}_#{normalized_name}"
[16] Fix | Delete
klass_name = "ITunes#{Utils.to_class_name(normalized_name)}"
[17] Fix | Delete
[18] Fix | Delete
case type
[19] Fix | Delete
when :element, :attribute
[20] Fix | Delete
klass::ELEMENTS << full_name
[21] Fix | Delete
def_element_class_accessor(klass, name, full_name, klass_name, *args)
[22] Fix | Delete
when :elements
[23] Fix | Delete
klass::ELEMENTS << full_name
[24] Fix | Delete
def_elements_class_accessor(klass, name, full_name, klass_name, *args)
[25] Fix | Delete
else
[26] Fix | Delete
klass.install_must_call_validator(ITUNES_PREFIX, ITUNES_URI)
[27] Fix | Delete
klass.install_text_element(normalized_name, ITUNES_URI, "?",
[28] Fix | Delete
full_name, type, name)
[29] Fix | Delete
end
[30] Fix | Delete
end
[31] Fix | Delete
[32] Fix | Delete
def def_element_class_accessor(klass, name, full_name, klass_name,
[33] Fix | Delete
recommended_attribute_name=nil)
[34] Fix | Delete
klass.install_have_child_element(name, ITUNES_PREFIX, "?", full_name)
[35] Fix | Delete
end
[36] Fix | Delete
[37] Fix | Delete
def def_elements_class_accessor(klass, name, full_name, klass_name,
[38] Fix | Delete
plural_name, recommended_attribute_name=nil)
[39] Fix | Delete
full_plural_name = "#{ITUNES_PREFIX}_#{plural_name}"
[40] Fix | Delete
klass.install_have_children_element(name, ITUNES_PREFIX, "*",
[41] Fix | Delete
full_name, full_plural_name)
[42] Fix | Delete
end
[43] Fix | Delete
end
[44] Fix | Delete
[45] Fix | Delete
module ITunesBaseModel
[46] Fix | Delete
extend ITunesModelUtils
[47] Fix | Delete
[48] Fix | Delete
ELEMENTS = []
[49] Fix | Delete
[50] Fix | Delete
ELEMENT_INFOS = [["author"],
[51] Fix | Delete
["block", :yes_other],
[52] Fix | Delete
["explicit", :explicit_clean_other],
[53] Fix | Delete
["keywords", :csv],
[54] Fix | Delete
["subtitle"],
[55] Fix | Delete
["summary"]]
[56] Fix | Delete
end
[57] Fix | Delete
[58] Fix | Delete
module ITunesChannelModel
[59] Fix | Delete
extend BaseModel
[60] Fix | Delete
extend ITunesModelUtils
[61] Fix | Delete
include ITunesBaseModel
[62] Fix | Delete
[63] Fix | Delete
ELEMENTS = []
[64] Fix | Delete
[65] Fix | Delete
class << self
[66] Fix | Delete
def append_features(klass)
[67] Fix | Delete
super
[68] Fix | Delete
[69] Fix | Delete
return if klass.instance_of?(Module)
[70] Fix | Delete
ELEMENT_INFOS.each do |name, type, *additional_infos|
[71] Fix | Delete
def_class_accessor(klass, name, type, *additional_infos)
[72] Fix | Delete
end
[73] Fix | Delete
end
[74] Fix | Delete
end
[75] Fix | Delete
[76] Fix | Delete
ELEMENT_INFOS = [
[77] Fix | Delete
["category", :elements, "categories", "text"],
[78] Fix | Delete
["image", :attribute, "href"],
[79] Fix | Delete
["owner", :element],
[80] Fix | Delete
["new-feed-url"],
[81] Fix | Delete
] + ITunesBaseModel::ELEMENT_INFOS
[82] Fix | Delete
[83] Fix | Delete
class ITunesCategory < Element
[84] Fix | Delete
include RSS09
[85] Fix | Delete
[86] Fix | Delete
@tag_name = "category"
[87] Fix | Delete
[88] Fix | Delete
class << self
[89] Fix | Delete
def required_prefix
[90] Fix | Delete
ITUNES_PREFIX
[91] Fix | Delete
end
[92] Fix | Delete
[93] Fix | Delete
def required_uri
[94] Fix | Delete
ITUNES_URI
[95] Fix | Delete
end
[96] Fix | Delete
end
[97] Fix | Delete
[98] Fix | Delete
[
[99] Fix | Delete
["text", "", true]
[100] Fix | Delete
].each do |name, uri, required|
[101] Fix | Delete
install_get_attribute(name, uri, required)
[102] Fix | Delete
end
[103] Fix | Delete
[104] Fix | Delete
ITunesCategory = self
[105] Fix | Delete
install_have_children_element("category", ITUNES_URI, "*",
[106] Fix | Delete
"#{ITUNES_PREFIX}_category",
[107] Fix | Delete
"#{ITUNES_PREFIX}_categories")
[108] Fix | Delete
[109] Fix | Delete
def initialize(*args)
[110] Fix | Delete
if Utils.element_initialize_arguments?(args)
[111] Fix | Delete
super
[112] Fix | Delete
else
[113] Fix | Delete
super()
[114] Fix | Delete
self.text = args[0]
[115] Fix | Delete
end
[116] Fix | Delete
end
[117] Fix | Delete
[118] Fix | Delete
def full_name
[119] Fix | Delete
tag_name_with_prefix(ITUNES_PREFIX)
[120] Fix | Delete
end
[121] Fix | Delete
[122] Fix | Delete
private
[123] Fix | Delete
def maker_target(categories)
[124] Fix | Delete
if text or !itunes_categories.empty?
[125] Fix | Delete
categories.new_category
[126] Fix | Delete
else
[127] Fix | Delete
nil
[128] Fix | Delete
end
[129] Fix | Delete
end
[130] Fix | Delete
[131] Fix | Delete
def setup_maker_attributes(category)
[132] Fix | Delete
category.text = text if text
[133] Fix | Delete
end
[134] Fix | Delete
[135] Fix | Delete
def setup_maker_elements(category)
[136] Fix | Delete
super(category)
[137] Fix | Delete
itunes_categories.each do |sub_category|
[138] Fix | Delete
sub_category.setup_maker(category)
[139] Fix | Delete
end
[140] Fix | Delete
end
[141] Fix | Delete
end
[142] Fix | Delete
[143] Fix | Delete
class ITunesImage < Element
[144] Fix | Delete
include RSS09
[145] Fix | Delete
[146] Fix | Delete
@tag_name = "image"
[147] Fix | Delete
[148] Fix | Delete
class << self
[149] Fix | Delete
def required_prefix
[150] Fix | Delete
ITUNES_PREFIX
[151] Fix | Delete
end
[152] Fix | Delete
[153] Fix | Delete
def required_uri
[154] Fix | Delete
ITUNES_URI
[155] Fix | Delete
end
[156] Fix | Delete
end
[157] Fix | Delete
[158] Fix | Delete
[
[159] Fix | Delete
["href", "", true]
[160] Fix | Delete
].each do |name, uri, required|
[161] Fix | Delete
install_get_attribute(name, uri, required)
[162] Fix | Delete
end
[163] Fix | Delete
[164] Fix | Delete
def initialize(*args)
[165] Fix | Delete
if Utils.element_initialize_arguments?(args)
[166] Fix | Delete
super
[167] Fix | Delete
else
[168] Fix | Delete
super()
[169] Fix | Delete
self.href = args[0]
[170] Fix | Delete
end
[171] Fix | Delete
end
[172] Fix | Delete
[173] Fix | Delete
def full_name
[174] Fix | Delete
tag_name_with_prefix(ITUNES_PREFIX)
[175] Fix | Delete
end
[176] Fix | Delete
[177] Fix | Delete
private
[178] Fix | Delete
def maker_target(target)
[179] Fix | Delete
if href
[180] Fix | Delete
target.itunes_image {|image| image}
[181] Fix | Delete
else
[182] Fix | Delete
nil
[183] Fix | Delete
end
[184] Fix | Delete
end
[185] Fix | Delete
[186] Fix | Delete
def setup_maker_attributes(image)
[187] Fix | Delete
image.href = href
[188] Fix | Delete
end
[189] Fix | Delete
end
[190] Fix | Delete
[191] Fix | Delete
class ITunesOwner < Element
[192] Fix | Delete
include RSS09
[193] Fix | Delete
[194] Fix | Delete
@tag_name = "owner"
[195] Fix | Delete
[196] Fix | Delete
class << self
[197] Fix | Delete
def required_prefix
[198] Fix | Delete
ITUNES_PREFIX
[199] Fix | Delete
end
[200] Fix | Delete
[201] Fix | Delete
def required_uri
[202] Fix | Delete
ITUNES_URI
[203] Fix | Delete
end
[204] Fix | Delete
end
[205] Fix | Delete
[206] Fix | Delete
install_must_call_validator(ITUNES_PREFIX, ITUNES_URI)
[207] Fix | Delete
[
[208] Fix | Delete
["name"],
[209] Fix | Delete
["email"],
[210] Fix | Delete
].each do |name,|
[211] Fix | Delete
ITunesBaseModel::ELEMENT_INFOS << name
[212] Fix | Delete
install_text_element(name, ITUNES_URI, nil, "#{ITUNES_PREFIX}_#{name}")
[213] Fix | Delete
end
[214] Fix | Delete
[215] Fix | Delete
def initialize(*args)
[216] Fix | Delete
if Utils.element_initialize_arguments?(args)
[217] Fix | Delete
super
[218] Fix | Delete
else
[219] Fix | Delete
super()
[220] Fix | Delete
self.itunes_name = args[0]
[221] Fix | Delete
self.itunes_email = args[1]
[222] Fix | Delete
end
[223] Fix | Delete
end
[224] Fix | Delete
[225] Fix | Delete
def full_name
[226] Fix | Delete
tag_name_with_prefix(ITUNES_PREFIX)
[227] Fix | Delete
end
[228] Fix | Delete
[229] Fix | Delete
private
[230] Fix | Delete
def maker_target(target)
[231] Fix | Delete
target.itunes_owner
[232] Fix | Delete
end
[233] Fix | Delete
[234] Fix | Delete
def setup_maker_element(owner)
[235] Fix | Delete
super(owner)
[236] Fix | Delete
owner.itunes_name = itunes_name
[237] Fix | Delete
owner.itunes_email = itunes_email
[238] Fix | Delete
end
[239] Fix | Delete
end
[240] Fix | Delete
end
[241] Fix | Delete
[242] Fix | Delete
module ITunesItemModel
[243] Fix | Delete
extend BaseModel
[244] Fix | Delete
extend ITunesModelUtils
[245] Fix | Delete
include ITunesBaseModel
[246] Fix | Delete
[247] Fix | Delete
class << self
[248] Fix | Delete
def append_features(klass)
[249] Fix | Delete
super
[250] Fix | Delete
[251] Fix | Delete
return if klass.instance_of?(Module)
[252] Fix | Delete
ELEMENT_INFOS.each do |name, type|
[253] Fix | Delete
def_class_accessor(klass, name, type)
[254] Fix | Delete
end
[255] Fix | Delete
end
[256] Fix | Delete
end
[257] Fix | Delete
[258] Fix | Delete
ELEMENT_INFOS = ITunesBaseModel::ELEMENT_INFOS +
[259] Fix | Delete
[["duration", :element, "content"]]
[260] Fix | Delete
[261] Fix | Delete
class ITunesDuration < Element
[262] Fix | Delete
include RSS09
[263] Fix | Delete
[264] Fix | Delete
@tag_name = "duration"
[265] Fix | Delete
[266] Fix | Delete
class << self
[267] Fix | Delete
def required_prefix
[268] Fix | Delete
ITUNES_PREFIX
[269] Fix | Delete
end
[270] Fix | Delete
[271] Fix | Delete
def required_uri
[272] Fix | Delete
ITUNES_URI
[273] Fix | Delete
end
[274] Fix | Delete
[275] Fix | Delete
def parse(duration, do_validate=true)
[276] Fix | Delete
if do_validate and /\A(?:
[277] Fix | Delete
\d?\d:[0-5]\d:[0-5]\d|
[278] Fix | Delete
[0-5]?\d:[0-5]\d|
[279] Fix | Delete
\d+
[280] Fix | Delete
)\z/x !~ duration
[281] Fix | Delete
raise ArgumentError,
[282] Fix | Delete
"must be one of HH:MM:SS, H:MM:SS, MM:SS, M:SS, S+: " +
[283] Fix | Delete
duration.inspect
[284] Fix | Delete
end
[285] Fix | Delete
[286] Fix | Delete
if duration.include?(':')
[287] Fix | Delete
components = duration.split(':')
[288] Fix | Delete
components[3..-1] = nil if components.size > 3
[289] Fix | Delete
[290] Fix | Delete
components.unshift("00") until components.size == 3
[291] Fix | Delete
components.collect do |component|
[292] Fix | Delete
component.to_i
[293] Fix | Delete
end
[294] Fix | Delete
else
[295] Fix | Delete
seconds_to_components(duration.to_i)
[296] Fix | Delete
end
[297] Fix | Delete
end
[298] Fix | Delete
[299] Fix | Delete
def construct(hours, minutes, seconds)
[300] Fix | Delete
components = [minutes, seconds]
[301] Fix | Delete
if components.include?(nil)
[302] Fix | Delete
nil
[303] Fix | Delete
else
[304] Fix | Delete
components.unshift(hours) if hours and hours > 0
[305] Fix | Delete
components.collect do |component|
[306] Fix | Delete
"%02d" % component
[307] Fix | Delete
end.join(':')
[308] Fix | Delete
end
[309] Fix | Delete
end
[310] Fix | Delete
[311] Fix | Delete
private
[312] Fix | Delete
def seconds_to_components(total_seconds)
[313] Fix | Delete
hours = total_seconds / (60 * 60)
[314] Fix | Delete
minutes = (total_seconds / 60) % 60
[315] Fix | Delete
seconds = total_seconds % 60
[316] Fix | Delete
[hours, minutes, seconds]
[317] Fix | Delete
end
[318] Fix | Delete
end
[319] Fix | Delete
[320] Fix | Delete
content_setup
[321] Fix | Delete
alias_method(:value, :content)
[322] Fix | Delete
remove_method(:content=)
[323] Fix | Delete
[324] Fix | Delete
attr_reader :hour, :minute, :second
[325] Fix | Delete
def initialize(*args)
[326] Fix | Delete
if Utils.element_initialize_arguments?(args)
[327] Fix | Delete
super
[328] Fix | Delete
else
[329] Fix | Delete
super()
[330] Fix | Delete
args = args[0] if args.size == 1 and args[0].is_a?(Array)
[331] Fix | Delete
if args.size == 1
[332] Fix | Delete
self.content = args[0]
[333] Fix | Delete
elsif args.size > 3
[334] Fix | Delete
raise ArgumentError,
[335] Fix | Delete
"must be (do_validate, params), (content), " +
[336] Fix | Delete
"(minute, second), ([minute, second]), " +
[337] Fix | Delete
"(hour, minute, second) or ([hour, minute, second]): " +
[338] Fix | Delete
args.inspect
[339] Fix | Delete
else
[340] Fix | Delete
@second, @minute, @hour = args.reverse
[341] Fix | Delete
update_content
[342] Fix | Delete
end
[343] Fix | Delete
end
[344] Fix | Delete
end
[345] Fix | Delete
[346] Fix | Delete
def content=(value)
[347] Fix | Delete
if value.nil?
[348] Fix | Delete
@content = nil
[349] Fix | Delete
elsif value.is_a?(self.class)
[350] Fix | Delete
self.content = value.content
[351] Fix | Delete
else
[352] Fix | Delete
begin
[353] Fix | Delete
@hour, @minute, @second = self.class.parse(value, @do_validate)
[354] Fix | Delete
rescue ArgumentError
[355] Fix | Delete
raise NotAvailableValueError.new(tag_name, value)
[356] Fix | Delete
end
[357] Fix | Delete
@content = value
[358] Fix | Delete
end
[359] Fix | Delete
end
[360] Fix | Delete
alias_method(:value=, :content=)
[361] Fix | Delete
[362] Fix | Delete
def hour=(hour)
[363] Fix | Delete
@hour = @do_validate ? Integer(hour) : hour.to_i
[364] Fix | Delete
update_content
[365] Fix | Delete
hour
[366] Fix | Delete
end
[367] Fix | Delete
[368] Fix | Delete
def minute=(minute)
[369] Fix | Delete
@minute = @do_validate ? Integer(minute) : minute.to_i
[370] Fix | Delete
update_content
[371] Fix | Delete
minute
[372] Fix | Delete
end
[373] Fix | Delete
[374] Fix | Delete
def second=(second)
[375] Fix | Delete
@second = @do_validate ? Integer(second) : second.to_i
[376] Fix | Delete
update_content
[377] Fix | Delete
second
[378] Fix | Delete
end
[379] Fix | Delete
[380] Fix | Delete
def full_name
[381] Fix | Delete
tag_name_with_prefix(ITUNES_PREFIX)
[382] Fix | Delete
end
[383] Fix | Delete
[384] Fix | Delete
private
[385] Fix | Delete
def update_content
[386] Fix | Delete
@content = self.class.construct(hour, minute, second)
[387] Fix | Delete
end
[388] Fix | Delete
[389] Fix | Delete
def maker_target(target)
[390] Fix | Delete
if @content
[391] Fix | Delete
target.itunes_duration {|duration| duration}
[392] Fix | Delete
else
[393] Fix | Delete
nil
[394] Fix | Delete
end
[395] Fix | Delete
end
[396] Fix | Delete
[397] Fix | Delete
def setup_maker_element(duration)
[398] Fix | Delete
super(duration)
[399] Fix | Delete
duration.content = @content
[400] Fix | Delete
end
[401] Fix | Delete
end
[402] Fix | Delete
end
[403] Fix | Delete
[404] Fix | Delete
class Rss
[405] Fix | Delete
class Channel
[406] Fix | Delete
include ITunesChannelModel
[407] Fix | Delete
class Item; include ITunesItemModel; end
[408] Fix | Delete
end
[409] Fix | Delete
end
[410] Fix | Delete
[411] Fix | Delete
element_infos =
[412] Fix | Delete
ITunesChannelModel::ELEMENT_INFOS + ITunesItemModel::ELEMENT_INFOS
[413] Fix | Delete
element_infos.each do |name, type|
[414] Fix | Delete
case type
[415] Fix | Delete
when :element, :elements, :attribute
[416] Fix | Delete
class_name = Utils.to_class_name(name)
[417] Fix | Delete
BaseListener.install_class_name(ITUNES_URI, name, "ITunes#{class_name}")
[418] Fix | Delete
else
[419] Fix | Delete
accessor_base = "#{ITUNES_PREFIX}_#{name.gsub(/-/, '_')}"
[420] Fix | Delete
BaseListener.install_get_text_element(ITUNES_URI, name, accessor_base)
[421] Fix | Delete
end
[422] Fix | Delete
end
[423] Fix | Delete
end
[424] Fix | Delete
[425] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function