From c7c771e34e5f9e27ab591f09bb93c32135fd0cd1 Mon Sep 17 00:00:00 2001
From: Julien Marchal <julien.marchal@univ-lorraine.fr>
Date: Tue, 4 Mar 2025 13:58:34 +0000
Subject: [PATCH] add getVideosMp4.py and requirements.txt for pip install

---
 README           | 11 +++++++---
 getVideosMp4.py  | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
 requirements.txt |  2 ++
 3 files changed, 64 insertions(+), 3 deletions(-)
 create mode 100644 getVideosMp4.py
 create mode 100644 requirements.txt

diff --git a/README b/README
index 8b369ed..f875ad5 100644
--- a/README
+++ b/README
@@ -1,12 +1,17 @@
 python3 -m venv .venv
 source .venv/bin/activate
 
-pip install requests
-pip install requests_toolbelt
+pip install -r requirements.txt
 
 rename and adapt config.sample.py to config.py
 rename and adapt usersList.sample.csv to usersList.csv
 rename and adapt videosList.sample.csv to videosList.csv
 
+# Create list of user from csv
 python3 createUsers.py usersList.csv
-python3 putVideos.py videosList.csv
\ No newline at end of file
+
+# Upload videos from csv
+python3 putVideos.py videosList.csv
+
+# get best definition of mp4 video for all videos
+python3 getVideosMp4.py
\ No newline at end of file
diff --git a/getVideosMp4.py b/getVideosMp4.py
new file mode 100644
index 0000000..7501134
--- /dev/null
+++ b/getVideosMp4.py
@@ -0,0 +1,54 @@
+import requests
+import sys
+import json
+import os
+
+import config
+
+headers_json={
+    'Content-Type':'application/json',
+    'Authorization': 'Token {}'.format(config.POD_TOKEN)
+}
+
+payload_search_videos={
+    
+}
+
+hasNext = True
+url_to_fetch=config.POD_API_UPLOAD_VIDEO
+while(hasNext):  
+    response = requests.get(url_to_fetch, headers=headers_json, params=payload_search_videos)
+    if(response.status_code != 200):
+        print("ERROR get [%s] : [CODE:%s]" % (url_to_fetch,response.status_code))
+    else:
+        result = json.loads(response.content.decode("utf-8"))
+        if(result['count'] == 0):                    
+            print("Videos not found")
+        else:
+            for video in result['results']:
+                id=video['id']
+                slug=video['slug']
+                mp4_orig_url=video['video']
+                mp4_orig_url_start='/'.join(mp4_orig_url.split('/')[:-1])
+
+                found_mp4 = False
+                for definition in ('1080p', '720p', '360p'):
+                    mp4_url='/'.join((mp4_orig_url_start,f'{id:04}',('%s.mp4' % definition)))
+                    r = requests.head(mp4_url)
+                    if(r.status_code == 200):
+                        found_mp4 = True
+                        print("[ID:%s] [SLUG:%s] [URL:%s]" % (id, slug, mp4_url))
+                        break
+                if(not found_mp4):
+                    print("[ID:%s] [SLUG:%s] [URL:no mp4 found]" % (id,slug))
+                
+            if(result['next']):
+                hasNext=True
+                url_to_fetch=result['next']
+                print("next page : %s" % url_to_fetch)                
+            else:
+                print("no next page")
+                hasNext=False
+            
+
+        
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..8550bb5
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+requests
+requests_toolbelt
\ No newline at end of file
-- 
GitLab