Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Memorekall Member New
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rekall
Memorekall Member New
Commits
0a4bdf73
Commit
0a4bdf73
authored
3 years ago
by
Camille Simiand
Browse files
Options
Downloads
Patches
Plain Diff
Use medium quality thumbnail if no maxres
parent
a8c697cd
No related branches found
No related tags found
1 merge request
!80
tuleap-194-some-youtube-video-thumbnail-are-not-retrieved
Pipeline
#974
passed
3 years ago
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Controller/CapsuleController.php
+5
-2
5 additions, 2 deletions
src/Controller/CapsuleController.php
src/Entity/Capsule.php
+11
-2
11 additions, 2 deletions
src/Entity/Capsule.php
templates/capsule/index.html.twig
+2
-2
2 additions, 2 deletions
templates/capsule/index.html.twig
with
18 additions
and
6 deletions
src/Controller/CapsuleController.php
+
5
−
2
View file @
0a4bdf73
...
...
@@ -21,6 +21,7 @@ use Symfony\Component\HttpFoundation\Request;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\Routing\Annotation\Route
;
use
Symfony\Component\Uid\Uuid
;
use
Symfony\Contracts\HttpClient\HttpClientInterface
;
use
Symfony\Contracts\Translation\TranslatorInterface
;
class
CapsuleController
extends
AbstractController
...
...
@@ -60,7 +61,8 @@ class CapsuleController extends AbstractController
#[Route('/{_locale<%app.supported_locales%>}', name:'home')]
public
function
index
(
PaginatorInterface
$paginator
,
Request
$request
Request
$request
,
HttpClientInterface
$http_client
):
Response
{
$current_user
=
$this
->
getUser
();
...
...
@@ -97,7 +99,8 @@ class CapsuleController extends AbstractController
'filterByGroupForm'
=>
$form
,
'capsules'
=>
$capsules
,
'current_user'
=>
$current_user
,
'legacy_url'
=>
$this
->
getParameter
(
'app.legacy_external_prefix'
)
'legacy_url'
=>
$this
->
getParameter
(
'app.legacy_external_prefix'
),
'http_client'
=>
$http_client
]);
}
...
...
This diff is collapsed.
Click to expand it.
src/Entity/Capsule.php
+
11
−
2
View file @
0a4bdf73
...
...
@@ -12,6 +12,7 @@ use Doctrine\ORM\Mapping\UniqueConstraint;
use
Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity
;
use
Symfony\Component\Filesystem\Filesystem
;
use
Symfony\Component\Security\Core\User\UserInterface
;
use
Symfony\Contracts\HttpClient\HttpClientInterface
;
#[ORM\Table(name:'capsule')]
#[UniqueConstraint(name:'index_capsule_nom', columns:['nom'])]
...
...
@@ -191,7 +192,7 @@ class Capsule
return
$this
->
editors
;
}
public
function
getVideoPreviewImageLink
():
?string
public
function
getVideoPreviewImageLink
(
HttpClientInterface
$http_client
):
?string
{
$file_system
=
new
Filesystem
();
...
...
@@ -204,7 +205,15 @@ class Capsule
$video_id
=
$project_retriever
->
getVideoId
(
$video_url
);
if
(
str_contains
(
$video_url
,
'yout'
))
{
return
'https://img.youtube.com/vi/'
.
$video_id
.
'/maxresdefault.jpg'
;
$url
=
'https://img.youtube.com/vi/%s/%s.jpg'
;
$high_resolution
=
sprintf
(
$url
,
$video_id
,
'maxresdefault'
);
$medium_resolution
=
sprintf
(
$url
,
$video_id
,
'mqdefault'
);
try
{
$http_client
->
request
(
'GET'
,
$high_resolution
);
return
$high_resolution
;
}
catch
(
\Exception
$e
)
{
return
$medium_resolution
;
}
}
return
'https://vumbnail.com/'
.
$video_id
.
'.jpg'
;
...
...
This diff is collapsed.
Click to expand it.
templates/capsule/index.html.twig
+
2
−
2
View file @
0a4bdf73
...
...
@@ -62,10 +62,10 @@
<div
class=
"d-flex flex-column flex-xl-row justify-content-center align-items-center"
>
<div
class=
"m-4 ratio ratio-16x9"
>
{%
if
capsule.getVideoPreviewImageLink
()
is
null
%}
{%
if
capsule.getVideoPreviewImageLink
(
http_client
)
is
null
%}
<img
src=
"
{{
asset
(
'build/images/project_not_found.jpg'
)
}}
"
alt=
"video preview"
>
{%
else
%}
<img
src=
"
{{
capsule.getVideoPreviewImageLink
()
}}
"
alt=
"video preview"
>
<img
src=
"
{{
capsule.getVideoPreviewImageLink
(
http_client
)
}}
"
alt=
"video preview"
>
{%
endif
%}
</div>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment