-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlScraper.js
executable file
·349 lines (318 loc) · 8.03 KB
/
urlScraper.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/// LABELING_SECTION_START
// https://github.com/puutaro/newsSpeecher
/// LABELING_SECTION_END
/// SETTING_SECTION_START
editExecute="ALWAYS"
onAutoExec="OFF"
mustUbuntuSetup="ON"
disableSettingValsEdit="ON"
terminalSizeType="LONG"
terminalOutputMode="NORMAL"
execPlayBtnLongPress="WEB_SEARCH"
execEditBtnLongPress="PAGE_SEARCH"
onUpdateLastModify="ON"
onUrlHistoryRegister="ON"
terminalFontZoom="0"
terminalColor=""
terminalFontColor=""
homeScriptUrlsPath=""
playButtonConfig="icon=black_history,caption=urlHistory,click=func=URL_HISTORY,longClick=func="
editButtonConfig="visible=ON,icon=shortcut,caption=spechList,click=func=OK,longClick=func="
srcImageAnchorLongPressMenuFilePath=""
srcAnchorLongPressMenuFilePath=""
setReplaceVariables="file://"
setVariableTypes="file://"
hideSettingVariables="file://"
scriptFileName="newsSpeecher.js"
/// SETTING_SECTION_END
/// CMD_VARIABLE_SECTION_START
SPEECH_MODE="shuffle"
EACH_NUM="5"
Summary=""
RE_SUMMARY=""
STOP=""
SETTING=""
newsUrlListName=""
EDIT_NEWS_URL_LIST_NAME=""
Install=""
TO_LANG="-"
ON_SPEECH="ON"
ON_BEFORE_SUMMARY="ON"
ON_OUTPUT_IN_HISTRORY_CLICK="OFF"
MAX_CONCUR=5
PICH=50
SUMMARY_LENGTH="300"
/// CMD_VARIABLE_SECTION_END
/// Please write bellow with javascript
const LONG_PRESS_NEWS_URL = "${LONG_PRESS_LINK_URL}";
let args = jsArgs.get().split("\t");
const FIRST_ARG = decide_arg(args[0]);
installModeHandler();
// execOnAutoExec();
const EDIT_URL_LIST_PATH = makeEditUrlListPath();
const PLAY_LIST_TEMP_DIR_PATH = makePlaySrcDirPath();
const PLAY_LIST_TEMP_SRC_DIR_PATH = `${PLAY_LIST_TEMP_DIR_PATH}/src`;
jsFileSystem.createDir(PLAY_LIST_TEMP_SRC_DIR_PATH);
const PLAY_CONTENTS_TXT_PATH = `${PLAY_LIST_TEMP_DIR_PATH}/contents.txt`;
const NEWS_PLAY_LIST_TSV_PATH = `${PLAY_LIST_TEMP_DIR_PATH}/play_list.tsv`;
argSwitcher();
function argSwitcher() {
jsFileSystem.createDir(
"${newsSpeecherShellTempDirPath}"
);
updateByVariableWhenDiff(
"newsUrlListName",
EDIT_URL_LIST_PATH.split("/").at(-1),
);
saveArgsTsv();
endByEachNum();
bootUbuntu();
switch(FIRST_ARG){
case "":
editSiteHandler();
break;
case "${STOP_MODE}":
execProcessStop();
break;
case "${EDIT_NEWS_URL_LIST_NAME_MODE}":
editUrlListHandler();
break;
case "${SETTIN_MODE}":
settingHandler();
break;
case "${RE_SUMMARY_MODE}":
reSumamryHandler();
break;
case "${URL_HISTORY_CLICK_MODE}":
case "${SUMMARY_MODE}":
summaryHandler();
break;
case "${LONG_PRESS_SUMMARY_MODE}":
longPressSummaryHandler();
break;
};
};
function editSiteHandler(){
let extraMapStr = [
`src_path=${APP_URL_HISTORY_PATH}`,
`on_click_sort=false`,
'on_sortable_js=true',
`on_click_url=true`,
`on_dialog=false`,
`extra_js_path_list=${01}/system/js/clipToHistory.js`,
`extra_label=CtoH`,
].join("|");
jsIntent.launchEditSite(
EDIT_URL_LIST_PATH,
extraMapStr,
"urlString.startsWith('http');",
);
};
function execProcessStop(){
jsToast.short("stop..");
jsUbuntu.execScriptByBackground(
"${NEWS_SPEECHER_STOP_ALL_PROCESS_SHELL_PATH}",
"",
1,
);
};
function longPressSummaryHandler(){
jsToast.short(`long press summary..`);
jsFileSystem.writeLocalFile(
EDIT_URL_LIST_PATH,
`${LONG_PRESS_NEWS_URL}\t${LONG_PRESS_NEWS_URL}`
);
jsUbuntu.execScriptByBackground(
`${NEWS_SPEECHER_SUMMARIZE_SHELL_PATH}`,
"",
1,
);
};
function summaryHandler(){
jsToast.short(`summary..`);
jsUbuntu.execScriptByBackground(
`${NEWS_SPEECHER_SUMMARIZE_SHELL_PATH}`,
"",
1,
);
};
function reSumamryHandler() {
jsToast.short(`re-summary..`);
jsUbuntu.execScriptByBackground(
`${NEWS_SPEECHER_CAT_AND_SPEECH_SHELL_PATH}`,
"IMPORTANCE=high",
1,
);
};
function editUrlListHandler(){
const setVariableTypeCon = [
`newsUrlListName:TXT:FSB=${FCB_DIR_PATH}=${NEWS_SPEECHER_EDIT_DIR_PATH}`,
`${FCB_PREFIX}=${NEWS_SPEECHER_PREFIX}`,
`${FCB_SUFFIX}=${TSV_EXTEND}`,
].join("?");
jsFileSelect.execEditTargetFileName(
"newsUrlListName",
"renameNewsUrlListName",
"${NEWS_SPEECHER_EDIT_DIR_PATH}",
setVariableTypeCon,
`newsUrlListName=${newsUrlListName}\nrenameNewsUrlListName=`,
"${NEWS_SPEECHER_PREFIX}",
"${TSV_EXTEND}",
"${NEWS_SPEECHER_PATH}",
"Edit newsUrlListName"
);
};
function getLang(){
if(
TO_LANG == "-"
|| TO_LANG == ""
) return jsUtil.lang();
return TO_LANG;
};
function endByEachNum(){
switch(FIRST_ARG){
case "":
case "${STOP_MODE}":
case "${EDIT_NEWS_URL_LIST_NAME_MODE}":
case "${SETTIN_MODE}":
return;
};
if(
EACH_NUM < Number("${EACH_NUM_MIN}")
) {
jsToast.short(`Set EACH_NUM: ${EACH_NUM}`);
exitZero();
};
};
function makeEditUrlListPath(){
jsFileSystem.createDir("${NEWS_SPEECHER_EDIT_DIR_PATH}");
if(
FIRST_ARG === "${LONG_PRESS_SUMMARY_MODE}"
) return `${NEWS_SPEECHER_EDIT_DIR_PATH}/${LONG_PRESS_EDIT_TSV_NAME}`;
if(
!newsUrlListName
) return `${NEWS_SPEECHER_EDIT_DIR_PATH}/${DEFAULT_EDIT_TSV_NAME}`;
const prefixCompUrlListName = jsPath.compPrefix(
newsUrlListName,
"${NEWS_SPEECHER_PREFIX}",
);
const compNewsUrlListName = jsPath.compExtend(
prefixCompUrlListName,
"${TSV_EXTEND}"
);
return `${NEWS_SPEECHER_EDIT_DIR_PATH}/${compNewsUrlListName}`;
};
function makePlaySrcDirPath() {
const playListTempDirName = jsPath.removeExtend(
EDIT_URL_LIST_PATH.split("/").at(-1),
"${TSV_EXTEND}",
);
return `${newsSpeecherShellTempDirPath}/${playListTempDirName}`;
};
function updateByVariableWhenDiff(
tergetVariableName,
currentVariableValue,
){
if (
FIRST_ARG === "${LONG_PRESS_SUMMARY_MODE}"
) return;
jsEdit.updateByVariable(
"${NEWS_SPEECHER_PATH}",
tergetVariableName,
currentVariableValue
);
};
function settingHandler(){
const setVariableContents = [
`TO_LANG:CB=-?ja?en?zh?es?ko`,
`ON_SPEECH:LBL:CB=${TXT_LABEL}=THIS|ON?OFF`,
`ON_BEFORE_SUMMARY:LBL:CB=${TXT_LABEL}=THIS|ON?OFF`,
`ON_OUTPUT_IN_HISTRORY_CLICK:LBL:CB=${TXT_LABEL}=THIS|ON?OFF`,
`PICH:TXT:LBL:NUM=${TXT_LABEL}=Pich (normal: 50)|?1..100?1`,
`SUMMARY_LENGTH:TXT:LBL:NUM=${TXT_LABEL}=THIS|?100..1000?100`,
`MAX_CONCUR:TXT:LBL:NUM=${TXT_LABEL}=Max concur (default: 5)|?2..20?1`,
].join("\n");
const varNameValCon = [
`TO_LANG=${TO_LANG}`,
`ON_SPEECH=${ON_SPEECH}`,
`ON_BEFORE_SUMMARY=${ON_BEFORE_SUMMARY}`,
`ON_OUTPUT_IN_HISTRORY_CLICK=${ON_OUTPUT_IN_HISTRORY_CLICK}`,
`PICH=${PICH}`,
`SUMMARY_LENGTH=${SUMMARY_LENGTH}`,
`MAX_CONCUR=${MAX_CONCUR}`,
].join("\n");
jsValEdit.editAndSaveCmdVar(
"Setting",
"${NEWS_SPEECHER_PATH}",
setVariableContents,
varNameValCon,
);
};
function installModeHandler(){
if(
FIRST_ARG !== "${INSTALL_MODE}"
) return;
jsToast.short("Installing..");
jsUbuntu.execScriptByBackground(
"${NEWS_SPEECHER_INSTALL_SHELL_PATH}",
"",
1,
);
exitZero();
};
function saveArgsTsv(){
switch(FIRST_ARG){
case "":
case "${STOP_MODE}":
case "${EDIT_NEWS_URL_LIST_NAME_MODE}":
case "${SETTIN_MODE}":
return;
};
if (
FIRST_ARG === "${LONG_PRESS_SUMMARY_MODE}"
){
EACH_NUM = Number(`${LONG_PRESS_EACH_NUM}`);
}
const summaryArgsCon = [
`EACH_NUM\t${EACH_NUM}`,
`TO_LANG\t${getLang()}`,
`SPEECH_MODE\t${SPEECH_MODE}`,
`ON_SPEECH\t${ON_SPEECH}`,
`ON_BEFORE_SUMMARY\t${ON_BEFORE_SUMMARY}`,
`ON_OUTPUT\t${decide_on_output()}`,
`SUMMARY_LENGTH\t${SUMMARY_LENGTH}`,
`MAX_CONCUR\t${MAX_CONCUR}`,
`PICH\t${PICH}`,
`EDIT_URL_LIST_PATH\t${EDIT_URL_LIST_PATH}`,
`PLAY_LIST_TEMP_DIR_PATH\t${PLAY_LIST_TEMP_DIR_PATH}`,
`PLAY_LIST_TEMP_SRC_DIR_PATH\t${PLAY_LIST_TEMP_SRC_DIR_PATH}`,
`PLAY_CONTENTS_TXT_PATH\t${PLAY_CONTENTS_TXT_PATH}`,
`NEWS_PLAY_LIST_TSV_PATH\t${NEWS_PLAY_LIST_TSV_PATH}`,
].join("\n");
jsFileSystem.writeLocalFile(
"${NEWS_SPEECHER_ARGS_TSV_PATH}",
summaryArgsCon
);
};
function bootUbuntu(){
switch(FIRST_ARG){
case "":
case "${EDIT_NEWS_URL_LIST_NAME_MODE}":
case "${SETTIN_MODE}":
return;
};
jsUbuntu.boot();
};
function decide_arg(first_arg){
if(
LONG_PRESS_NEWS_URL.includes("https://")
) return "${LONG_PRESS_SUMMARY_MODE}";
return first_arg;
};
function decide_on_output(){
if(
FIRST_ARG == "${URL_HISTORY_CLICK_MODE}"
&& ON_OUTPUT_IN_HISTRORY_CLICK == "OFF"
) return "OFF";
return "ON";
};