Gazelle/sections/ajax/better/transcode.php

132 lines
4.4 KiB
PHP
Raw Normal View History

2012-01-19 08:00:18 +00:00
<?
2013-05-05 08:00:31 +00:00
if (!isset($_GET['type']) || !is_number($_GET['type']) || $_GET['type'] > 3) {
2012-11-07 08:00:18 +00:00
error(0);
}
2012-01-19 08:00:18 +00:00
2013-07-17 08:00:52 +00:00
$Options = array('v0', 'v2', '320');
2012-11-07 08:00:18 +00:00
$Encodings = array('V0 (VBR)', 'V2 (VBR)', '320');
$EncodingKeys = array_fill_keys($Encodings, true);
2012-01-19 08:00:18 +00:00
2013-07-17 08:00:52 +00:00
if ($_GET['type'] === '3') {
2012-01-19 08:00:18 +00:00
$List = "!(v0 | v2 | 320)";
} else {
$List = '!'.$Options[$_GET['type']];
2013-07-17 08:00:52 +00:00
if ($_GET['type'] !== '0') {
2012-01-19 08:00:18 +00:00
$_GET['type'] = display_str($_GET['type']);
}
}
2013-09-13 08:00:53 +00:00
$SphQL = new SphinxqlQuery();
2012-11-07 08:00:18 +00:00
$SphQL->select('id, groupid')
->from('better_transcode')
->where('logscore', 100)
->where_match('FLAC', 'format')
->where_match($List, 'encoding', false)
->order_by('RAND()')
->limit(0, TORRENTS_PER_PAGE, TORRENTS_PER_PAGE);
2013-05-05 08:00:31 +00:00
if (!empty($_GET['search'])) {
2012-11-07 08:00:18 +00:00
$SphQL->where_match($_GET['search'], '(groupname,artistname,year,taglist)');
2012-01-19 08:00:18 +00:00
}
2012-11-07 08:00:18 +00:00
$SphQLResult = $SphQL->query();
$TorrentCount = $SphQLResult->get_meta('total');
2012-01-19 08:00:18 +00:00
2012-11-07 08:00:18 +00:00
if ($TorrentCount == 0) {
error('No results found!');
}
2012-01-19 08:00:18 +00:00
2012-11-07 08:00:18 +00:00
$Results = $SphQLResult->to_array('groupid');
$Groups = Torrents::get_groups(array_keys($Results));
2012-01-19 08:00:18 +00:00
2012-11-07 08:00:18 +00:00
$TorrentGroups = array();
foreach ($Groups as $GroupID => $Group) {
if (empty($Group['Torrents'])) {
unset($Groups[$GroupID]);
continue;
2012-01-19 08:00:18 +00:00
}
2012-11-07 08:00:18 +00:00
foreach ($Group['Torrents'] as $Torrent) {
$TorRemIdent = "$Torrent[Media] $Torrent[RemasterYear] $Torrent[RemasterTitle] $Torrent[RemasterRecordLabel] $Torrent[RemasterCatalogueNumber]";
if (!isset($TorrentGroups[$Group['ID']])) {
$TorrentGroups[$Group['ID']] = array(
$TorRemIdent => array(
'FlacID' => 0,
'Formats' => array(),
'RemasterTitle' => $Torrent['RemasterTitle'],
'RemasterYear' => $Torrent['RemasterYear'],
'RemasterRecordLabel' => $Torrent['RemasterRecordLabel'],
'RemasterCatalogueNumber' => $Torrent['RemasterCatalogueNumber'],
'IsSnatched' => false
)
);
} elseif (!isset($TorrentGroups[$Group['ID']][$TorRemIdent])) {
$TorrentGroups[$Group['ID']][$TorRemIdent] = array(
'FlacID' => 0,
'Formats' => array(),
'RemasterTitle' => $Torrent['RemasterTitle'],
'RemasterYear' => $Torrent['RemasterYear'],
'RemasterRecordLabel' => $Torrent['RemasterRecordLabel'],
'RemasterCatalogueNumber' => $Torrent['RemasterCatalogueNumber'],
'IsSnatched' => false
);
}
if (isset($EncodingKeys[$Torrent['Encoding']])) {
$TorrentGroups[$Group['ID']][$TorRemIdent]['Formats'][$Torrent['Encoding']] = true;
} elseif ($TorrentGroups[$Group['ID']][$TorRemIdent]['FlacID'] == 0 && $Torrent['Format'] == 'FLAC' && $Torrent['LogScore'] == 100) {
$TorrentGroups[$Group['ID']][$TorRemIdent]['FlacID'] = $Torrent['ID'];
$TorrentGroups[$Group['ID']][$TorRemIdent]['IsSnatched'] = $Torrent['IsSnatched'];
2012-01-19 08:00:18 +00:00
}
}
}
$JsonResults = array();
2012-11-07 08:00:18 +00:00
foreach ($TorrentGroups as $GroupID => $Editions) {
$GroupInfo = $Groups[$GroupID];
$GroupYear = $GroupInfo['Year'];
$ExtendedArtists = $GroupInfo['ExtendedArtists'];
$GroupCatalogueNumber = $GroupInfo['CatalogueNumber'];
$GroupName = $GroupInfo['Name'];
$GroupRecordLabel = $GroupInfo['RecordLabel'];
$ReleaseType = $GroupInfo['ReleaseType'];
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
$ArtistNames = Artists::display_artists($ExtendedArtists, false, false, false);
} else {
$ArtistNames = '';
2012-01-19 08:00:18 +00:00
}
2012-11-07 08:00:18 +00:00
$TagList = array();
2013-07-17 08:00:52 +00:00
$TagList = explode(' ', str_replace('_', '.', $GroupInfo['TagList']));
2012-11-07 08:00:18 +00:00
$TorrentTags = array();
foreach ($TagList as $Tag) {
2013-07-17 08:00:52 +00:00
$TorrentTags[] = "<a href=\"torrents.php?taglist=$Tag\">$Tag</a>";
2012-01-19 08:00:18 +00:00
}
2012-11-07 08:00:18 +00:00
$TorrentTags = implode(', ', $TorrentTags);
foreach ($Editions as $RemIdent => $Edition) {
if (!$Edition['FlacID']
2013-07-17 08:00:52 +00:00
|| !empty($Edition['Formats']) && $_GET['type'] === '3'
2012-11-07 08:00:18 +00:00
|| $Edition['Formats'][$Encodings[$_GET['type']]] == true) {
continue;
}
2012-01-19 08:00:18 +00:00
2012-11-07 08:00:18 +00:00
$JsonResults[] = array(
'torrentId' => (int) $Edition['FlacID'],
'groupId' => (int) $GroupID,
'artist' => $ArtistNames,
'groupName' => $GroupName,
'groupYear' => (int) $GroupYear,
'missingV2' => !isset($Edition['Formats']['V2 (VBR)']),
'missingV0' => !isset($Edition['Formats']['V0 (VBR)']),
'missing320' => !isset($Encodings['Formats']['320']),
'downloadUrl' => 'torrents.php?action=download&id='.$Edition['FlacID'].'&authkey='.$LoggedUser['AuthKey'].'&torrent_pass='.$LoggedUser['torrent_pass']
);
}
2012-01-19 08:00:18 +00:00
}
print json_encode(
array(
'status' => 'success',
'response' => $JsonResults
)
);