-
Notifications
You must be signed in to change notification settings - Fork 159
/
episodes_ftp_feature.php
175 lines (165 loc) · 6.89 KB
/
episodes_ftp_feature.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
############################################################
# PODCAST GENERATOR
#
# Created by Alberto Betella and Emil Engler
# http://www.podcastgenerator.net
#
# This is Free Software released under the GNU/GPL License.
############################################################
require 'checkLogin.php';
require '../core/include_admin.php';
// Fetch ID3 tags. Try ID3V2, then ID3V1, before falling back
// to the specific default value.
function getID3Tag($fileinfo, $tagName, $defaultValue = null)
{
return ($fileinfo['tags']['id3v2'][$tagName][0] != null
? $fileinfo['tags']['id3v2'][$tagName][0]
: ($fileinfo['tags']['id3v1'][$tagName][0] != null
? $fileinfo['tags']['id3v1'][$tagName][0]
: $defaultValue));
}
if (isset($_GET['start'])) {
$new_files = array();
$mimetypes = simplexml_load_file($config['absoluteurl'] . 'components/supported_media/supported_media.xml');
// Get all files and check if they have an XML file associated
if ($handle = opendir('../' . $config['upload_dir'])) {
while (false !== ($entry = readdir($handle))) {
// Skip dotfiles
if (substr($entry, 0, 1) == '.') {
continue;
}
// Skip XML files
if (pathinfo('../' . $config['upload_dir'] . $entry, PATHINFO_EXTENSION) == 'xml') {
continue;
}
// Check if an XML file for that episode exists
if (file_exists('../' . $config['upload_dir'] . pathinfo('../' . $config['upload_dir'] . $entry, PATHINFO_FILENAME) . '.xml')) {
continue;
}
// Get mime type
$mimetype = getmime('../' . $config['upload_dir'] . $entry);
// Continue if file isn't readable
if (!$mimetype)
continue;
// Skip invalid mime types
$validExtension = false;
foreach ($mimetypes->mediaFile as $item) {
if ($mimetype == $item->mimetype) {
$validExtension = true;
break;
}
}
if (!$validExtension) {
continue;
}
array_push($new_files, $entry);
}
}
require_once '../components/getid3/getid3.php';
// Generate XML from audio file (with mostly empty values)
$num_added = 0;
for ($i = 0; $i < sizeof($new_files); $i++) {
// Skip files if they are not strictly named
if ($config['strictfilenamepolicy'] == 'yes') {
if (!preg_match('/^[\w.]+$/', $new_files[$i])) {
continue;
}
}
// Get audio metadata (duration, bitrate etc)
$getID3 = new getID3;
$fileinfo = $getID3->analyze('../' . $config['upload_dir'] . $new_files[$i]);
$duration = $fileinfo['playtime_string']; // Get duration
$bitrate = $fileinfo['audio']['bitrate']; // Get bitrate
$frequency = $fileinfo['audio']['sample_rate']; // Frequency
$title = getID3Tag($fileinfo, 'title', pathinfo('../' . $config['upload_dir'] . $new_files[$i], PATHINFO_FILENAME));
$comment = getID3Tag($fileinfo, 'comment', '');
$author_name = getID3Tag($fileinfo, 'artist', $config['author']);
$episodefeed = '<?xml version="1.0" encoding="utf-8"?>
<PodcastGenerator>
<episode>
<titlePG><![CDATA[' . htmlspecialchars($title, ENT_NOQUOTES) . ']]></titlePG>
<shortdescPG><![CDATA[' . htmlspecialchars($comment) . ']]></shortdescPG>
<longdescPG><![CDATA[' . htmlspecialchars($comment) . ']]></longdescPG>
<imgPG></imgPG>
<categoriesPG>
<category1PG>uncategorized</category1PG>
<category2PG></category2PG>
<category3PG></category3PG>
</categoriesPG>
<keywordsPG><![CDATA[]]></keywordsPG>
<explicitPG>' . htmlspecialchars($config['explicit_podcast']) . '</explicitPG>
<authorPG>
<namePG>' . htmlspecialchars($author_name) . '</namePG>
<emailPG>' . htmlspecialchars($config['author_email']) . '</emailPG>
</authorPG>
<fileInfoPG>
<size>' . intval(filesize('../' . $config['upload_dir'] . $new_files[$i]) / 1000 / 1000) . '</size>
<duration>' . $duration . '</duration>
<bitrate>' . substr(strval($bitrate), 0, 3) . '</bitrate>
<frequency>' . $frequency . '</frequency>
</fileInfoPG>
</episode>
</PodcastGenerator>';
// Select new filenames (with date) if not already exsits
preg_match('/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/', $new_files[$i], $output_array);
$fname = $new_files[$i];
if (sizeof($output_array) == 0) {
$new_filename = '../' . $config['upload_dir'] . date('Y-m-d') . '-' . $new_files[$i];
$new_filename = str_replace(' ', '_', $new_filename);
$appendix = 1;
while (file_exists($new_filename)) {
$new_filename = '../' . $config['upload_dir'] . date('Y-m-d') . '-' . $appendix . '-' . basename($new_files[$i]);
$new_filename = str_replace(' ', '_', $new_filename);
$appendix++;
}
rename('../' . $config['upload_dir'] . $new_files[$i], $new_filename);
$fname = $new_filename;
}
// Write image if set
if (isset($fileinfo['comments']['picture'])) {
$imgext = ($fileinfo['comments']['picture'][0]['image_mime'] == 'image/png') ? 'png' : 'jpg';
$img_filename = $config['absoluteurl'] . $config['img_dir'] . pathinfo($fname, PATHINFO_FILENAME) . '.' . $imgext;
file_put_contents($img_filename, $fileinfo['comments']['picture'][0]['data']);
}
// Write XML file
file_put_contents('../' . $config['upload_dir'] . pathinfo($fname, PATHINFO_FILENAME) . '.xml', $episodefeed);
$num_added++;
}
if ($num_added) {
// Regenerate RSS feed
generateRSS();
$success = sprintf(_('Added %d new episode(s)'), $num_added);
} else {
$success = _('No new episodes were found');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo htmlspecialchars($config['podcast_title']); ?> - <?php echo _('FTP Feature'); ?></title>
<meta charset="utf-8">
<link rel="stylesheet" href="../core/bootstrap/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="<?php echo $config['url']; ?>favicon.ico">
</head>
<body>
<?php
include 'js.php';
include 'navbar.php';
?>
<br>
<div class="container">
<h1><?php echo _('FTP Auto Indexing'); ?></h1>
<?php
if (!isset($_GET['start'])) {
echo '<a href="episodes_ftp_feature.php?start=1" class="btn btn-success">' . _('Begin') . '<a>';
}
if (isset($success)) {
echo '<p>' . htmlspecialchars($success) . '</p>';
}
?>
</div>
</body>
</html>