Skip to content

Commit 6964012

Browse files
committed
Added support for YouTube live videos playback.
1 parent fcefcce commit 6964012

File tree

4 files changed

+100
-79
lines changed

4 files changed

+100
-79
lines changed

README.md

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,48 @@
1010

1111
- Same code used in the WebApp but organized as a class; it also includes a test class; CLI app.
1212

13-
## WebApp
13+
## Web App
1414

1515
- Link: [`URL Parser`](https://tomasfn87.github.io/url-parser/)
1616

1717
### Description
1818

19-
- [Parses](https://github.com/tomasfn87/url-parser/blob/main/index.html#L41) a URL in 4 parts:
19+
- [Parses](https://github.com/tomasfn87/url-parser/blob/main/index.html#L42) a URL in 4 parts:
2020
- `Domain`;
2121
- `Path`;
2222
- `Parameters`;
2323
- `Fragment`.
24-
- **Domain** tries to [obtain](https://github.com/tomasfn87/url-parser/blob/main/index.html#L217) the site's icon (`favicon`) using a Google API;
25-
- **Parameters** and **Fragment** are [parsed](https://github.com/tomasfn87/url-parser/blob/main/index.html#L24) into `key` and (optional) `value`;
26-
- **Decode**: press the [`Decode`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L160) button to solve encoded characters and actually read the URL's content.
27-
28-
### [`YouTube`](https://www.youtube.com)
29-
30-
- Supports `YouTube` - for [`videos`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L344), [`playlists`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L311) and [`user uploaded videos`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L385):
31-
- When a `YouTube` **video**, **playlist** or **user** URL is detected, a `YouTube IFrame API player` will appear bellow the result table;
32-
- **Videos**, **playlists** and **user uploaded videos** are `automatically played`;
33-
- **Videos**, **playlists** and **user uploaded videos** start `muted`.
34-
- YouTube Video
35-
- [`https://` `www.youtube.com/watch` `?v=QD5cs3R1bL4`](https://www.youtube.com/watch?v=QD5cs3R1bL4)
36-
- [`https://` `youtu.be/` `QD5cs3R1bL4`](https://youtu.be/QD5cs3R1bL4)
37-
- YouTube Playlist with video
38-
- [`https://` `www.youtube.com/watch` `?v=HvC96EaQDmU` `&list=PLUQEQQ0Bum94su5p55Hr55R97X-SsMzQl`](https://www.youtube.com/watch?v=HvC96EaQDmU&list=PLUQEQQ0Bum94su5p55Hr55R97X-SsMzQl)
39-
- YouTube Playlist
40-
- [`https://` `www.youtube.com/` `?list=PLUQEQQ0Bum94su5p55Hr55R97X-SsMzQl`](https://www.youtube.com/?list=PLUQEQQ0Bum94su5p55Hr55R97X-SsMzQl)
41-
- YouTube User
42-
- [`https://` `www.youtube.com/` `@Google`](https://www.youtube.com/@Google)
43-
- :warning: not all user uploaded videos lists were sucessfully [loaded](https://github.com/tomasfn87/url-parser/blob/main/index.html#L488); bigger channels seem to work fine.
44-
45-
### [`Vimeo`](https://www.vimeo.com)
46-
47-
- [Videos](https://github.com/tomasfn87/url-parser/blob/main/index.html#L418).
48-
49-
### [`Spotify`](https://www.spotify.com)
50-
51-
- [Tracks](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
52-
- [Episodes](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
53-
- [Shows](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
54-
- [Artists](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
55-
- [Albums](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
56-
- [Playlists](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
24+
- **Domain** tries to [obtain](https://github.com/tomasfn87/url-parser/blob/main/index.html#L218) the site's icon (`favicon`) using a Google API;
25+
- **Parameters** and **Fragment** are [parsed](https://github.com/tomasfn87/url-parser/blob/main/index.html#L25) into `key` and (optional) `value`;
26+
- **Decode**: press the [`Decode`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L161) button to solve encoded characters and actually read the URL's content.
27+
28+
### Media Players supported
29+
30+
#### [`YouTube`](https://www.youtube.com)
31+
32+
- [`Videos`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L344);
33+
- [`Playlists`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L311;)
34+
- [`Lives`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L385);
35+
- [`User uploaded videos`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L411).
36+
37+
#### [`Vimeo`](https://www.vimeo.com)
38+
39+
- [Videos](https://github.com/tomasfn87/url-parser/blob/main/index.html#L444).
40+
41+
#### [`Spotify`](https://www.spotify.com)
42+
43+
- [Tracks](https://github.com/tomasfn87/url-parser/blob/main/index.html#L465);
44+
- [Episodes](https://github.com/tomasfn87/url-parser/blob/main/index.html#L465);
45+
- [Shows](https://github.com/tomasfn87/url-parser/blob/main/index.html#L465);
46+
- [Artists](https://github.com/tomasfn87/url-parser/blob/main/index.html#L465);
47+
- [Albums](https://github.com/tomasfn87/url-parser/blob/main/index.html#L465);
48+
- [Playlists](https://github.com/tomasfn87/url-parser/blob/main/index.html#L465);
49+
- Spotify URIs are accepted and converted into URLs.
50+
51+
#### Spotify Audio Tag for Google Tag Manager
52+
5753
- [Contribution](https://community.spotify.com/t5/Spotify-for-Developers/Spotify-iFrame-tracking-via-GTM-Any-code/m-p/6945950) to Google [Tag Manager](https://tagmanager.google.com) / [Analytics](https://analytics.google.com) tracking solution for Spotify content:
5854
- [Documentation](https://github.com/tomasfn87/url-parser/blob/main/gtm/spotify-audio.json.md).
59-
- Spotify URIs are accepted and converted into URLs.
6055

6156
## Art
6257

README.pt-br.md

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,48 @@
1010

1111
- Mesmo código usado no WebApp porém organizado como uma classe; também inclui uma classe de testes; app de ILC (CLI).
1212

13-
## WebApp
13+
## Aplicação Web
1414

1515
- Link: [`URL Parser`](https://tomasfn87.github.io/url-parser/)
1616

1717
### Descrição
1818

19-
- [Divide](https://github.com/tomasfn87/url-parser/blob/main/index.html#L41) a URL em 4 partes:
19+
- [Divide](https://github.com/tomasfn87/url-parser/blob/main/index.html#L42) a URL em 4 partes:
2020
- `Domínio`;
2121
- `Caminho`;
2222
- `Parâmetros`;
2323
- `Fragmento`.
24-
- **Domínio** tenta [obter](https://github.com/tomasfn87/url-parser/blob/main/index.html#L217) o ícone do site (`favicon`) usando uma API do Google;
25-
- **Parâmetros** e **Fragmento** são [divididos](https://github.com/tomasfn87/url-parser/blob/main/index.html#L24) em `chave` e `valor` (opcional);
26-
- **Decodificar**: aperte o botão [`Decodificar`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L160) para resolver caracteres codificados e de fato ler o conteúdo da URL.
27-
28-
### [`YouTube`](https://www.youtube.com)
29-
30-
- Suporta `YouTube` - para [`vídeos`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L344), [`listas de reprodução`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L311) e [`vídeos enviados pelo usuário`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L385):
31-
- Quando uma URL do `YouTube` de **vídeo**, **lista de reprodução** ou **usuário** é detectada, um `Reprodutor da API de IFrame do YouTube` irá aparecer abaixo da tabela do resultado;
32-
- **Videos**, **listas de reprodução** e **vídeos enviados pelo usuário** são `automaticamente executados`;
33-
- **Videos**, **listas de reprodução** e **vídeos enviados pelo usuário** iniciam `mudos`.
34-
- Vídeo do YouTube
35-
- [`https://` `www.youtube.com/watch` `?v=QD5cs3R1bL4`](https://www.youtube.com/watch?v=QD5cs3R1bL4)
36-
- [`https://` `youtu.be/` `QD5cs3R1bL4`](https://youtu.be/QD5cs3R1bL4)
37-
- Lista de reprodução do YouTube com vídeo
38-
- [`https://` `www.youtube.com/watch` `?v=HvC96EaQDmU` `&list=PLUQEQQ0Bum94su5p55Hr55R97X-SsMzQl`](https://www.youtube.com/watch?v=HvC96EaQDmU&list=PLUQEQQ0Bum94su5p55Hr55R97X-SsMzQl)
39-
- Lista de reprodução do YouTube
40-
- [`https://` `www.youtube.com/` `?list=PLUQEQQ0Bum94su5p55Hr55R97X-SsMzQl`](https://www.youtube.com/?list=PLUQEQQ0Bum94su5p55Hr55R97X-SsMzQl)
41-
- Usuário do YouTube
42-
- [`https://` `www.youtube.com/` `@Google`](https://www.youtube.com/@Google)
43-
- :warning: nem todas as listas de vídeos enviados pelo usuário foram [carregadas](https://github.com/tomasfn87/url-parser/blob/main/index.html#L488) com sucesso; canais maiores parecem funcionar bem.
44-
45-
### [`Vimeo`](https://www.vimeo.com)
24+
- **Domínio** tenta [obter](https://github.com/tomasfn87/url-parser/blob/main/index.html#L218) o ícone do site (`favicon`) usando uma API do Google;
25+
- **Parâmetros** e **Fragmento** são [divididos](https://github.com/tomasfn87/url-parser/blob/main/index.html#L25) em `chave` e `valor` (opcional);
26+
- **Decodificar**: aperte o botão [`Decodificar`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L161) para resolver caracteres codificados e de fato ler o conteúdo da URL.
27+
28+
### Reprodutores de Mídia suportados
29+
30+
#### [`YouTube`](https://www.youtube.com)
31+
32+
- [`Vídeos`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L344);
33+
- [`Listas de reprodução`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L311;)
34+
- [`Ao vivo`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L385);
35+
- [`Vídeos enviados pelo usuário`](https://github.com/tomasfn87/url-parser/blob/main/index.html#L411).
36+
37+
#### [`Vimeo`](https://www.vimeo.com)
4638

4739
- [Vídeos](https://github.com/tomasfn87/url-parser/blob/main/index.html#L418).
4840

49-
### [`Spotify`](https://www.spotify.com)
41+
#### [`Spotify`](https://www.spotify.com)
5042

5143
- [Faixas](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
5244
- [Episódios](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
5345
- [Shows](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
5446
- [Artistas](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
5547
- [Álbuns](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
5648
- [Listas de reprodução](https://github.com/tomasfn87/url-parser/blob/main/index.html#L439);
49+
- URIs do Spotify são aceitas e convertidas em URLs.
50+
51+
#### Tag Áudio do Spotify para Google Tag Manager
52+
5753
- [Contribuição](https://community.spotify.com/t5/Spotify-for-Developers/Spotify-iFrame-tracking-via-GTM-Any-code/m-p/6945950) com a solução de tracking para Google [Tag Manager](https://tagmanager.google.com) / [Analytics](https://analytics.google.com) para conteúdo do Spotify:
5854
- [Documentação](https://github.com/tomasfn87/url-parser/blob/main/gtm/spotify-audio.json.pt-br.md).
59-
- URIs do Spotify são aceitas e convertidas em URLs.
6055

6156
## Arte
6257

index.html

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
YouTubeVideo: /(https?:\/\/)?((?:www|m)\.)?youtu(\.be|be\.com)\/?(?:(?:watch)?\?.*v=|embed\/)?([0-9A-Za-z_-]{11}).*/i,
1717
YouTubePlaylist: /(https?:\/\/)?((?:www|m)\.)?youtu(\.be|be\.com)\/?.*?(?:play)?list=([0-9A-Za-z_-]+)/i,
1818
YouTubeUser: /(https?:\/\/)?((?:www|m)\.)?youtu(\.be|be\.com)\/?.*@([^\/?#=]+).*/i,
19+
YouTubeLive: /(https?:\/\/)?((?:www|m)\.)?youtu(\.be|be\.com)\/?(?:live\/)?([0-9A-Za-z_-]{11}).*/i,
1920
VimeoVideo: /(https?:\/\/)?(\w+\.)?vimeo.com\/(\d+)/i,
2021
SpotifyContent: /(?:https?:\/\/)?(?:\w+\.)?spotify.com\/.*(track|episode|playlist|album|artist|show)\/([^\/?#=]+)\S*/i,
2122
SpotifyUri: /spotify:(album|artist|episode|playlist|show|track):([^ \/?&#=]+)/i
@@ -189,7 +190,7 @@ <h2>Analysis Result:</h2>
189190
const r = parseUrl(url);
190191
parsedResultTableBody.innerHTML = '';
191192
document.getElementById('output-container').querySelectorAll('#youtube-embed-container, .youtube-message-container').forEach(el => el.remove());
192-
document.body.classList.remove('youtube-background');
193+
document.body.classList.remove('media-background');
193194

194195
if (!r && urlInput.value) {
195196
const row = parsedResultTableBody.insertRow();
@@ -302,15 +303,14 @@ <h2>Analysis Result:</h2>
302303
}
303304

304305
addTableRow("Full URL", `<a href="${`https://${fullUrl.replace(/^\s*\w+:\/\//, '')}`}" class="url-link">${decode?decodeURIComponent(fullUrl):fullUrl}</a>`, isOdd);
305-
306306

307307
let link = 'https://'
308308
+ parsed_self_url.parts.domain.replace(/^\w+:\/\//, '')
309309
+ parsed_self_url.parts.path
310310

311311
// YouTube Playlist
312312
if (regexp.YouTubePlaylist.test(url)) {
313-
document.body.classList.add('youtube-background');
313+
document.body.classList.add('media-background');
314314
const match = url.match(regexp.YouTubePlaylist);
315315
const playlistId = match && match[4];
316316
if (playlistId) {
@@ -341,9 +341,9 @@ <h2>Analysis Result:</h2>
341341
messageContainer.textContent = "Não foi possível extrair o ID da playlist.";
342342
document.getElementById('output-container').appendChild(messageContainer);
343343
}
344-
// YouTube Video
344+
// YouTube Video
345345
} else if (regexp.YouTubeVideo.test(url)) {
346-
document.body.classList.add('youtube-background');
346+
document.body.classList.add('media-background');
347347
const match = url.match(regexp.YouTubeVideo);
348348
const videoId = match && match[4];
349349
if (videoId) {
@@ -382,9 +382,35 @@ <h2>Analysis Result:</h2>
382382
messageContainer.textContent = "Não foi possível extrair o ID do vídeo.";
383383
document.getElementById('output-container').appendChild(messageContainer);
384384
}
385+
// YouTube Live
386+
} else if (regexp.YouTubeLive.test(url)) {
387+
document.body.classList.add('media-background');
388+
const match = url.match(regexp.YouTubeLive);
389+
const liveId = match && match[4];
390+
if (liveId) {
391+
youtubeEmbedContainer.innerHTML = '';
392+
player = new YT.Player('youtube-embed-container', {
393+
height: '270',
394+
width: '480',
395+
videoId: liveId,
396+
playerVars: {
397+
'playsinline': 1,
398+
'autoplay': 1,
399+
'mute': 1
400+
},
401+
events: {
402+
'onReady': onPlayerReadyYouTube,
403+
'onStateChange': onPlayerStateChangeYouTube
404+
}
405+
});
406+
link += '?youtubelive=' + liveId;
407+
link = correctMediaLink(link);
408+
document.getElementById('media-link').innerHTML =
409+
'&nbsp;&nbsp;|&nbsp;&nbsp;<a href="' + link + '" target="_blank">Media Link</a>';
410+
}
385411
// YouTube User's Videos
386412
} else if (regexp.YouTubeUser.test(url)) {
387-
document.body.classList.add('youtube-background');
413+
document.body.classList.add('media-background');
388414
const match = url.match(regexp.YouTubeUser);
389415
const userId = match && match[4];
390416
if (userId) {
@@ -417,7 +443,7 @@ <h2>Analysis Result:</h2>
417443
}
418444
// Vimeo Video
419445
} else if (regexp.VimeoVideo.test(url)) {
420-
document.body.classList.add('youtube-background');
446+
document.body.classList.add('media-background');
421447
const match = url.match(regexp.VimeoVideo);
422448
const videoId = match && match[3];
423449
var player = new Vimeo.Player(
@@ -438,7 +464,7 @@ <h2>Analysis Result:</h2>
438464
'&nbsp;&nbsp;|&nbsp;&nbsp;<a href="' + link + '" target="_blank">Media Link</a>';
439465
// Spotify Content
440466
} else if (regexp.SpotifyContent.test(url)) {
441-
document.body.classList.add('youtube-background');
467+
document.body.classList.add('media-background');
442468
const match = url.match(regexp.SpotifyContent);
443469
const contentType = match && match[1];
444470
const contentId = match && match[2];
@@ -468,7 +494,7 @@ <h2>Analysis Result:</h2>
468494
'&nbsp;&nbsp;|&nbsp;&nbsp;<a href="' + link + '" target="_blank">Media Link</a>';
469495
} else {
470496
youtubeEmbedContainer.innerHTML = '';
471-
document.body.classList.remove('youtube-background');
497+
document.body.classList.remove('media-background');
472498
}
473499
};
474500

@@ -526,6 +552,11 @@ <h2>Analysis Result:</h2>
526552
const youtubevideoUrl = 'https://www.youtube.com/?v='
527553
+ parsed_self_url.parts.parameters.obj.youtubevideo;
528554
document.getElementById('urlInput').value = youtubevideoUrl;
555+
// YouTube Live from URL Parameters
556+
} else if (parsed_self_url.parts.parameters.obj.youtubelive) {
557+
const youtubeliveUrl = 'https://www.youtube.com/live/'
558+
+ parsed_self_url.parts.parameters.obj.youtubelive;
559+
document.getElementById('urlInput').value = youtubeliveUrl;
529560
// YouTube User from URL Parameters
530561
} else if (parsed_self_url.parts.parameters.obj.youtubeuser) {
531562
const youtubeuserUrl = 'https://www.youtube.com/@'

style.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,34 +256,34 @@ th, td {
256256
margin: 0 auto;
257257
}
258258

259-
.youtube-background {
259+
.media-background {
260260
background-color: #111;
261261
color: #eee;
262262
}
263263

264-
.youtube-background h1,
265-
.youtube-background h2,
266-
.youtube-background label {
264+
.media-background h1,
265+
.media-background h2,
266+
.media-background label {
267267
color: #eee;
268268
}
269269

270-
.youtube-background .form-control {
270+
.media-background .form-control {
271271
background-color: #222;
272272
color: #eee;
273273
border-color: #555;
274274
}
275275

276-
.youtube-background .form-control:focus {
276+
.media-background .form-control:focus {
277277
background-color: #222;
278278
border-color: #baff33;
279279
box-shadow: 0 0 0 0.2rem rgba(186, 255, 51, 0.25);
280280
}
281281

282-
.youtube-background .form-control::placeholder {
282+
.media-background .form-control::placeholder {
283283
color: #999;
284284
}
285285

286-
.youtube-background .url-table {
286+
.media-background .url-table {
287287
background-color: #222;
288288
color: #eee;
289289
}

0 commit comments

Comments
 (0)