Skip to content

Commit 6c1be9d

Browse files
N3X15ZomgPonies
authored andcommitted
HOLY FUCK PLAYLISTS AND SHIT
1 parent 0e8c675 commit 6c1be9d

File tree

76 files changed

+133
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+133
-51
lines changed

Diff for: web/htdocs/media/config.php.dist

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
// Change this.
4+
define('BASE_URL', 'http://yoursite.tld/media');
5+
6+
// What file extensions do you want to look for?
7+
// Files must be tagged and cannot have spaces in the name.
8+
$validExtensions = array('mp3', 'ogg');
9+
10+
// Names of your playlists, without the .PHP at the end.
11+
// See playlists/example.php for an example.
12+
// Must correspond with your jukebox's playlists list.
13+
$playlists = array(
14+
'bar', // Bar-specific shit.
15+
'jazz',
16+
'rock',
17+
);

Diff for: web/htdocs/media/files/index.htm

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Your music files go here. This file is here to prevent people from just leeching everything.

Diff for: web/htdocs/media/index.php

+97-51
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,107 @@
11
<?php
2-
//header('Content-type: text/plain');
2+
require_once ('config.php');
33

4-
define('BASE_URL', 'http://ss13.nexisonline.net/media');
4+
define('MEDIA_ROOT', dirname(__FILE__));
5+
define('FILE_DIR', MEDIA_ROOT . '/files');
6+
define('LIB_DIR', MEDIA_ROOT . '/lib');
7+
define('PLAYLIST_DIR', MEDIA_ROOT . '/playlists');
58

6-
// include getID3() library (can be in a different directory if full path is specified)
7-
require_once('getid3/getid3.php');
9+
require_once (LIB_DIR . '/getid3/getid3.php');
810

9-
// Initialize getID3 engine
11+
// Don't fuck with this shit.
1012
$getID3 = new getID3;
1113

