line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MP3::Podcast; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
MP3::Podcast - Perl extension for podcasting directories full of MP3 files |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use MP3::Podcast; |
10
|
|
|
|
|
|
|
my $dirbase = shift; |
11
|
|
|
|
|
|
|
my $urlbase = shift; |
12
|
|
|
|
|
|
|
my $dir = shift; |
13
|
|
|
|
|
|
|
my $pod = MP3::Podcast->new($dirbase,$urlbase); |
14
|
|
|
|
|
|
|
my $rss = $pod->podcast( $dir, "This is a test" ); |
15
|
|
|
|
|
|
|
print $rss->as_string; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 ABSTRACT |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Create podcast easily from directories, using MP3's own info. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Creates a podcast, basically a RSS feed for a directory full of MP3 files. |
24
|
|
|
|
|
|
|
Takes information from the MP3 files themselves; it needs MP3 files with |
25
|
|
|
|
|
|
|
their ID tags completed. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
The bundle includes two programs in the C dir: C, |
28
|
|
|
|
|
|
|
used this way: |
29
|
|
|
|
|
|
|
bash% ./gen-podcast.pl |
30
|
|
|
|
|
|
|
which generates a static RSS from a dir, and C, to use from a |
31
|
|
|
|
|
|
|
webserver. To use it, copy C and C to a cgi-serviceable |
32
|
|
|
|
|
|
|
dir; edit C to your liking and copy it to the directory you want. |
33
|
|
|
|
|
|
|
Copy also C<.podcast> to the directory you want served as a podcast |
34
|
|
|
|
|
|
|
(this is done mainly to avoid dir-creeping), |
35
|
|
|
|
|
|
|
edit the path to fetch the MP3::Podcast lib, and call it with |
36
|
|
|
|
|
|
|
C |
37
|
|
|
|
|
|
|
The name of the directory to scan will be taken from the URI |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This new version includes in the test directory MP3s by the Spanish |
40
|
|
|
|
|
|
|
group L, which are freely |
41
|
|
|
|
|
|
|
distributed under a CC license. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
25653
|
use 5.008; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
46
|
|
48
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
49
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
29
|
|
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
|
373
|
use XML::RSS; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
use URI; |
53
|
|
|
|
|
|
|
use MP3::Info; |
54
|
|
|
|
|
|
|
use POSIX qw(strftime); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
our $VERSION = '0.06_1aa'; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Preloaded methods go here. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item new |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Creates the object. Takes basic info as input: the address of the |
63
|
|
|
|
|
|
|
directory that will |
64
|
|
|
|
|
|
|
be scanned, the base URL that will be used to podcast this URL base. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub new { |
69
|
|
|
|
|
|
|
my $class = shift; |
70
|
|
|
|
|
|
|
my $dirbase = shift || die "Need a base dir\n"; |
71
|
|
|
|
|
|
|
my $urlbase = shift || die "Need a base URL\n"; |
72
|
|
|
|
|
|
|
my $self = { dirbase => $dirbase, |
73
|
|
|
|
|
|
|
urlbase => $urlbase }; |
74
|
|
|
|
|
|
|
bless $self, $class; |
75
|
|
|
|
|
|
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item podcast |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Creates the podcast for a dir, that is, an RSS file with enclosures |
81
|
|
|
|
|
|
|
containing the MP3s it can find in that dir. Information to fill RSS |
82
|
|
|
|
|
|
|
fields is contained in the ID3 fields of the MP3 files. |
83
|
|
|
|
|
|
|
Returns an XML::RSS object, which you can manipulate, if you feel |
84
|
|
|
|
|
|
|
like doing so. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub podcast { |
89
|
|
|
|
|
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
my $dir = shift || die "Can't find dir\n"; |
91
|
|
|
|
|
|
|
my $title = shift || die "Can't find podcast title\n"; |
92
|
|
|
|
|
|
|
my $creator = shift || "MP3::Podcast $VERSION"; |
93
|
|
|
|
|
|
|
my $description = shift || $title; |
94
|
|
|
|
|
|
|
my $sort = shift; |
95
|
|
|
|
|
|
|
my $rss = XML::RSS->new( version => '2.0', |
96
|
|
|
|
|
|
|
encoding=> 'UTF-8' ); |
97
|
|
|
|
|
|
|
my $urlbase = $self->{'urlbase'}; |
98
|
|
|
|
|
|
|
my $dirbase = $self->{'dirbase'}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$rss->channel(title => $title, |
101
|
|
|
|
|
|
|
link => "$urlbase/$dir", |
102
|
|
|
|
|
|
|
publisher => $creator, |
103
|
|
|
|
|
|
|
description => $description ); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $poddir="$dirbase/$dir"; |
106
|
|
|
|
|
|
|
my $podurl="$urlbase/$dir"; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#Read directory |
109
|
|
|
|
|
|
|
opendir(D, "$poddir") || die "Couldn't open directory $poddir: $!\n"; |
110
|
|
|
|
|
|
|
my @files = readdir(D); |
111
|
|
|
|
|
|
|
closedir(D) || die "Couldn't close dir $poddir\n"; |
112
|
|
|
|
|
|
|
if ( $sort ) { |
113
|
|
|
|
|
|
|
@files = reverse(sort(@files)); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
foreach my $file ( @files ) { |
116
|
|
|
|
|
|
|
next if $file !~ /\.[Mm][Pp]3$/i; |
117
|
|
|
|
|
|
|
my $filePath="$poddir/$file"; |
118
|
|
|
|
|
|
|
my @stat = stat($filePath); |
119
|
|
|
|
|
|
|
my $pubdate = strftime("%a, %e %b %Y %T %z", localtime($stat[9])); |
120
|
|
|
|
|
|
|
my $tag = get_mp3tag($filePath) or die "No TAG info for $filePath"; |
121
|
|
|
|
|
|
|
my ($mp3title) = ( $file =~ /^(.+?)\.mp3/i ); |
122
|
|
|
|
|
|
|
my $uri = URI->new("$podurl/$file"); |
123
|
|
|
|
|
|
|
$rss->add_item( title => $tag->{'TITLE'} || $mp3title, |
124
|
|
|
|
|
|
|
link => $uri, |
125
|
|
|
|
|
|
|
enclosure => { url => $uri, |
126
|
|
|
|
|
|
|
length => $stat[7], |
127
|
|
|
|
|
|
|
type => 'audio/mpeg' }, |
128
|
|
|
|
|
|
|
pubDate => $pubdate, |
129
|
|
|
|
|
|
|
description => "Podcast $tag->{COMMENT}" ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
return $rss; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
'All\'s well that ends well'; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SEE ALSO |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Info on podcasting: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 4 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item Podcast in perl: http://escripting.com/podcast/ |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item Podcastamatic: http://bradley.chicago.il.us/projects/podcastamatic/readme.html |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item Examples in the C dir. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Juan Julian Merelo Guervos, Ejmerelo {at} geneura.ugr.esE. Thanks |
155
|
|
|
|
|
|
|
to Juan Schwindt Ejuan {at} schwindt.orgE, Matt Domsch |
156
|
|
|
|
|
|
|
Ematt {at} domsch.comE, Gavin Hurlbut Egjhurlbu {at} |
157
|
|
|
|
|
|
|
gmail.comE and Eric Johnson Eeric {at} el-studio.com E |
158
|
|
|
|
|
|
|
for patches, suggestion and encouragement. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Copyright 2005-2009 by Juan Julian Merelo Guervos |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This library is free software; you can redistribute it and or modify |
165
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |