Gazelle/sections/better/snatch.php

245 lines
8.2 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
2012-11-06 08:00:20 +00:00
if (!empty($_GET['userid']) && is_number($_GET['userid'])) {
2011-03-28 14:21:28 +00:00
if (check_perms('users_override_paranoia')) {
$UserID = $_GET['userid'];
} else {
error(403);
}
} else {
$UserID = $LoggedUser['ID'];
}
2012-11-06 08:00:20 +00:00
$Encodings = array('V0 (VBR)', 'V2 (VBR)', '320');
$EncodingKeys = array_fill_keys($Encodings, true);
2013-07-17 08:00:52 +00:00
if (!empty($_GET['filter']) && $_GET['filter'] === 'seeding') {
$SeedingOnly = true;
} else {
$SeedingOnly = false;
}
2011-03-28 14:21:28 +00:00
// Get list of FLAC snatches
2013-06-18 08:00:48 +00:00
$DB->query("
SELECT t.GroupID, x.fid
FROM ".($SeedingOnly ? 'xbt_files_users' : 'xbt_snatched')." AS x
2013-07-10 00:08:53 +00:00
JOIN torrents AS t ON t.ID = x.fid
2013-02-18 08:00:22 +00:00
JOIN torrents_group AS tg ON tg.ID = t.GroupID
2013-07-10 00:08:53 +00:00
WHERE t.Format = 'FLAC'
AND ((t.LogScore = '100' AND t.Media = 'CD')
2013-02-17 08:00:08 +00:00
OR t.Media != 'CD')
2013-02-18 08:00:22 +00:00
AND tg.CategoryID = 1
2013-07-10 00:08:53 +00:00
AND x.uid = '$UserID'" .
2013-06-18 08:00:48 +00:00
($SeedingOnly ? ' AND x.active = 1 AND x.remaining = 0' : ''));
2011-03-28 14:21:28 +00:00
2012-11-06 08:00:20 +00:00
$SnatchedTorrentIDs = array_fill_keys($DB->collect('fid'), true);
$SnatchedGroupIDs = array_unique($DB->collect('GroupID'));
if (count($SnatchedGroupIDs) > 1000) {
shuffle($SnatchedGroupIDs);
$SnatchedGroupIDs = array_slice($SnatchedGroupIDs, 0, 1000);
}
2011-03-28 14:21:28 +00:00
2013-07-17 08:00:52 +00:00
if (count($SnatchedGroupIDs) === 0) {
2013-02-17 08:00:08 +00:00
error(($SeedingOnly ? "You aren't seeding any perfect FLACs!" : "You haven't snatched any perfect FLACs!"));
2012-11-06 08:00:20 +00:00
}
2011-03-28 14:21:28 +00:00
// Create hash table
2013-06-18 08:00:48 +00:00
$DB->query("
CREATE TEMPORARY TABLE temp_sections_better_snatch
SELECT
t.GroupID,
GROUP_CONCAT(t.Encoding SEPARATOR ' ') AS EncodingList,
CRC32(CONCAT_WS(
' ', Media, Remasteryear, Remastertitle,
Remasterrecordlabel, Remastercataloguenumber)
) AS RemIdent
2011-03-28 14:21:28 +00:00
FROM torrents AS t
2013-06-18 08:00:48 +00:00
WHERE t.GroupID IN(".implode(',', $SnatchedGroupIDs).")
AND t.Format IN ('FLAC', 'MP3')
2012-11-06 08:00:20 +00:00
GROUP BY t.GroupID, RemIdent");
2011-03-28 14:21:28 +00:00
2013-07-10 00:08:53 +00:00
/*$DB->query('
SELECT *
FROM t');
*/
2013-06-18 08:00:48 +00:00
$DB->query("
SELECT GroupID
FROM temp_sections_better_snatch
WHERE EncodingList NOT LIKE '%V0 (VBR)%'
2013-02-13 08:00:35 +00:00
OR EncodingList NOT LIKE '%V2 (VBR)%'
2011-03-28 14:21:28 +00:00
OR EncodingList NOT LIKE '%320%'");
2012-11-06 08:00:20 +00:00
$GroupIDs = array_fill_keys($DB->collect('GroupID'), true);
2011-03-28 14:21:28 +00:00
2013-07-17 08:00:52 +00:00
if (count($GroupIDs) === 0) {
2012-11-06 08:00:20 +00:00
error('No results found');
}
$Groups = Torrents::get_groups(array_keys($GroupIDs));
$Groups = $Groups['matches'];
2011-03-28 14:21:28 +00:00
2012-11-06 08:00:20 +00:00
$TorrentGroups = array();
foreach ($Groups as $GroupID => $Group) {
if (empty($Group['Torrents'])) {
unset($Groups[$GroupID]);
continue;
}
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(),
2012-12-06 08:00:17 +00:00
'IsSnatched' => $Torrent['IsSnatched'],
2012-11-06 08:00:20 +00:00
'Medium' => $Torrent['Media'],
'RemasterTitle' => $Torrent['RemasterTitle'],
'RemasterYear' => $Torrent['RemasterYear'],
'RemasterRecordLabel' => $Torrent['RemasterRecordLabel'],
'RemasterCatalogueNumber' => $Torrent['RemasterCatalogueNumber']
)
);
} elseif (!isset($TorrentGroups[$Group['ID']][$TorRemIdent])) {
$TorrentGroups[$Group['ID']][$TorRemIdent] = array(
'FlacID' => 0,
'Formats' => array(),
2012-12-06 08:00:17 +00:00
'IsSnatched' => $Torrent['IsSnatched'],
2012-11-06 08:00:20 +00:00
'Medium' => $Torrent['Media'],
'RemasterTitle' => $Torrent['RemasterTitle'],
'RemasterYear' => $Torrent['RemasterYear'],
'RemasterRecordLabel' => $Torrent['RemasterRecordLabel'],
'RemasterCatalogueNumber' => $Torrent['RemasterCatalogueNumber']
);
}
2013-02-18 08:00:22 +00:00
if ($Torrent['Format'] == 'MP3' && isset($EncodingKeys[$Torrent['Encoding']])) {
2012-11-06 08:00:20 +00:00
$TorrentGroups[$Group['ID']][$TorRemIdent]['Formats'][$Torrent['Encoding']] = true;
} elseif (isset($SnatchedTorrentIDs[$Torrent['ID']])) {
$TorrentGroups[$Group['ID']][$TorRemIdent]['FlacID'] = $Torrent['ID'];
}
}
}
2013-02-18 08:00:22 +00:00
$Counter = array(
'total' => 0, //how many FLAC torrents can be transcoded?
'miss_total' => 0, //how many transcodes are missing?
'miss_V0 (VBR)' => 0, //how many V0 transcodes are missing?
'miss_V2 (VBR)' => 0, //how many V2 transcodes are missing?
'miss_320' => 0, //how many 320 transcodes are missing?
);
2013-05-05 08:00:31 +00:00
foreach ($TorrentGroups as $Editions) {
foreach ($Editions as $Edition) {
if ($Edition['FlacID'] == 0) { // no FLAC in this edition
continue;
}
2013-02-17 08:00:08 +00:00
$edition_miss = 0; //number of transcodes missing in this edition
2013-05-05 08:00:31 +00:00
foreach ($Encodings as $Encoding) {
if (!isset($Edition['Formats'][$Encoding])) {
2013-02-17 08:00:08 +00:00
++$edition_miss;
2013-07-10 00:08:53 +00:00
++$Counter["miss_$Encoding"];
2013-02-17 08:00:08 +00:00
}
}
$Counter['miss_total'] += $edition_miss;
$Counter['total'] += (bool)$edition_miss;
}
}
2011-03-28 14:21:28 +00:00
2012-10-11 08:00:15 +00:00
View::show_header('Transcode Snatches');
2011-03-28 14:21:28 +00:00
?>
<div class="linkbox">
2013-02-23 08:00:22 +00:00
<a href="better.php" class="brackets">Back to better.php list</a>
2012-11-06 08:00:20 +00:00
<? if ($SeedingOnly) { ?>
2013-02-13 08:00:35 +00:00
<a href="better.php?method=snatch" class="brackets">Show all</a>
<? } else { ?>
2013-02-23 08:00:22 +00:00
<a href="better.php?method=snatch&amp;filter=seeding" class="brackets">Show only those currently seeding</a>
<? } ?>
</div>
2011-03-28 14:21:28 +00:00
<div class="thin">
2013-02-17 08:00:08 +00:00
<h2>Transcode <?=($SeedingOnly ? 'seeding' : 'snatched')?> torrents</h2>
<h3>Stats</h3>
<div class="box pad">
<p>
2013-02-23 08:00:22 +00:00
Number of perfect FLACs you can transcode: <?=number_format($Counter['total'])?><br />
Number of missing transcodes: <?=number_format($Counter['miss_total'])?><br />
Number of missing V2 / V0 / 320 transcodes: <?=number_format($Counter['miss_V2 (VBR)'])?> / <?=number_format($Counter['miss_V0 (VBR)'])?> / <?=number_format($Counter['miss_320'])?>
2013-02-17 08:00:08 +00:00
</p>
</div>
<h3>List</h3>
2012-09-01 08:00:24 +00:00
<table width="100%" class="torrent_table">
2011-03-28 14:21:28 +00:00
<tr class="colhead">
<td>Torrent</td>
<td>V2</td>
<td>V0</td>
<td>320</td>
</tr>
<?
2012-11-06 08:00:20 +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);
} else {
$ArtistNames = '';
2011-03-28 14:21:28 +00:00
}
2013-02-26 08:00:42 +00:00
$TorrentTags = new Tags($GroupInfo['TagList']);
2012-11-06 08:00:20 +00:00
foreach ($Editions as $RemIdent => $Edition) {
2013-07-17 08:00:52 +00:00
if (!$Edition['FlacID'] || count($Edition['Formats']) === 3) {
2012-11-06 08:00:20 +00:00
continue;
2012-02-05 08:00:20 +00:00
}
2013-08-28 23:08:41 +00:00
$DisplayName = $ArtistNames . '<a href="torrents.php?id='.$GroupID.'&amp;torrentid='.$Edition['FlacID'].'#torrent'.$Edition['FlacID'].'" title="View Torrent" dir="ltr">'.$GroupName.'</a>';
2013-05-05 08:00:31 +00:00
if ($GroupYear > 0) {
$DisplayName .= " [$GroupYear]";
2012-11-06 08:00:20 +00:00
}
if ($ReleaseType > 0) {
2013-07-10 00:08:53 +00:00
$DisplayName .= ' ['.$ReleaseTypes[$ReleaseType].']';
2012-11-06 08:00:20 +00:00
}
$DisplayName .= ' ['.$Edition['Medium'].']';
$EditionInfo = array();
if (!empty($Edition['RemasterYear'])) {
$ExtraInfo = $Edition['RemasterYear'];
} else {
$ExtraInfo = '';
}
if (!empty($Edition['RemasterRecordLabel'])) {
$EditionInfo[] = $Edition['RemasterRecordLabel'];
}
if (!empty($Edition['RemasterTitle'])) {
$EditionInfo[] = $Edition['RemasterTitle'];
}
if (!empty($Edition['RemasterCatalogueNumber'])) {
$EditionInfo[] = $Edition['RemasterCatalogueNumber'];
}
if (!empty($Edition['RemasterYear'])) {
$ExtraInfo .= ' - ';
}
$ExtraInfo .= implode(' / ', $EditionInfo);
2011-03-28 14:21:28 +00:00
?>
2012-12-06 08:00:17 +00:00
<tr class="torrent torrent_row<?=$Edition['IsSnatched'] ? ' snatched_torrent' : ''?>">
2011-03-28 14:21:28 +00:00
<td>
2012-11-06 08:00:20 +00:00
<span class="torrent_links_block">
2013-02-13 08:00:35 +00:00
<a href="torrents.php?action=download&amp;id=<?=$Edition['FlacID']?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>" title="Download" class="brackets">DL</a>
2012-11-06 08:00:20 +00:00
</span>
<?=$DisplayName?>
<div class="torrent_info"><?=$ExtraInfo?></div>
2013-02-25 21:16:55 +00:00
<div class="tags"><?=$TorrentTags->format()?></div>
2011-03-28 14:21:28 +00:00
</td>
2013-06-18 08:00:48 +00:00
<td><?=isset($Edition['Formats']['V2 (VBR)']) ? '<strong class="important_text_alt">YES</strong>' : '<strong class="important_text">NO</strong>'?></td>
<td><?=isset($Edition['Formats']['V0 (VBR)']) ? '<strong class="important_text_alt">YES</strong>' : '<strong class="important_text">NO</strong>'?></td>
<td><?=isset($Edition['Formats']['320']) ? '<strong class="important_text_alt">YES</strong>' : '<strong class="important_text">NO</strong>'?></td>
2011-03-28 14:21:28 +00:00
</tr>
2012-11-06 08:00:20 +00:00
<?
}
}
?>
2011-03-28 14:21:28 +00:00
</table>
</div>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();
2011-03-28 14:21:28 +00:00
?>