]> code.delx.au - webdl/blobdiff - brightcove.py
Return false instead of throwing exception when missing HLS stream
[webdl] / brightcove.py
index 9d054d62a141bc3e3b5a4977164e0bae3535741a..7bb57372572840fdb7173288b7a7177370f22d80 100644 (file)
@@ -1,13 +1,12 @@
 import re
 import sys
 
-from common import grab_json, download_rtmp, Node, append_to_qs
+from common import grab_json, download_hls, Node, append_to_qs
 
 CH9_TOKEN = "ogxhPgSphIVa2hhxbi9oqtYwtg032io4B4-ImwddYliFWHqS0UfMEw.."
 CH10_TOKEN = "lWCaZyhokufjqe7H4TLpXwHSTnNXtqHxyMvoNOsmYA_GRaZ4zcwysw.."
 
 BRIGHTCOVE_API = "http://api.brightcove.com/services/library?"
-HASH_URL = "http://admin.brightcove.com/viewer/us20130530.1140/connection/ExternalConnection_2.swf"
 
 
 class BrightcoveVideoNode(Node):
@@ -21,28 +20,17 @@ class BrightcoveVideoNode(Node):
         desc_url = append_to_qs(BRIGHTCOVE_API, {
             "token": self.token,
             "command": "find_video_by_id",
-            "video_fields": "renditions",
+            "video_fields": "HLSURL",
             "video_id": self.video_id,
         })
-        print "video desc_url", desc_url
-
         doc = grab_json(desc_url, 3600)
+        video_url = doc["HLSURL"]
+        if not video_url:
+            print("No HLS stream available for: " + self.title)
+            return False
 
-        best_encoding_rate = 0
-        best_url = None
-        for item in doc['renditions']:
-            encoding_rate = item['encodingRate']
-            if encoding_rate > best_encoding_rate:
-                best_encoding_rate = encoding_rate
-                best_url = item['url']
-
-        if best_url is None:
-            raise Exception("Could not find video URL: " + desc_url)
-
-        vbase, vpath = best_url.split("&")
-        filename = self.title + ".mp4"
-        return download_rtmp(filename, vbase, vpath, HASH_URL)
-
+        filename = self.title + ".ts"
+        return download_hls(filename, video_url)
 
 class BrightcoveRootNode(Node):
     def __init__(self, title, parent, token):