Compare commits
2 Commits
master
...
overwite_o
Author | SHA1 | Date | |
---|---|---|---|
717e85ce09 | |||
|
14403676c7 |
147
podcasts/scripts/feed2lav-qgull.pl
Executable file
147
podcasts/scripts/feed2lav-qgull.pl
Executable file
@ -0,0 +1,147 @@
|
||||
#! /usr/bin/perl -CAS
|
||||
# Gérald Sédrati-Dinet
|
||||
# Frédéric Couchet
|
||||
# License : WTFPL
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
# Version 2, December 2004
|
||||
#
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
#
|
||||
# Everyone is permitted to copy and distribute verbatim or modified
|
||||
# copies of this license document, and changing it is allowed as long
|
||||
# as the name is changed.
|
||||
#
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
#
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
||||
use 5.014;
|
||||
use utf8;
|
||||
use open qw(:std :encoding(UTF-8));
|
||||
use LWP::Simple;
|
||||
use XML::RSS;
|
||||
use DateTime;
|
||||
use DateTime::Format::DateParse;
|
||||
use Net::SSL;
|
||||
|
||||
{
|
||||
# Overwrite output of enclosures to have attributes in fixed order
|
||||
no warnings qw(redefine);
|
||||
sub XML::RSS::Private::Output::Base::_out_single_item_enclosure {
|
||||
my ($self, $item, $enc) = @_;
|
||||
|
||||
return
|
||||
$self->_out(
|
||||
"<enclosure " .
|
||||
join(' ',
|
||||
map { "$_=\"" . $self->_encode($enc->{$_}) . '"' } sort keys(%$enc)
|
||||
) .
|
||||
" />\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# Configuration variables
|
||||
my $url = "https://www.april.org/taxonomy_all_items/term/1918/all";
|
||||
my $urlfeed = "https://www.april.org/taxonomy_all_items/term/1918/all/feed";
|
||||
my $filename = "/usr/share/drupal6/lav.xml";
|
||||
my $linkurl = "https://april.org/libre-a-vous";
|
||||
my $feedurl = "https://april.org/lav.xml";
|
||||
|
||||
# build RSS object
|
||||
my $rss = XML::RSS->new;
|
||||
|
||||
# Fetch Drupal feed
|
||||
my $ua = LWP::UserAgent->new;
|
||||
$ua->ssl_opts( verify_hostname => 0);
|
||||
my $req = HTTP::Request->new(GET => $urlfeed);
|
||||
my $res = $ua->request($req);
|
||||
|
||||
die "Couldn't get $urlfeed\n!" unless $res->is_success();
|
||||
|
||||
# Parse RSS
|
||||
open(my $fh, '>:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!";
|
||||
$rss->parse($res->content);
|
||||
|
||||
# Add description
|
||||
$rss->{channel}->{description} = "<p>Chaque mardi de 15 h 30 à 17 h 00, l'April, l'association de promotion et de défense du logiciel libre, propose une émission de radio d'explications et d'échanges concernant les dossiers politiques et juridiques que l'association traite et les actions qu'elle mène : <a href=\"https://april.org/libre-a-vous\">Libre à vous !</a>. Une partie de l'émission est également consacrée aux actualités et actions de type sensibilisation. L'émission est diffusée sur radio Cause Commune sur la bande FM en Île-de-France (93.1) et <a href=\"https://cause-commune.fm\">sur le site web de la radio</a>.</p><p>Donner à chacun et chacune, de manière simple et accessible les clefs pour comprendre les enjeux mais aussi proposer des moyens d'action, tel est l'objectif de l'émission.</p>";
|
||||
|
||||
# Add image
|
||||
$rss->image(title=>'Libre à vous !', url=>'https://april.org/files/libre-a-vous/banniere-libre-a-vous-flux-rss-1400x1400.png', link=>$linkurl);
|
||||
|
||||
$rss->{channel}->{link} = $linkurl;
|
||||
|
||||
# Parse items
|
||||
my @new_items;
|
||||
foreach my $item (@{$rss->{'items'}}) {
|
||||
# Add mp3 enclosure
|
||||
my $ogg_enclosure = $item->{enclosure};
|
||||
if ($ogg_enclosure and ($ogg_enclosure->{type} eq 'audio/ogg' or $ogg_enclosure->{type} eq 'application/ogg')) {
|
||||
my $mp3_enclosure;
|
||||
$mp3_enclosure->{type} = 'audio/mpeg';
|
||||
$mp3_enclosure->{length} = $ogg_enclosure->{length};
|
||||
($mp3_enclosure->{url} = $ogg_enclosure->{url}) =~ s/\.ogg$/.mp3/;
|
||||
$item->{enclosure} = [$ogg_enclosure, $mp3_enclosure];
|
||||
}
|
||||
|
||||
# Add items for each topic
|
||||
if ($item->{description} =~ /Podcasts des différents sujets abordés(?:<\/strong><\/p>|<\/h2>)?\s*<ul>(.+?)<\/ul>/s) {
|
||||
# Extract topics
|
||||
my $topics = $1;
|
||||
|
||||
# Add current item to items list so new item for each topic goes after this one
|
||||
push @new_items, $item;
|
||||
|
||||
my ($datediffusion) = ($item->{title} =~ /diffusée (.+) sur radio/);
|
||||
|
||||
# Parse each topic
|
||||
while ($topics =~ /<li><a href="([^"]+)">([^>]+)<\/a>/g) {
|
||||
# Extract ogg url for enclosures
|
||||
my ($ogg_url, $title) = ($1, $2);
|
||||
(my $mp3_url = $ogg_url) =~ s/\.ogg$/.mp3/;
|
||||
|
||||
# Extract date for description
|
||||
my $date = DateTime::Format::DateParse->parse_datetime($item->{pubDate})->set_locale('fr')->strftime("%A %d %B %Y");
|
||||
|
||||
# Build new item for this topic
|
||||
my %new_item = %$item;
|
||||
|
||||
$new_item{title} = $title;
|
||||
$new_item{description} = <<"__HTML__";
|
||||
<p><a href="https://april.org/libre-a-vous"><em>Libre à vous !</em></a>, l'émission pour comprendre et agir avec l'April, chaque mardi de 15h30 à 17h sur la radio <em>Cause commune</em> (93.1 FM en Île-de-France et sur <a href="https://causecommune.fm">Internet</a>.</p>
|
||||
|
||||
<p><em>Émission « Libre à vous ! »</em> diffusée $datediffusion, partie « $title »</p>
|
||||
|
||||
<p>Retrouvez les références citées dans ce podcast sur <a href="$item->{link}">la page dédiée à l'émission</a>.</p>
|
||||
__HTML__
|
||||
$new_item{category} = 'Podcast Libre à vous !';
|
||||
$new_item{enclosure} = [{length => 0, type => 'audio/ogg', url => $ogg_url}, {length => 0, type => 'audio/mpeg', url => $mp3_url}];
|
||||
$new_item{guid} = $item->{guid} . "- $title";
|
||||
|
||||
# Add new item in items list
|
||||
push @new_items, \%new_item;
|
||||
}
|
||||
} else {
|
||||
# Add current item to items list
|
||||
push @new_items, $item;
|
||||
}
|
||||
}
|
||||
|
||||
# Replace list of items
|
||||
$rss->{items} = \@new_items;
|
||||
|
||||
# Output RSS
|
||||
my $rsscontent = $rss->as_string;
|
||||
|
||||
# Add stuff for iTunes
|
||||
$rsscontent =~s#</description>#</description>\n<itunes:category text="Technology" />\n<itunes:author>April et Radio Cause Commune</itunes:author>\n<itunes:summary>Libre à vous ! L'émission de l'April, l'association de promotion et de défense du logiciel libre, sur radio Cause Commune. Prenez le contrôle de vos libertés informatiques, découvrez les enjeux et l’actualité du Libre.</itunes:summary>\n<itunes:owner>\n<itunes:name>April</itunes:name>\n<itunes:email>libre-a-vous\@april.org</itunes:email>\n</itunes:owner>\n<itunes:explicit>no</itunes:explicit>\n<itunes:image href="https://media.april.org/audio/radio-cause-commune/libre-a-vous/visuels/banniere-libre-a-vous-flux-rss-3000x3000.png"></itunes:image>#;
|
||||
|
||||
$rsscontent =~s#xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"#xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"\n xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"\n#;
|
||||
|
||||
#$rsscontent =~s#https://www.april.org/taxonomy_all_items/term/1918/all#$feedurl#g;
|
||||
$rsscontent =~s#${url}#$feedurl#g;
|
||||
|
||||
print $fh $rsscontent;
|
||||
|
||||
close $fh;
|
@ -24,6 +24,23 @@ use XML::RSS;
|
||||
use DateTime;
|
||||
use DateTime::Format::DateParse;
|
||||
|
||||
{
|
||||
# Overwrite output of enclosures to have attributes in fixed order
|
||||
no warnings qw(redefine);
|
||||
sub XML::RSS::Private::Output::Base::_out_single_item_enclosure {
|
||||
my ($self, $item, $enc) = @_;
|
||||
|
||||
return
|
||||
$self->_out(
|
||||
"<enclosure " .
|
||||
join(' ',
|
||||
map { "$_=\"" . $self->_encode($enc->{$_}) . '"' } sort keys(%$enc)
|
||||
) .
|
||||
" />\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# Configuration variables
|
||||
my $url = "https://www.april.org/taxonomy_all_items/term/1918/all";
|
||||
my $urlfeed = "https://www.april.org/taxonomy_all_items/term/1918/all/feed";
|
||||
|
Loading…
Reference in New Issue
Block a user