12-
$validExtensions = array('mp3', 'ogg');
14+
if (!isset($_GET['playlist']))
15+
die(json_encode($playlists));
16+
$playlist = $_GET['playlist'];
17+
if (!in_array($playlist, $playlists))
18+
die('No');
19+
20+
function loadFilesIn($subdir) {
21+
$pl = array();
22+
$striplen=strlen(FILE_DIR)+1;
23+
foreach (new RecursiveIteratorIterator (new RecursiveDirectoryIterator (FILE_DIR.'/'.$subdir)) as $name => $file)
24+
{
25+
$relfile = substr($file->getPathname(),$striplen);// . '/' . $file;
26+
if(substr($relfile,-1)=='.') continue;
27+
$pl[$relfile] = array();
28+
}
29+
return $pl;
30+
}
31+
32+
require (PLAYLIST_DIR . '/' . $playlist . '.php');
33+
34+
if (!file_exists('cache/'))
35+
mkdir('cache/');
36+
1337
$json = array();
14-
foreach (glob('*.*') as $file) {
15-
list(, $ext) = explode('.', $file);
16-
if(!in_array($ext, $validExtensions))
17-
continue;
18-
$data = $getID3->analyze($file);
19-
getid3_lib::CopyTagsToComments($data);
38+
foreach ($playlist as $file => $data) {
39+
list(, $ext) = explode('.', $file);
40+
41+
if (!in_array($ext, $validExtensions))
42+
continue;
2043

21-
if(file_exists($file.'.cache.php'))
22-
require($file.'.cache.php');
23-
else{
24-
$row = array(
25-
'title' => '???',
26-
'artist' => 'Unknown',
27-
'album' => '',
28-
29-
'url' => BASE_URL.'/'.urlencode($file),
30-
'length' => ''.(int)($data['playtime_seconds']*10)
31-
);
32-
if(array_key_exists('artist',$data['comments_html']) || array_key_exists('album',$data['comments_html'])){
33-
$row['title']=$data['comments_html']['title'][0];
34-
if(isset($data['comments']['artist']))
35-
$row['artist']=$data['comments']['artist'][0];
36-
if(isset($data['comments']['album']))
37-
$row['album'] = $data['comments']['album'][0];
38-
} else {
39-
$matches=array();
40-
// Search for something of the form "artist - title (album).ext"
41-
if (preg_match('/([^\\-]+)\\-([^\\(\\.]+)(\\(([^\\)])\\))?\\.([a-z0-9]{3})/', $file, $matches) !== FALSE)
42-
{
43-
if(count($matches)>=2){
44-
$row['artist'] = trim($matches[1]);
45-
$row['title'] = trim($matches[2]);
46-
$row['album'] = trim($matches[3]);
47-
}
48-
}
49-
}
50-
}
44+
$json[]=analyzeFile($file, $data);
45+
}
46+
47+
function analyzeFile($file,$playlist_data) {
48+
global $validExtensions, $getID3;
49+
$fileURL = BASE_URL . '/files/' . $file;
50+
$file = FILE_DIR . '/' . $file;
5151

52-
$json[]=$row;
53-
/*
54-
echo '<pre>';
55-
#echo json_encode($row);
56-
echo htmlentities(print_r($data['comments'], true));
57-
echo '</pre>';
58-
*/
59-
52+
// use cache, if available
53+
$cachefile = 'cache/' . md5($file) . '.cache.php';
54+
if (file_exists($cachefile)) {
55+
require ($cachefile);
56+
$row = array_merge($row, $playlist_data);
57+
return $row;
58+
}
59+
60+
// Get ID3 tags and whatnot
61+
$data = $getID3->analyze($file);
62+
getid3_lib::CopyTagsToComments($data);
63+
64+
// We need a playtime. Abort if not found.
65+
if (!isset($data['playtime_seconds'])) {
66+
echo "<h2>{$file}</h2>";
67+
var_dump($data);
68+
return;
69+
}
70+
71+
//@formatter:off
72+
$row = array(
73+
'title' => '???',
74+
'artist' => 'Unknown',
75+
'album' => '',
76+
77+
'url' => $fileURL,
78+
'length' => '' . (int)($data['playtime_seconds'] * 10)
79+
);
80+
//@formatter:on
81+
82+
if (isset($data['comments_html']) && (array_key_exists('artist', $data['comments_html']) || array_key_exists('album', $data['comments_html']))) {
83+
$row['title'] = $data['comments_html']['title'][0];
84+
if (isset($data['comments']['artist']))
85+
$row['artist'] = $data['comments']['artist'][0];
86+
if (isset($data['comments']['album']))
87+
$row['album'] = $data['comments']['album'][0];
88+
} else {
89+
$matches = array();
90+
// Search for something of the form "artist - title (album).ext"
91+
if (preg_match('/([^\\-]+)\\-([^\\(\\.]+)(\\(([^\\)])\\))?\\.([a-z0-9]{3})/', $file, $matches) !== FALSE) {
92+
if (count($matches) >= 2) {
93+
$row['artist'] = trim($matches[1]);
94+
$row['title'] = trim($matches[2]);
95+
$row['album'] = trim($matches[3]);
96+
}
97+
}
98+
}
99+
100+
file_put_contents($cachefile, '<?php $row=' . var_export($row, true).';');
101+
102+
$row = array_merge($row, $playlist_data);
103+
return $row;
60104
}
61-
echo json_encode($json);
105+
header('Content-type: text/plain');
106+
#echo json_encode($json);
107+
echo json_encode($json,JSON_PRETTY_PRINT);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: web/htdocs/media/playlists/example.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
// Simple playlist:
3+
// Files MUST be under files/.
4+
$playlist=array(
5+
'file1.mp3'=>array(),
6+
'subfolder/file2.mp3'=>array(
7+
'title'=>'Just a Friend',
8+
'artist'=>'Biz Markie'
9+
)
10+
);
11+
12+
// Dynamic Playlist
13+
// Loads files from files/subfolder.
14+
$playlist=loadFilesIn('subfolder');
15+
16+
17+
// Adjust playlist entry's tags.
18+
$playlist['file1.mp3']=array('artist'=>'Kingston','title'=>'SS13 sucks','album'=>'Fuck You');

0 commit comments

Comments
 (0)