Commit d5a59aed authored by Citronalco's avatar Citronalco
Browse files

first commit

This diff is collapsed.
# MP3 to Atom Feed
Creates a RSS Atom feed for all MP3 files in a given directory, suitable for the usual podcast players.
### Synopsis ###
./ <mp3 files directory> <feed title> <mp3 files url>
### Example ###
Your MP3 files are in directory "/data/mp3files/" and accessible via https below "".
The following would create a valid RSS Atom feed with the title "My Podcast":
```./ "/data/mp3files/" "My Podcast" ""```
The script saves the feed file as "podcast.xml" in the MP3 files' directory.
"podcast.xml" contains all MP3 files from "/data/mp3files" sorted from the newest files to the oldest.
Titles and descriptions get read from the MP3 files (ID3 tags title and comment).
\ No newline at end of file
use strict;
use warnings;
use File::Find::Rule;
use MP3::Info;
use MP3::Tag;
use URI::file;
use POSIX;
use XML::Writer;
use utf8;
use Unicode::String qw(utf8 latin1);
if (@ARGV ne 3) {
print "USAGE:\n";
print $0." <directory with MP3 files> <feed title> <url to directory with MP3 files>\n\n";
print "Example:\n";
print $0.' /data/public/yoga-sessions-2017/ "My Yoga Podcast 2017"'."\n";
print 'This would create a file "/data/public/yoga-sessions-2017/podcast.xml", which should also be available via to get things going.'."\n";
my $DIR=$ARGV[0];
my $LINK=$URLBASE."/podcast.xml";
my $NOW=POSIX::strftime("%a, %d %b %Y %T %z",localtime);
open my $RSS, '>', $DIR."/podcast.xml" or die($!);
my $xml=XML::Writer->new(OUTPUT=>$RSS,DATA_MODE=>1,DATA_INDENT=>1);
$xml->emptyTag('atom:link', 'href'=>$LINK, 'rel'=>'self', 'type'=>'application/rss+xml');
my @files;
foreach (File::Find::Rule->file()->name('*.mp3')->in($DIR)) {
my %fileinfo;
$fileinfo{'mtime'}=(stat($fileinfo{'name'}))[10] or die($!);
$fileinfo{'mdatetime'}=POSIX::strftime("%a, %d %b %Y %T %z",localtime((stat($fileinfo{'name'}))[10]));
$fileinfo{'size'}=(stat($fileinfo{'name'}))[7] or die($!);
my $mp3=MP3::Tag->new($fileinfo{'name'}) or die($!);
foreach my $file (reverse(sort { $a->{'mtime'} cmp $b->{'mtime'} } @files )) {
$xml->emptyTag('enclosure','url'=>$file->{'url'}, 'type'=>'audio/mpeg', 'length'=>$file->{'size'});
close $RSS;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment