]> gitweb.factorcode.org Git - factor.git/commitdiff
youtube: throw an error if the given youtube video isn't downloadable
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 23 Jun 2016 00:14:37 +0000 (02:14 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Thu, 23 Jun 2016 00:20:25 +0000 (02:20 +0200)
well it is, but you have to go through lots of hops to download "secure"
videos

extra/youtube/youtube.factor

index 32c69988631d78a3d8d431c7e165f11d00c996f2..5c6e7e9c3a9c89661cf3594c1a61e723ea3c941e 100644 (file)
@@ -47,7 +47,6 @@ CONSTANT: video-info-url URL" http://www.youtube.com/get_video_info"
 : get-video-info ( video-id -- video-info )
     video-info-url clone
         3 "asv" set-query-param
-        "detailpage" "el" set-query-param
         "en_US" "hl" set-query-param
         swap "video_id" set-query-param
     http-get nip query>assoc ;
@@ -64,10 +63,15 @@ CONSTANT: video-info-url URL" http://www.youtube.com/get_video_info"
     [ "\"#$%'*,./:;<>?^|~\\" member? ] reject
     200 short head ;
 
+: downloadable? ( video-info -- ? )
+    "use_cipher_signature" of "False" = ;
+
 : download-video ( video-id -- )
     get-video-info [
+        downloadable? [ "Video is encrypted." throw ] unless
+    ] [
         video-formats [ "type" of "video/mp4" head? ] find nip
         video-download-url
     ] [
         "title" of sanitize ".mp4" append download-to
-    ] bi ;
+    ] tri ;