(Add) Torrent Tags System

- used for genres
This commit is contained in:
HDVinnie
2018-12-30 13:35:46 -05:00
parent 1da55fbc2c
commit 93d721f2d9
14 changed files with 613 additions and 9 deletions
+77
View File
@@ -0,0 +1,77 @@
<?php
/**
* NOTICE OF LICENSE
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author HDVinnie
*/
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Torrent;
use App\TagTorrent;
class FetchGenres extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fetch:genres';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fetch Genres For Torrents In DB';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$client = new \App\Services\MovieScrapper(config('api-keys.tmdb'), config('api-keys.tvdb'), config('api-keys.omdb'));
$torrents = Torrent::withAnyStatus()->select(['id', 'category_id', 'imdb', 'tmdb'])
->whereBetween('id', [21640, 21869])
->get();
foreach ($torrents as $torrent) {
if ($torrent->category_id == 2) {
if ($torrent->tmdb && $torrent->tmdb != 0) {
$movie = $client->scrape('tv', null, $torrent->tmdb);
} else {
$movie = $client->scrape('tv', 'tt' . $torrent->imdb);
}
} else {
if ($torrent->tmdb && $torrent->tmdb != 0) {
$movie = $client->scrape('movie', null, $torrent->tmdb);
} else {
$movie = $client->scrape('movie', 'tt' . $torrent->imdb);
}
}
if ($movie->genres) {
foreach ($movie->genres as $genre) {
$tag = new TagTorrent();
$tag->torrent_id = $torrent->id;
$tag->tag_name = $genre;
$tag->save();
}
}
// sleep for 2 seconds
sleep(2);
}
}
}
+1
View File
@@ -55,6 +55,7 @@ class Kernel extends ConsoleKernel
\App\Console\Commands\ClearCache::class,
\App\Console\Commands\SetCache::class,
\App\Console\Commands\TestMailSettings::class,
\App\Console\Commands\FetchGenres::class
];
/**
@@ -0,0 +1,113 @@
<?php
/**
* NOTICE OF LICENSE
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author HDVinnie
*/
namespace App\Http\Controllers\Staff;
use App\Tag;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use \Toastr;
class TagController extends Controller
{
/**
* Get All Tags
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$tags = Tag::all()->sortBy('name');
return view('Staff.tag.index', ['tags' => $tags]);
}
/**
* Tag Add Form
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function addForm()
{
return view('Staff.tag.add');
}
/**
* Add A Tag
*
* @param \Illuminate\Http\Request $request
* @return Illuminate\Http\RedirectResponse
*/
public function add(Request $request)
{
$tag = new Tag();
$tag->name = $request->input('name');
$tag->slug = str_slug($tag->name);
$v = validator($tag->toArray(), [
'name' => 'required|unique:tags',
'slug' => 'required',
]);
if ($v->fails()) {
return redirect()->back()
->with(Toastr::error($v->errors()->toJson(), 'Whoops!', ['options']));
} else {
$tag->save();
return redirect()->route('staff_tag_index')
->with(Toastr::success('Tag Successfully Added', 'Yay!', ['options']));
}
}
/**
* Tag Edit Form
*
* @param $slug
* @param $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function editForm($slug, $id)
{
$tag = Tag::findOrFail($id);
return view('Staff.tag.edit', ['tag' => $tag]);
}
/**
* Edit A Tag
*
* @param \Illuminate\Http\Request $request
* @param $slug
* @param $id
* @return Illuminate\Http\RedirectResponse
*/
public function edit(Request $request, $slug, $id)
{
$tag = Tag::findOrFail($id);
$tag->name = $request->input('name');
$tag->slug = str_slug($tag->name);
$v = validator($type->toArray(), [
'name' => 'required',
'slug' => 'required',
]);
if ($v->fails()) {
return redirect()->back()
->with(Toastr::error($v->errors()->toJson(), 'Whoops!', ['options']));
} else {
$tag->save();
return redirect()->route('staff_tag_index')
->with(Toastr::success('Tag Successfully Modified', 'Yay!', ['options']));
}
}
}
@@ -21,6 +21,7 @@ use App\Torrent;
use App\Warning;
use App\Category;
use Carbon\Carbon;
use App\TagTorrent;
use App\TorrentFile;
use App\FreeleechToken;
use App\PrivateMessage;
@@ -194,6 +195,7 @@ class TorrentController extends Controller
$mal = $request->input('mal');
$categories = $request->input('categories');
$types = $request->input('types');
$genres = $request->input('genres');
$freeleech = $request->input('freeleech');
$doubleupload = $request->input('doubleupload');
$featured = $request->input('featured');
@@ -269,6 +271,11 @@ class TorrentController extends Controller
$torrent->whereIn('type', $types);
}
if ($request->has('genres') && $request->input('genres') != null) {
$genreID = TagTorrent::select('torrent_id')->whereIn('tag_name', $genres)->get();
$torrent->whereIn('id', $genreID);
}
if ($request->has('freeleech') && $request->input('freeleech') != null) {
$torrent->where('free', '=', $freeleech);
}
@@ -681,6 +688,7 @@ class TorrentController extends Controller
public function upload(Request $request)
{
$user = auth()->user();
$client = new \App\Services\MovieScrapper(config('api-keys.tmdb'), config('api-keys.tvdb'), config('api-keys.omdb'));
$requestFile = $request->file('torrent');
if ($request->hasFile('torrent') == false) {
@@ -814,6 +822,29 @@ class TorrentController extends Controller
\LogActivity::addToLog("Member {$user->username} has uploaded torrent, ID: {$torrent->id} NAME: {$torrent->name} . \nThis torrent is pending approval from satff.");
}
if ($torrent->category_id == 2) {
if ($torrent->tmdb && $torrent->tmdb != 0) {
$movie = $client->scrape('tv', null, $torrent->tmdb);
} else {
$movie = $client->scrape('tv', 'tt' . $torrent->imdb);
}
} else {
if ($torrent->tmdb && $torrent->tmdb != 0) {
$movie = $client->scrape('movie', null, $torrent->tmdb);
} else {
$movie = $client->scrape('movie', 'tt' . $torrent->imdb);
}
}
if ($movie->genres) {
foreach ($movie->genres as $genre) {
$tag = new TagTorrent();
$tag->torrent_id = $torrent->id;
$tag->tag_name = $genre;
$tag->save();
}
}
return redirect()->route('download_check', ['slug' => $torrent->slug, 'id' => $torrent->id])
->with($this->toastr->success('Your torrent file is ready to be downloaded and seeded!', 'Yay!', ['options']));
}
+12 -1
View File
@@ -13,6 +13,7 @@
namespace App\Repositories;
use App\Tag;
use App\Type;
use App\Category;
@@ -39,7 +40,17 @@ class TorrentFacetedRepository
}
/**
* Options for sort the search result.
* Return a collection of Tag Name from storage
*
* @return \Illuminate\Support\Collection
*/
public function tags()
{
return Tag::all()->sortBy('name')->pluck('name', 'id');
}
/**
* Options for sort the search result
*
* @return array
*/
+42
View File
@@ -0,0 +1,42 @@
<?php
/**
* NOTICE OF LICENSE
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author HDVinnie
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
class TagTorrent extends Model
{
/**
* The Database Table Used By The Model
*
* @var string
*/
protected $table = 'tag_torrent';
/**
* Indicates If The Model Should Be Timestamped
*
* @var bool
*/
public $timestamps = false;
/**
* Has Many Tags
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function genre()
{
return $this->belongsTo(Tag::class, "tag_name", "name");
}
}
@@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UpdateTagTorrentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::dropIfExists('tag_torrent');
Schema::create('tag_torrent', function (Blueprint $table) {
$table->increments('id');
$table->integer('torrent_id')->unsigned()->index();
$table->string('tag_name')->index();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
+160
View File
@@ -0,0 +1,160 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D
*
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
* @author HDVinnie
*/
use Illuminate\Database\Seeder;
class TagsTableSeeder extends Seeder
{
/**
* Auto generated seed file.
*
* @return void
*/
public function run()
{
\DB::table('tags')->delete();
\DB::table('tags')->insert([
0 => [
"id" => 1,
"name" => "Action",
"slug" => "action",
],
1 => [
"id" => 2,
"name" => "Adventure",
"slug" => "adventure",
],
2 => [
"id" => 3,
"name" => "Animation",
"slug" => "animation",
],
3 => [
"id" => 4,
"name" => "Biography",
"slug" => "biography",
],
4 => [
"id" => 5,
"name" => "Comedy",
"slug" => "comedy",
],
5 => [
"id" => 6,
"name" => "Crime",
"slug" => "crime",
],
6 => [
"id" => 7,
"name" => "Documentary",
"slug" => "documentary",
],
7 => [
"id" => 8,
"name" => "Drama",
"slug" => "drama",
],
8 => [
"id" => 9,
"name" => "Family",
"slug" => "family",
],
9 => [
"id" => 10,
"name" => "Fantasy",
"slug" => "fantasy",
],
10 => [
"id" => 11,
"name" => "History",
"slug" => "history",
],
11 => [
"id" => 12,
"name" => "Horror",
"slug" => "horror",
],
12 => [
"id" => 13,
"name" => "Music",
"slug" => "music",
],
13 => [
"id" => 14,
"name" => "Musical",
"slug" => "musical",
],
14 => [
"id" => 15,
"name" => "Mystery",
"slug" => "mystery",
],
15 => [
"id" => 16,
"name" => "Romance",
"slug" => "romance",
],
16 => [
"id" => 17,
"name" => "Science Fiction",
"slug" => "science-fiction",
],
16 => [
"id" => 18,
"name" => "Sport",
"slug" => "sport",
],
17 => [
"id" => 19,
"name" => "Thriller",
"slug" => "thriller",
],
18 => [
"id" => 20,
"name" => "War",
"slug" => "war",
],
19 => [
"id" => 21,
"name" => "Western",
"slug" => "western",
],
20 => [
"id" => 22,
"name" => "Game-Show",
"slug" => "game-show",
],
21 => [
"id" => 23,
"name" => "News",
"slug" => "news",
],
22 => [
"id" => 24,
"name" => "Reality-TV",
"slug" => "reality-tv",
],
23 => [
"id" => 25,
"name" => "Sitcom",
"slug" => "sitcom",
],
24 => [
"id" => 26,
"name" => "Talk-Show",
"slug" => "talk-show",
],
]);
}
}
+35
View File
@@ -0,0 +1,35 @@
@extends('layout.default')
@section('breadcrumb')
<li>
<a href="{{ route('staff_dashboard') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Staff Dashboard</span>
</a>
</li>
<li>
<a href="{{ route('staff_tag_index') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Torrent Tags</span>
</a>
</li>
<li class="active">
<a href="{{ route('staff_tag_add_form') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Add Torrent Tag</span>
</a>
</li>
@endsection
@section('content')
<div class="container box">
<h2>Add A Torrent Tag (Genre)</h2>
<form role="form" method="POST" action="{{ route('staff_tag_add') }}">
@csrf
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name">
</div>
<button type="submit" class="btn btn-default">{{ trans('common.add') }}</button>
</form>
</div>
@endsection
+36
View File
@@ -0,0 +1,36 @@
@extends('layout.default')
@section('breadcrumb')
<li>
<a href="{{ route('staff_dashboard') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Staff Dashboard</span>
</a>
</li>
<li>
<a href="{{ route('staff_tag_index') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Torrent Types</span>
</a>
</li>
<li class="active">
<a href="{{ route('staff_tag_edit_form', ['slug' => $tag->slug, 'id' => $tag->id]) }}" itemprop="url"
class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Edit Torrent Tag</span>
</a>
</li>
@endsection
@section('content')
<div class="container box">
<h2>Edit A Torrent Tag (Genre)</h2>
<form role="form" method="POST" action="{{ route('staff_type_edit', ['slug' => $tag->slug, 'id' => $tag->id]) }}">
@csrf
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" value="{{ $tag->name }}">
</div>
<button type="submit" class="btn btn-default">{{ trans('common.submit') }}</button>
</form>
</div>
@endsection
+45
View File
@@ -0,0 +1,45 @@
@extends('layout.default')
@section('breadcrumb')
<li>
<a href="{{ route('staff_dashboard') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Staff Dashboard</span>
</a>
</li>
<li class="active">
<a href="{{ route('staff_tag_index') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Torrent Tags</span>
</a>
</li>
@endsection
@section('content')
<div class="container box">
<h2>Tags (Genres)</h2>
<a href="{{ route('staff_tag_add') }}" class="btn btn-primary">Add A Torrent Tag</a>
<div class="table-responsive">
<table class="table table-condensed table-striped table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($tags as $tag)
<tr>
<td>
<a href="{{ route('staff_tag_edit_form', ['slug' => $tag->slug, 'id' => $tag->id]) }}">{{ $tag->name }}</a>
</td>
<td>
<a href="{{ route('staff_tag_edit_form', ['slug' => $tag->slug, 'id' => $tag->id]) }}"
class="btn btn-warning">Edit</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endsection
@@ -91,6 +91,11 @@
<i class="{{ config('other.font-awesome') }} fa-columns"></i> @lang('staff.torrent-types')
</a>
</li>
<li>
<a href="{{ route('staff_tag_index') }}">
<i class="{{ config('other.font-awesome') }} fa-columns"></i> Torrent Tags (Genres)
</a>
</li>
<li>
<a href="{{ route('getCatalog') }}">
<i class="{{ config('other.font-awesome') }} fa-book"></i> @lang('staff.catalog-groups')
+2 -2
View File
@@ -291,7 +291,7 @@
</span>
@endif
{{--@php $torrent_tags = App\TagTorrent::where('torrent_id', '=', $torrent->id)->get(); @endphp
@php $torrent_tags = App\TagTorrent::where('torrent_id', $torrent->id)->get(); @endphp
@if ($torrent_tags)
@foreach($torrent_tags as $torrent_tag)
<span class="badge-extra text-bold">
@@ -299,7 +299,7 @@
data-original-title='Genre'></i> {{ $torrent_tag->genre->name }}
</span>
@endforeach
@endif--}}
@endif
</td>
<td>
+20 -6
View File
@@ -18,9 +18,6 @@
@section('content')
<div class="container box">
<div class="text-center">
<h3 class="filter-title">Search Filters</h3>
</div>
<form role="form" method="GET" action="TorrentController@torrents" class="form-horizontal form-condensed form-torrent-search form-bordered">
@csrf
<div class="form-group">
@@ -86,6 +83,19 @@
</div>
</div>
<div class="form-group">
<label for="genre" class="col-sm-1 label label-default">Genre</label>
<div class="col-sm-10">
@foreach ($repository->tags() as $id => $genre)
<span class="badge-user">
<label class="inline">
<input type="checkbox" id="{{ $genre }}" value="{{ $genre}}" class="genre"> {{ $genre }}
</label>
</span>
@endforeach
</div>
</div>
<div class="form-group">
<label for="type" class="col-sm-1 label label-default">@lang('torrent.discounts')</label>
<div class="col-sm-10">
@@ -184,7 +194,7 @@
</div>
</div>
</div>
</div>
<div class="container-fluid">
@@ -270,6 +280,7 @@
var mal = $("#mal").val();
var categories = [];
var types = [];
var genres = [];
var sorting = $("#sorting").val();
var direction = $("#direction").val();
var qty = $("#qty").val();
@@ -329,7 +340,9 @@
$(".type:checked").each(function () {
types.push($(this).val());
});
$(".genre:checked").each(function () {
genres.push($(this).val());
});
if (xhr !== 'undefined') {
xhr.abort();
@@ -348,6 +361,7 @@
mal: mal,
categories: categories,
types: types,
genres: genres,
freeleech: freeleech,
doubleupload: doubleupload,
featured: featured,
@@ -412,7 +426,7 @@
})
</script>
<script>
$(".category,.type").on("click", function () {
$(".category,.type,.genre").on("click", function () {
faceted();
});
</script>