Skip to content

Improve automatic torrent-naming #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Http/Controllers/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ public function upload()
// Find the right category
$category = Category::findOrFail(Request::get('category_id'));
// Create the torrent (DB)
$name = Request::get('name');
$torrent = new Torrent([
'name' => str_replace(".", " ", Request::get('name')),
'slug' => str_slug(str_replace(".", " ", Request::get('name'))),
'name' => $name,
'slug' => str_slug($name),
'description' => Request::get('description'),
'mediainfo' => Request::get('mediainfo'),
'info_hash' => $info['info_hash'],
Expand Down
24 changes: 23 additions & 1 deletion resources/views/torrent/upload.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@
@stop

@section('content')
<script>
function updateTorrentName() {
let name = document.querySelector("#name");
let torrent = document.querySelector("#torrent");
let fileEndings = [".mkv.torrent", ".torrent"];
let allowed = ["1.0", "2.0", "5.1", "7.1"];
if (name !== null && torrent !== null) {
let value = torrent.value.split('\\').pop().split('/').pop();
fileEndings.forEach(function(e) {
if (value.endsWith(e)) {
value = value.substr(0, value.length - e.length);
}
});
value = value.replace(/\./g, " ");
allowed.forEach(function(a) {
search = a.replace(/\./g, " ");
value = value.replace(search, a);
})
name.value = value;
}
}
</script>
@if($user->can_upload == 0)
<div class="container">
<div class="jumbotron shadowed">
Expand Down Expand Up @@ -56,7 +78,7 @@
{{ Form::open(['route' => 'upload', 'files' => true, 'class' => 'upload-form']) }}
<div class="form-group">
<label for="torrent">Torrent File</label>
<input class="upload-form-file" type="file" name="torrent" id="torrent" onchange="document.getElementById('name').value = this.value.split('\\').pop().split('/').pop()">
<input class="upload-form-file" type="file" name="torrent" id="torrent" onchange="updateTorrentName()">
</div>

<div class="form-group">
Expand Down