From a0076fbdb41c2da200b51c769b28c1fa4bd2c555 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu>
Date: Wed, 23 Jan 2019 16:17:58 +0100
Subject: [PATCH] do not reupload video files, refs #26945

---
 .../3.Deploy_demokit/publish_zip_by_url.py        | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/5.MediaServer/3.Deploy_demokit/publish_zip_by_url.py b/5.MediaServer/3.Deploy_demokit/publish_zip_by_url.py
index 092ebb02..afded968 100755
--- a/5.MediaServer/3.Deploy_demokit/publish_zip_by_url.py
+++ b/5.MediaServer/3.Deploy_demokit/publish_zip_by_url.py
@@ -60,11 +60,16 @@ if __name__ == '__main__':
     # ping
     print(msc.api('/', method='get'))
 
-    with open('/tmp/file.zip', 'wb') as f:
-        f.write(requests.get(args.url).content)
-        # add media with a zip
-        #print(msc.add_media('Test multichunk upload zip', file_path='/tmp/file.zip'))
-        print(msc.add_media(file_path='/tmp/file.zip'))
+    basename = os.path.basename(args.url)
+    r = msc.api('/search', method='get', data={'search': basename})
+    if r.get('videos'):
+        print('Video %s seems to be already present on the portal, not reuploading' % basename)
+    else:
+        with open('/tmp/file.zip', 'wb') as f:
+            f.write(requests.get(args.url).content)
+            # add media with a zip
+            #print(msc.add_media('Test multichunk upload zip', file_path='/tmp/file.zip'))
+            print(msc.add_media(file_path='/tmp/file.zip'))
 
     # add user
     # print(msc.api('users/add/', method='post', data={'email': 'test@test.com'}))
-- 
GitLab