This repository was archived by the owner on Jan 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathartePlusPlus.user.js
158 lines (133 loc) · 4.27 KB
/
artePlusPlus.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// ==UserScript==
// @name Arte++
// @version 1.2.2
// @description Download videos of Arte.tv
// @downloadURL https://raw.githubusercontent.com/valsou/artePlusPlus/master/artePlusPlus.user.js
// @updateURL https://raw.githubusercontent.com/valsou/artePlusPlus/master/artePlusPlus.user.js
// @author Valentin MEZIN
// @match https://www.arte.tv/*/videos/*
// @run-at document-body
// @grant GM_addStyle
// @grant GM_setClipboard
// @noframes
// ==/UserScript==
'use strict';
GM_addStyle(`
#arteplusplus {
width: 100%;
font-family: barna,sans-serif;
font-weight: 500;
line-height: 1.4;
background-color: rgb(31,31,31);
color: white;
display: inline-block;
}
#arteplusplus p {
padding: 16px 0;
}
.arteplusplus_link:after {
content: "Copied";
position: absolute;
right: 0;
color: #fff;
}
.arteplusplus_link {
position: relative;
background-color: rgb(70,70,70);
color: rgb(40,40,40);
border: 0;
padding: 4px;
}
.arteplusplus_link.copied {
background-color: rgb(250,72,28);
color: white;
}
#arteplusplus a {
color: white;
text-decoration: underline;
}`);
const ARTE_API = 'https://api.arte.tv/api/player/v2/config/';
const REGEX = /https:\/\/www.arte.tv\/(fr|de|en|es|pl|it)\/videos\/\d{6}-\d{3}-[A-Z]\//;
const LOCATION = window.location.pathname.split("/");
const LANG = LOCATION[1];
const VIDEO_ID = LOCATION[3];
const ELEMENT_TO_OBSERVE = document.querySelector('main').children[1];
const LOCALE = {
'downloads': {
'fr': 'Téléchargements',
'de': 'Downloads',
'en': 'Downloads',
'es': 'Descargas',
'pl': 'Pliki do pobrania',
'it': 'Download'},
'copy': {
'fr': 'Copier',
'de': 'Kopieren',
'en': 'Copy',
'es': 'Copiar',
'pl': 'Kopiuj',
'it': 'Copia'},
'copied': {
'fr': 'Copié !',
'de': 'Kopiert !',
'en': 'Copied !',
'es': 'Copiado !',
'pl': 'Skopiowane !',
'it': 'Copiato !'}
};
const ICON_COPY = '⎘';
console.log("Arte++ is running...");
(function() {
console.log("Observing...");
getJSON();
})();
function getJSON() {
let api_base_url = ARTE_API + LANG + "/";
let api_url = api_base_url + VIDEO_ID;
fetch(api_url)
.then(
function(response) {
response.json().then(function(data) {
getLinks(data);
});
}
);
}
function getLinks(json) {
let video_data = json.data.attributes.streams;
let video_keys = Object.keys(video_data);
let array_to_return = [];
Array.from(video_keys).forEach((key) => {
let data = video_data[key];
array_to_return.push({
url: data.url,
label: data.versions[0].label
});
});
showLinks(array_to_return);
}
function showLinks(data) {
ELEMENT_TO_OBSERVE.insertAdjacentHTML('afterend', '<div id="arteplusplus"></div>');
let div = document.querySelector("#arteplusplus");
div.setAttribute('class',div.previousSibling.getAttribute('class'));
div.innerHTML = "<p><b>Copy and paste one of the links below with youtube-dl software.</b>It will download the stream of the audio & the video, then merge both into a .mp4 file. You'll also need ffmpeg to do the merging.<br>";
div.innerHTML += "Youtube-dl downlopad page: <a href=\"https://github.com/ytdl-org/youtube-dl\">https://github.com/ytdl-org/youtube-dl</a><br>FFmpeg download page: <a href=\"https://ffmpeg.org/download.html\">https://ffmpeg.org/download.html</a><br><br>";
div.innerHTML += "arte.tv doesn't provide anymore link to a .mp4 file. :)<br><br>";
data.forEach((key) => {
div.innerHTML += `<div><b>`+key.label+`</b> : <input style="width:100%;" class="arteplusplus_link" type="text" value="`+encodeURI(key.url)+`"></div>`
});
div.innerHTML += "</p>";
let inputs = document.querySelectorAll('.arteplusplus_link');
Array.from(inputs).forEach(link => {
link.addEventListener('click', function(event) {
GM_setClipboard(link.value, "text")
link.classList.add("copied");
let temp = link.value
link.value = LOCALE.copied[LANG]
setTimeout(function(timer){
link.classList.remove("copied");
link.value = temp
}, 400)
});
});
}