aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2015-05-08 00:59:51 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2015-05-08 00:59:51 (GMT)
commit4c3586d5a1b0d6b4c306865f8586200282510090 (patch)
tree8a1afdcc02d2d0d68254b808a2a9bde67a9a69a3
parent05f3ea94f54f90a7ac081927dda8f8ed1c83977f (diff)
downloadslipshine-rss-4c3586d5a1b0d6b4c306865f8586200282510090.zip
slipshine-rss-4c3586d5a1b0d6b4c306865f8586200282510090.tar.gz
Simplified everything and split single items with multiple links into their own items.
-rw-r--r--rss-fix_no-xml-rss.pl54
1 files changed, 22 insertions, 32 deletions
diff --git a/rss-fix_no-xml-rss.pl b/rss-fix_no-xml-rss.pl
index 0285812..2a73522 100644
--- a/rss-fix_no-xml-rss.pl
+++ b/rss-fix_no-xml-rss.pl
@@ -15,35 +15,29 @@ $header_sections{'docs'} = '';
15$header_sections{'generator'} = 'Not Slipshine. That shit\'s borked.'; 15$header_sections{'generator'} = 'Not Slipshine. That shit\'s borked.';
16 16
17my @items = $borked_rss =~ /<item>(.*?)<\/item>/smg; 17my @items = $borked_rss =~ /<item>(.*?)<\/item>/smg;
18 18my @ul_links;
19my @new_items;
20 19
21foreach my $item (@items) { 20foreach my $item (@items) {
22 my %sections = $item =~ /<([^>]+)>(.*?)<\/\1>/smg; 21 my %sections = $item =~ /<([^>]+)>(.*?)<\/\1>/smg;
23 22
24 $sections{'description'} =~ s/^\s+//sg; 23 $sections{'description'} =~ m/<ul>(.*?)<\/ul>/smg;
25 $sections{'description'} =~ s/\s+/ /sg; 24 my @list_items = split /<li>/, $1;
26 $sections{'description'} =~ s/<!\[CDATA\[//sg; 25 foreach my $l (@list_items) {
27 $sections{'description'} =~ s/\s*\]\]>//sg; 26 if ($l) {
28 27 $l =~ m#<a href="(.*?)">(.*?)</a>#;
29 $sections{'description'} =~ /href="([^"]+)"/; 28 my $ul_link = $1;
30 my $real_link = $1; 29 my $ul_title = $2;
31 30
32 $sections{'description'} =~ s/<br> /\n/g; 31 my %link_data;
33 $sections{'description'} =~ s/<[^>]+>//g; 32 $link_data{'link'} = $ul_link;
34 $sections{'description'} =~ s/\n/ - /sg; 33 $link_data{'title'} = $ul_title;
35 $sections{'description'} =~ s/\s+$//sg; 34 $link_data{'pubDate'} = $sections{'pubDate'};
36 35
37 $sections{'description'} =~ /^(.+) by (.+) - (.+)$/; 36 push @ul_links, \%link_data;
38 my $real_title = $1. ' - '. $3; 37 }
39 38 }
40 ## Re-assignment
41 $sections{'link'} = $real_link;
42 $sections{'title'} = $real_title;
43 $sections{'guid'} = md5_hex($real_title.$real_link);
44 $sections{'description'} .= "<br /><a href=\"$real_link\">$real_link</a>";
45 push(@new_items, \%sections);
46} 39}
40
47print "Content-type: text/xml\n\n"; 41print "Content-type: text/xml\n\n";
48 42
49print qq(<?xml version="1.0" encoding="iso-8859-1" ?>\n<rss version="2.0">\n); 43print qq(<?xml version="1.0" encoding="iso-8859-1" ?>\n<rss version="2.0">\n);
@@ -53,17 +47,13 @@ print "<channel>\n\t<title>$header_sections{title}</title>\n",
53 "\t<generator>$header_sections{generator}</generator>\n", 47 "\t<generator>$header_sections{generator}</generator>\n",
54 "\t<link>$header_sections{link}</link>\n"; 48 "\t<link>$header_sections{link}</link>\n";
55 49
56foreach my $n_item (@new_items) { 50foreach my $nlink (@ul_links) {
57 print "\t<item>\n"; 51 print "\t<item>\n";
58 foreach my $section (sort keys %{$n_item}) { 52 print "\t\t<title>$nlink->{title}</title>\n";
59 if( $section eq 'description' ) { 53 print "\t\t<guid>$nlink->{link}</guid>\n";
60 print "\t\t<description><![CDATA[$n_item->{description}]]></description>\n"; 54 print "\t\t<link>$nlink->{link}</link>\n";
61 } elsif( $section eq 'guid' ) { 55 print "\t\t<pubDate>$nlink->{pubDate}</pubDate>\n";
62 print "\t\t<guid isPermaLink=\"false\">$n_item->{guid}</guid>\n"; 56 print "\t\t<description><![CDATA[<a href=\"$nlink->{link}\">$nlink->{title}</a>]]></description>\n";
63 } else {
64 print "\t\t<$section>$n_item->{$section}</$section>\n";
65 }
66 }
67 print "\t</item>\n"; 57 print "\t</item>\n";
68} 58}
69print "</channel>\n</rss>\n"; 59print "</channel>\n</rss>\n";