SpotifyTools.php /split/split.php

Language PHP Lines 59
MD5 Hash 420accccb37f9a27a5583be4fb723ce1
Repository https://github.com/Allikin/SpotifyTools.php.git View Raw File
 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
<?php
if ((isset($_POST['submit'])) && ($_POST['tracks'] > '')) {
	$correct_format = true;
	$message = '';
	$split = 1000;
	$count = 0;
	$tracks = $_POST['tracks'];

	if (correctTracksFormat($tracks)) {
		$list = preg_split('/[\n\r]+/',$tracks);
		$list = array_filter($list,'strlen');
		$list = tracksGetSpotifyURIs($list); 		// returns an array of Spotif URIs: spotify:track:<URI>
	} else {
   		$correct_format = false;
		$messages[] = "<p style='font-size:12px;'>&nbsp;<br/>Please apply valid tracks by HTTP or Spotify URI.</p>";
	}
	
	if ($_POST['split'] > 0) {
		$split = $_POST['split'];
	}

	if ($correct_format) {
		if (isset($_POST['random'])) {
			shuffle($list); 						//randomize the list of tracks
		}
		
		// split list
		$number_of_tracks = count($list);
		foreach ($list as $uri) {
			$tracklist[$count] = $uri;
			$count++;
			if (($count == $split) || ($count == $number_of_tracks)){
				$number_of_tracks = $number_of_tracks - $count;
				$lists[] = $tracklist;
				unset($tracklist);
				$count = 0;
			}
		}
		
		echo "<h3>".count($list)." tracks split up into ".count($lists)." lists:</h3><br/>
				Select the tracks by clicking inside the textarea and use CTRL-C or right click to copy, or just drag them to an empty playlist.<br/>&nbsp;<br/></p>";
		foreach ($lists as $i => $newlist) {
			echo "List ".($i+1).": ".count($newlist)." tracks:
				<textarea name='randomlist' rows='10' cols='52' wrap='off' onClick='select(this)' wrap='off' readonly>";
			foreach ($newlist as $uri) {
				echo $uri."\r\n";
			}
			echo "</textarea><br/><br/>";
		}
	} else {
		foreach ($messages as $message) {
			echo $message;
		}
	}
	
}	
?>
Back to Top