-
Notifications
You must be signed in to change notification settings - Fork 6
/
rc-file.adl
749 lines (576 loc) · 17.1 KB
/
rc-file.adl
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# =====================================================
# General Parsers, not specific to Mediathek-Archives #
# =====================================================
# ---------------
# Parser "empty":
# ---------------
# empty means something like "after implicit get do NOP"
# the parser definition is emty and only for testing.
# This can make sense in checking if the implicit get works+
# (check if the start-url works at all).
# also can be used together with "-v" option to get all
# sorts of information without starting any download actions
# and without injvoking any other ecreen-filling parsers like "dump".
parsername "empty": ()
start
dummy;
end
parsername "linkextract": ( )
start
linkextract;
print;
end
# seconds since the unix-epoche ( seconds since 00 h 00 min 00 s, 01.01.1970 )
# ----------------------------------------------------------------------------
parsername "unix-time": ( )
start
recall("NOW");
print;
end
parsername "linkextract-uniq": ( )
start
linkextract;
uniq;
print;
end
parsername "linkextract-uniq-sorted": ( )
start
linkextract;
uniq;
sort;
print;
end
parsername "linkextract2csv": ( )
start
linkextract;
to_matchres;
csv_save_as("links.csv");
print;
end
parsername "linkextract_xml": ( )
start
linkextract_xml;
print;
end
# html-deparse-dump
parsername "dump": ( )
start
dump;
end
# show tags
# ---------
parsername "show_tags": ( )
start
show_tags;
end
# show tags with complete html-path
# ---------------------------------
parsername "show_tags_full": ( )
start
show_tags_fullpath;
end
# show URL and title
# -------------------
parsername "pageinfo": ( )
start
print_string("\n"); # blank line
titleextract;
print;
print( " ", $STARTURL, "\n" );
end
# show URL and title - print as markdown link
# -------------------------------------------
# To be used as:
# $ any-dl -sep "" -p pageinfo.md <url.1> <url.2> ... <url.n>
parsername "pageinfo.md": ( )
start
titleextract;
store("title");
print( "[", $title, "](", $STARTURL, ")" );
end
# show URL and title, html-decoded
# -------------------
parsername "pageinfo2": ( )
start
print_string("\n"); # blank line
titleextract;
htmldecode;
print;
print( " ", $STARTURL, "\n" );
end
# show URL and title, html-decoded
# -------------------
# Htmldecode is done before text extraction
# Therefore the title is also converted correctly to utf-8, if
# other encodeings have been found.
# This seems to be the correct pageinfo-parser,
# which would relace "pageinfo" and "pageinfo2",
# but because missing time to test intensively,
# "pageinfo" and "pageinfo2" will not be removed now.
# Maybe later "pageinfo3" will replace "pageinfo",
# and the other pageinfo-parsers would be removed then.
# -------------------
parsername "pageinfo3": ( )
start
print_string("\n"); # blank line
htmldecode;
titleextract;
print;
print( " ", $STARTURL, "\n" );
end
# -----------------------------------------------------------
# Pageinfo as HTML-Link
# -----------------------------------------------------------
# use with CLI-switch -sep=""
# -----------------------------------------------------------
# You need to add html-beginning and html-end,
# but this creates the content in between,
# if used on many urls on CLI.
# -----------------------------------------------------------
parsername "pageinfo_html": ( )
start
print_string("<hr><p>");
htmldecode;
titleextract;
store("TITLE");
print_string("\n"); # blank line
print(>>><a href="<<<, $STARTURL, >>>"><<<, $TITLE, "</a>");
end
# ------------------------------------------
# only prints data part of the html, no tags
# acts like html-2-txt, but does not change
# tags by their text-aequivalent. So, html2txt
# would be overestimating it's functionality.
# ------------------------------------------
parsername "dumptext": ( )
start
dump_data;
end
# ------------------------------------------
# same as dumptext, but with html-decode
# ------------------------------------------
parsername "dumptext2": ( )
start
htmldecode;
dump_data;
end
# show video-files
parsername "videonames": ( )
start
match( "(.*mp4)|(.*flv)|(.*swf)|(.*mpg)|(.*m4v)|(.*mp4)|(.*rtmp)|(.*f4v)|(.*3gp)|(.*mkv)" );
uniq;
print;
end
# show video-files
parsername "videolinks": ( )
start
tagselect( "a"."href" | argpairs );
grep("mkv"); # here match on all filenames would be needed
#match( "(.*mp4)|(.*flv)|(.*swf)|(.*mpg)|(.*m4v)|(.*mp4)|(.*rtmp)|(.*f4v)|(.*3gp)|(.*mkv)" );
print;
#match( "(.*mp4)|(.*flv)|(.*swf)|(.*mpg)|(.*m4v)|(.*mp4)|(.*rtmp)|(.*f4v)|(.*3gp)|(.*mkv)" );
uniq;
print;
end
# downloading picture-files
parsername "pics": ( )
start
linkextract;
print;
grep("((\.jpg)|(\.jpeg)|(\.gif)|(\.png)|(\.svg)|(\.pnm)|(\.ppm)|(\.pgm)|(\.pbm))$");
uniq;
print( " ======================================================================== ");
print;
show_type;
download; # directly writing files to disk
end
# downloads the img-src
# ---------------------
parsername "get-img-src": ( )
start
tagselect( "img" | arg("src") );
rebase;
makeurl;
download;
end
# get pdf-docs
# ------------
parsername "pdfs": ( )
start
#match( >>>"(http[^"]+\.pdf)<<< );
linkextract;
grep( >>>(.*?\.pdf)<<< );
uniq;
print;
to_matchres;
dropcol(1); # referrer removed!
show_match;
makeurl;
show_type;
print;
download; # directly writing files to disk
end
# =================================
# mp3-files matched and downloaed =
# =================================
parsername "mp3": ( )
start
linkextract;
grep("\.mp3");
makeurl;
download;
end
# ------------------------
# Show all script-sources
# ------------------------
# ( shows js-file-urls )
# ------------------------
parsername "script-src": ( )
start
tagselect( "script" | arg( "src" ) );
rebase;
show_match;
#exitparse;
makeurl;
download; # directly writing files to disk
end
# ------------------------
# Download all source-src
# ------------------------
parsername "source-src": ( )
start
tagselect( "source" | arg( "src" ) );
rebase;
show_match;
makeurl;
download; # directly writing files to disk
end
# ------------------------
# Show all meta-tags
# ------------------------
parsername "show-meta": ( )
start
tagselect( "meta" | dump );
end
# ------------------------
# Save all meta-tags
# ------------------------
parsername "save-meta": ( )
start
tagselect( "meta" | htmlstring );
to_string;
store("META");
paste($STARTURL);
subst("[[:^alnum:]]+", "_"); # non-alnum -> "_"
store("BASENAME");
paste($BASENAME, ".meta");
store("FILENAME");
recall("META");
save_as( $FILENAME );
end
# ---------------------------------------------
# Show all name-attributes of meta-tags
# ---------------------------------------------
# This can be used to extract all meta-names
# from a webpage, for example to easier create
# scraperJSON-Files (ContentMine).
# ---------------------------------------------
parsername "show-meta-names": ( )
start
tagselect( "meta"."name" | arg("name") );
transpose; uniq; transpose;
sort;
print("Meta-Tags (alphabetically sorted) from site ", $STARTURL, "\n");
show_match;
end
# ---------------------------------------------
# show all argkey-combinations of meta-tags
# ---------------------------------------------
parsername "show-meta-argkeys": ( )
start
tagselect( "meta"."name" | argkeys );
uniq;
sort;
print("Meta-Tag argkey-combinations: (alphabetically sorted) from site ", $STARTURL, "\n");
show_match;
end
# --------------------------------------------------------------
# This parser creates the output for a Gnome-Desktop-File.
# --------------------------------------------------------------
# (what you get on your desktop, when you drag&drop
# the URL-line from your browser (e.g. firefox) to
# the desktop
# --------------------------------------------------------------
# Does create the output and prints it to stdout; does not
# directly create the file.
# --------------------------------------------------------------
parsername "desktop": ()
start
print( "[Desktop Entry]" );
print( "Encoding=UTF-8" );
titleextract;
store("title");
print("Name=", $title);
print("Type=Link");
print("URL=", $STARTURL);
print("Icon=gnome-fs-bookmark");
end
parsername "desktop2": ()
start
print( "[Desktop Entry]" );
print( "Encoding=UTF-8" );
titleextract;
print;
htmldecode;
print;
store("title");
print("Name=", $title);
print("Type=Link");
print("URL=", $STARTURL);
print("Icon=gnome-fs-bookmark");
end
# ----------------------------------------------------
# parser for testing cookies
# ----------------------------------------------------
# Some tests of cookies can be found here:
# http://winware.org/de/cookietest.php
#
# Used testpage for setting/reflecting a cookie:
# http://winware.org/de/cookietest.php?cookie=set
# ----------------------------------------------------
parsername "cookieecho": ( )
start
call("cookieecho");
end
# ---------------------------------------------
# parser for testing cookies, using a testpage,
# so enforcing cookies to be set.
# the URL on the command line will be ignored!
# ---------------------------------------------
parsername "cookieecho-forced": ( )
start
print("The URL provided via command line will be ignored.");
print("The test-url http://winware.org/de/cookietest.php?cookie=set will be used instead!\n");
paste("http://winware.org/de/cookietest.php?cookie=set"); # use this test-url to check the COOKIE-functionality!
makeurl;
store("STARTURL");
get; # use this test-url (INSTEAD of the one given by to check the COOKIE-functionality!
call("cookieecho");
end
# ----------------------------------------------------
# ----------------------------------------------------
# ----------------------------------------------------
parsername "cookietest": ( "http://winware.org/de/cookietest.php" )
start
# the rreceived cookies will not be sent back - hence no effect
# -------------------------------------------------------------
get("http://winware.org/de/cookietest.php");
get("http://winware.org/de/cookietest.php?cookie=set");
get("http://winware.org/de/cookietest.php");
get("http://winware.org/de/cookietest.php?cookie=set");
# now with using cookies (by copying the cookies from RECEIVED to SEND):
# ----------------------------------------------------------------------
recall("COOKIES.RECEIVED");
store("COOKIES.SEND");
get("http://winware.org/de/cookietest.php?cookie=set");
end
# ==============================================
# Parser-Definitions for the Mediathek-Parsers #
# ==============================================
# ------------------------------------------------------
# Extract OSR Shownotes, and write them to csv-file;
# and download the audio-file.
# with -i switch, the audio-file-type can be selected.
# ------------------------------------------------------
parsername "OSR-shownotes-2-csv": ( "https://www.openscienceradio.org/" )
start
# extract title, for usage as part of the filename
call("_extract-and-store-title_");
recall("BASEDOC");
# html.body.div.div.div.div.article.div.div.p.a.target
tagselect("article", "div", "div", "p", "a" | arg("title"), arg("href") );
transpose;
# Html-decode first, then remove semicolons left over
# ----------------------------------------------------
htmldecode; # html-encoded stuff to UTF-8
subst(";", " -"); # remove semicolon, because of CSV-saving later on !!
subst(" - \(link\)", ""); # remove unnecessary stuff
#print;
show_match;
csv_save; # SAVING the show-notes as csv-file.
# extract the AUDIO-urls
# ----------------------
recall("BASEDOC");
tagselect("meta"."property"="og:audio" | arg("content") );
transpose;
# downloading the AUDIO-file now, and print some messages to the user.
# --------------------------------------------------------------------
iselectmatch(0, "http", "mp3");
makeurl;
print_string("\n\n-------------------------------------\n");
print_string("Start downloading the audio-file now.\nURL: ");
print;
print("...please be patient.");
download;
print("done.");
print_string("-------------------------------------\n");
end
# ---------------------------------
# Resonator
# ---------------------------------
# Downloads mp3 by default.
# With -i switch on command line,
# the user can select preferred audio file.
# ------------------------------------------
parsername "resonator": ( "https://resonator-podcast.de", "http://resonator-podcast.de" )
start
# extract the audio-urls
# ----------------------
tagselect("meta"."property"="og:audio" | arg("content") );
transpose;
#show_match;
iselectmatch(0, "RES", "mp3");
# download and save
# -----------------
makeurl;
download; # directly writing files to disk
end
# ---------------------------------
# ARD
# ---------------------------------
# Example: https://www.ardmediathek.de/video/charite/folge-1-barmherzigkeit-s01-e01/mdr-fernsehen/Y3JpZDovL21kci5kZS9zZW5kdW5nLzI4MjA0MS8yMDI0MDIwNjAwMzUvbWRycGx1cy1zZW5kdW5nLTgwNjI
# =================================
parsername "ard_mediathek_get": ("https://www.ardmediathek.de" )
start
call("_extract-and-store-title_");
recall("BASEDOC");
tagselect("meta"."property"="contentUrl" | arg("content") );
makeurl;
download($title, ".mp4");
end
# ------------------------------------
# Wrapper-Parser for youtube and vimeo
# ====================================
parsername "youtube-and-vimeo": ( "https://www.youtube.com/", "https://vimeo.com/" )
start
paste(" yt-dlp ", $STARTURL );
system;
end
# =================================
# working, but too simple, you could use wget instead ;-) It's just for testing purposes
parsername "save": ( )
start
save; # save original document
linkextract; # grab links from the document
print; # print links/referers
get; # get all documents, to which the extracted documents are linking
save; # save all the retrieved documents, that wre elinked to via the main page
end
# =================================
# youtube Info
# =================================
# For a youtube-link directly to a
# video, print title, date and url.
# ---------------------------------
parsername "ytinfo": ( )
start
# Title
#recall("BASEDOC");
tagselect("meta"."property"="og:title" | arg("content"));
htmldecode;
to_string;
print;
# Date
recall("BASEDOC");
tagselect("meta"."itemprop"="datePublished" | arg("content") );
subst("T.*", ""); # remove time, only date needed (better readable without time)
store("datePublished");
print(" - ", $datePublished, " -");
# Video URL
print($STARTURL);
end
#
# vimscript-Function to insert the result of the ytinfo-parser into your current vim buffer:
#
#:function Youtubeinfo()
#: call inputsave()
#: let url = input(' Enter youtube-URL: ')
#: call inputrestore()
#: execute "r! any-dl -p ytinfo -sep=\"\" " . url
#:endfunction
# =====================================================
# M A C R O S
# =====================================================
# =========================================================
# Extract title-tag and suvstitute non-alnum chars by "-" =
# and store the result in variable "title".
# =========================================================
defmacro "_extract-and-store-title_":
start
titleextract;
subst("[[:^alnum:]]+", "_"); # non-alnum -> "_"
store("title");
end
defmacro "_extract-and-store-title-htmldecode_":
start
titleextract;
htmldecode;
subst("[[:^alnum:]]+", "_"); # non-alnum -> "_"
store("title");
end
# ----------------------------------------------------
# Macro for testing cookies
# ----------------------------------------------------
# Some tests of cookies can be found here:
# http://winware.org/de/cookietest.php
#
# Used testpage for setting/reflecting a cookie:
# http://winware.org/de/cookietest.php?cookie=set
# ----------------------------------------------------
defmacro "cookieecho":
start
print("COOKIES.RECEIVED:\n", $COOKIES.RECEIVED );
print("Preparing cookies for get");
recall("COOKIES.RECEIVED");
store("COOKIES.SEND");
recall("STARTURL");
print;
get;
print("COOKIES.SEND:\n", $COOKIES.SEND );
print("COOKIES.RECEIVED:\n", $COOKIES.RECEIVED );
print("Preparing cookies for second get");
recall("COOKIES.RECEIVED");
store("COOKIES.SEND");
recall("STARTURL");
print;
get;
print("COOKIES.SEND:\n", $COOKIES.SEND );
print("COOKIES.RECEIVED:\n", $COOKIES.RECEIVED );
end
# -------------------------------------------------
# All fields of an <input> are listed (as columns)
# -------------------------------------------------
# Col 0, Col 2, Col 4, ... are fieldnames,
# Col 1, Col 3, Col 5, ... are fieldvalues
# -------------------------------------------------
# use case: analyze page for setting up POST call
# -------------------------------------------------
parsername "showinput": ()
start
tagselect( "input" | argpairs );
show_match;
end
# show form's arg-pairs
# =====================
defmacro "showforms":
start
tagselect("form" | argpairs);
print;
end
# show input's arg-pairs
# ======================
defmacro "showinputs":
start
tagselect("input" | argpairs);
print;
end