Created
February 4, 2016 06:38
-
-
Save izmailoff/c36f7ff6a344ce321ae8 to your computer and use it in GitHub Desktop.
Generates unix commands (wget, youtube-dl) to download files based on the links found on a web page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala "$0" "$@" | |
!# | |
import scala.io.Source | |
val url = "https://work.caltech.edu/lectures.html" | |
val html = Source fromURL(url) mkString | |
val href = """<a href="\s*(.+?)\s*">""".r | |
val links = (for (m <- href findAllMatchIn html) yield m group 1) toList | |
val slides = links filter (_ endsWith "pdf") toSet | |
val videos = links filter (_ contains "youtube.com") map { _.takeWhile (_ != '#') } toSet | |
slides foreach { x => println(s"wget '$x'") } | |
videos foreach { x => println(s"youtube-dl '$x'") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prints something like this: