blib/lib/Kwiki/Podcast.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary Build »
1 package Kwiki::Podcast;
2 1 ▶use Kwiki::Plugin -Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use mixin 'Kwiki::Installer';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XML::RSS;
Subroutine BEGIN: called CC=1 SCAR=2.6
5 use URI;
6 our $VERSION = '0.02';
7  
8 const class_id => 'podcast';
9 const class_title => 'Podcast';
10 const config_file => 'podcast.yaml';
11  
12 sub register {
13 my $registry = shift;
14 $registry->add(action => 'podcast');
15 $registry->add(toolbar => 'podcast_button',
16 template => 'podcast_button.html',
17 );
18 }
19  
20 sub podcast {
21 my @pods;
22 for($self->hub->pages->all){
23 if($_->content =~ m/(https?:.+?\.mp3)/i) {
24 push @pods, { uri => $1 , page => $_ };
25 }
26 }
27 $self->hub->headers->content_type('text/xml');
28 return $self->mkrss($self->hub->config->podcast_title,
29 $self->hub->config->podcast_publisher,
30 $self->hub->config->podcast_description,
31 @pods);
32 }
33  
34 sub mkrss {
35 my ($title,$creator,$description,@pods) = @_;
36 my $rss = XML::RSS->new( version => '2.0', encoding=> 'utf-8' );
37  
38 $rss->channel(title => $title,
39 publisher => $creator,
40 description => $description );
41  
42 for (@pods) {
43 my $uri = URI->new($_->{uri});
44 my ($sec,$min,$hour,$mday,$mon,$year,,,) = localtime($_->{page}->io->ctime);
45 $rss->add_item( title => $_->{page}->title,
46 link => $uri,
47 enclosure => { url => $uri, type => 'audio/mpeg' },
48 description => '<![CDATA[' . $_->{page}->content . ']]>',
49 category => "Podcast",
50 pubDate => ($year+1900)."-$mon-$mday"."T"."$hour:$min:$sec",
51 author => $_->{page}->metadata->edit_by
52 );
53 }
54 return $rss->as_string;
55 }
56  
57 =head1 NAME
58  
59 Kwiki::Podcast - Podcasting in a Kwiki way
60  
61 =head1 INSTALLATION
62  
63 kwiki -install Kwiki::Podcast
64  
65 =head1 DESCRIPTION
66  
67 This plugin offer an Kwiki action to generate podcast rss. User
68 simply put down a mp3 URL in a page, and leave the rest to Kwiki.
69 For example, you only have to write something like:
70  
71 My Podcast Try. This is my first podcast song, please
72 take a look at it.
73  
74 http://foobar.org/podcast/first.mp3
75  
76 With proper user preference, your podcast will have proper publisher
77 tag too.
78  
79 Subscribe can address your podcast RSS URL from Kwiki's toolbar.
80  
81 =head1 CONFIGURATION
82  
83 The following 3 configuration keys are available:
84  
85 =over 4
86  
87 =item podcast_title
88  
89 General title for you Podcasting
90  
91 =item podcast_publisher
92  
93 Your name
94  
95 =item podcast_description
96  
97 General description for this podcast.
98  
99 =back
100  
101 =head1 AUTHOR
102  
103 Kang-min Liu <gugod@gugod.org>
104  
105 =head1 LICENSE
106  
107 This program is free software; you can redistribute it and/or modify
108 it under the same terms as Perl itself.
109  
110 See <http://www.perl.com/perl/misc/Artistic.html>
111  
112 =cut
113  
114 __DATA__
115 __config/podcast.yaml__
116 podcast_title: Kwiki Podcast
117 podcast_publisher: Kwiki Hacker
118 podcast_description: Podcast in a Kwiki way
119 __template/tt2/podcast_button.html__
120 <a href="[% script_name %]?action=podcast">
121 [% INCLUDE podcast_button_icon.html %]
122 </a>
123 __template/tt2/podcast_button_icon.html__
124 Podcast
↑ Summary Build »