4
4
*/
5
5
/* eslint-disable require-await */
6
6
7
+ import { kodi } from "../kodi.js" ;
7
8
import * as labeller from "../labeller/youtube.js" ;
8
9
import { matchPattern } from "../tools/matchpattern.js" ;
9
10
10
11
/**
11
- * L'URL de l'extension pour lire des vidéos issues de YouTube.
12
+ * L'URL de l'extension <em>YouTube</em> pour lire des vidéos issues de YouTube.
12
13
*
13
14
* @type {string }
14
15
*/
15
- const PLUGIN_URL = "plugin://plugin.video.youtube/play/" ;
16
+ const YOUTUBE_PLUGIN_URL = "plugin://plugin.video.youtube/play/" ;
17
+
18
+ /**
19
+ * L'URL de l'extension <em>Tubed</em> pour lire des vidéos issues de YouTube.
20
+ *
21
+ * @type {string }
22
+ */
23
+ const TUBED_PLUGIN_URL = "plugin://plugin.video.tubed/?mode=play" ;
16
24
17
25
/**
18
26
* Génère l'URL d'une vidéo dans l'extension YouTube.
@@ -24,8 +32,17 @@ const PLUGIN_URL = "plugin://plugin.video.youtube/play/";
24
32
* <em>fichier</em>.
25
33
*/
26
34
export const generateVideoUrl = async function ( videoId , incognito ) {
27
- return `${ PLUGIN_URL } ?video_id=${ videoId } ` +
28
- `&incognito=${ incognito . toString ( ) } ` ;
35
+ const addons = await kodi . addons . getAddons ( "video" ) ;
36
+ // Si les deux extensions YouTube et Tubed sont présentes ou si aucune est
37
+ // présente : envoyer les vidéos à YouTube ; sinon envoyer à l'extension
38
+ // présente.
39
+ if ( addons . includes ( "plugin.video.tubed" ) &&
40
+ ! addons . includes ( "plugin.video.youtube" ) ) {
41
+ return `${ TUBED_PLUGIN_URL } &video_id=${ videoId } ` ;
42
+ }
43
+
44
+ return `${ YOUTUBE_PLUGIN_URL } ?video_id=${ videoId } ` +
45
+ `&incognito=${ incognito . toString ( ) } ` ;
29
46
} ;
30
47
31
48
/**
@@ -38,14 +55,23 @@ export const generateVideoUrl = async function (videoId, incognito) {
38
55
* <em>fichier</em>.
39
56
*/
40
57
export const generatePlaylistUrl = async function ( playlistId , incognito ) {
58
+ const addons = await kodi . addons . getAddons ( "video" ) ;
59
+ // Si les deux extensions YouTube et Tubed sont présentes ou si aucune est
60
+ // présente : envoyer les vidéos à YouTube ; sinon envoyer à l'extension
61
+ // présente.
62
+ if ( addons . includes ( "plugin.video.tubed" ) &&
63
+ ! addons . includes ( "plugin.video.youtube" ) ) {
64
+ return `${ TUBED_PLUGIN_URL } &playlist_id=${ playlistId } ` ;
65
+ }
66
+
41
67
const config = await browser . storage . local . get ( [ "youtube-order" ] ) ;
42
- return `${ PLUGIN_URL } ?playlist_id=${ playlistId } ` +
43
- `&order=${ config [ "youtube-order" ] } ` +
44
- `&play=1&incognito=${ incognito . toString ( ) } ` ;
68
+ return `${ YOUTUBE_PLUGIN_URL } ?playlist_id=${ playlistId } ` +
69
+ `&order=${ config [ "youtube-order" ] } ` +
70
+ `&play=1&incognito=${ incognito . toString ( ) } ` ;
45
71
} ;
46
72
47
73
/**
48
- * Extrait le titre d'une vidéo ou d'une liste de lecture YouTube.
74
+ * Extrait le titre d'une vidéo ou d'une playlist YouTube.
49
75
*
50
76
* @param {URL } url L'URL utilisant le plugin de YouTube.
51
77
* @returns {Promise<?string> } Une promesse contenant le titre ou
@@ -61,4 +87,5 @@ const action = async function ({ searchParams }) {
61
87
return null ;
62
88
} ;
63
89
export const extract = matchPattern ( action ,
64
- "plugin://plugin.video.youtube/play/*" ) ;
90
+ "plugin://plugin.video.youtube/play/*" ,
91
+ "plugin://plugin.video.tubed/*" ) ;
0 commit comments