-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.pl
executable file
·83 lines (63 loc) · 2.41 KB
/
filter.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
# This software is public domain. 2022
# Usage: cat some-rss-file.xml | filter.pl > clean-rss-file.xml
# Description: This script is meant to rewrite podcast enclosure urls in
# order to remove calls to trackers. The expected use-case is to use it
# as a filter for podcast feeds in liferea.
use strict;
use warnings;
while(<>) {
my $rss = $_;
my $matched = 0;
# Since trackers may be chained, we keep looping through all of the known
# trackers until no more matches are made.
do{
$matched = 0;
if($rss =~ /"https:\/\/pdcn\.co\/e\/https:\/\//) {
$rss =~ s/"https:\/\/pdcn\.co\/e\/https:\/\//"https:\/\//g;
$matched = 1;
}
if($rss =~ /"https:\/\/pdcn\.co\/e\//) {
$rss =~ s/"https:\/\/pdcn\.co\/e\//"https:\/\//g;
$matched = 1;
}
if($rss =~ /"https:\/\/www\.podtrac\.com\/pts\/redirect\.mp3\//) {
$rss =~ s/"https:\/\/www\.podtrac\.com\/pts\/redirect\.mp3\//"https:\/\//g;
$matched = 1;
}
if($rss =~ /"https:\/\/dts\.podtrac\.com\/redirect\.mp3\//) {
$rss =~ s/"https:\/\/dts\.podtrac\.com\/redirect.mp3\//"https:\/\//g;
$matched = 1;
}
if($rss =~ /"https:\/\/chrt\.fm\/track\/[0-9A-Z]+\//) {
$rss =~ s/"https:\/\/chrt\.fm\/track\/[0-9A-Z]+\//"https:\/\//g;
$matched = 1;
}
if($rss =~ /"https:\/\/chtbl\.com\/track\/[A-Z0-9]+\//) {
$rss =~ s/"https:\/\/chtbl\.com\/track\/[A-Z0-9]+\//"https:\/\//g;
$matched = 1;
}
if($rss =~ /"https:\/\/pdst\.fm\/e\//) {
$rss =~ s/"https:\/\/pdst\.fm\/e\//"https:\/\//g;
$matched = 1;
}
# This was an unusual case where the remainder of the url contained
# escaped characters. Liferea would not play the mp3 unless the
# escaped characters were converted back to unescaped characters.
if($rss =~ /"https:\/\/anchor\.fm\/s\/[a-z0-9]+\/podcast\/play\/[0-9]+\/https/) {
$rss =~ s/"https:\/\/anchor\.fm\/s\/[a-z0-9]+\/podcast\/play\/[0-9]+\/https/"https/g;
$rss =~ s/%3A/:/g;
$rss =~ s/%2F/\//g;
$matched = 1;
}
if($rss =~ /"https:\/\/anchor\.fm\/s\/[a-z0-9]+\/podcast\/play\/[0-9]+\//) {
$rss =~ s/"https:\/\/anchor\.fm\/s\/[a-z0-9]+\/podcast\/play\/[0-9]+\//"https:\/\//g;
$matched = 1;
}
if($rss =~ /"https:\/\/mgln\.ai\/track\//) {
$rss =~ s/"https:\/\/mgln\.ai\/track\//"https:\/\//g;
$matched = 1;
}
} while($matched);
print "$rss";
}