-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCollab.py
147 lines (113 loc) · 5.82 KB
/
Collab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
'''
Copyright (C) 2016, Blackboard Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of Blackboard Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY BLACKBOARD INC ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLACKBOARD INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Created on May 25, 2016
@author: shurrey
'''
import sys
import os
import getopt
import datetime
import uuid
import json
import urllib.request
import argparse
import ntpath # so we can grab the basename off the end of the full-file-path.
from panopto_oauth2 import PanoptoOAuth2
from panopto_uploader import PanoptoUploader
from video_link_creator import VideoLinkCreator
from upload_and_create_link import UploadAndCreateLink
import time
import urllib3
# Import Config
import Config
# Import Controllers
from controllers import AuthController
from controllers import UserController
from controllers import SessionController
from controllers import ContextController
# Import Models
from models import User
from models import Session
class Collab():
def __init__ (self):
self.URL = Config.adict['collab_base_url']
self.COLLAB_KEY = Config.adict['collab_key']
self.COLLAB_SECRET = Config.adict['collab_secret']
if Config.adict['verify_certs'] == 'True':
self.COLLAB_CERTS = True
else:
self.COLLAB_CERTS = False
self.authorized_session = None
def getToken(self):
self.authorized_session = AuthController.AuthController(self.URL, self.COLLAB_KEY, self.COLLAB_SECRET,self.COLLAB_CERTS)
self.authorized_session.setToken()
return(self.authorized_session.getToken())
def get_recordings(self, course_uuid, startTime):
sessions = SessionController.SessionController(self.URL, self.getToken(), self.COLLAB_CERTS)
recordings = sessions.get_recordings(course_uuid, startTime)
print (str(recordings))
return recordings
def get_recording_data(self,recording_id):
sessions = SessionController.SessionController(self.URL, self.getToken(), self.COLLAB_CERTS)
recordingid = sessions.get_recording_data(recording_id)
print(str(recordingid))
return recordingid
def getCourseName(self, course_uuid):
contexts = ContextController.ContextController(self.URL, self.getToken(), self.COLLAB_CERTS)
return(contexts.getContext(course_uuid))
#other functions for recordings
#Creating a list for recordings that need to be downloaded
def listrecordings(recordings):
recordinglist = []
x=0
try:
number_of_recordings = (len(recordings['results']))
if number_of_recordings <= 0:
return None
while x < number_of_recordings:
recordinglist.append({"recording_id" : recordings['results'][x]['id'], "recording_name" : recordings['results'][x]['name'] })
x += 1
print(str(recordinglist))
return recordinglist
except TypeError:
return None
#downloading the recordings
def downloadrecording(recording_list, name, course_uuid):
for recording in recording_list:
recording_data = collab_service.get_recording_data(recording['recording_id'])
print(str(recording_data))
print('**** Downloading recording with id ****' + recording['recording_id'])
filename = name + ' - ' + recording['recording_name'].replace(':', ' ').replace('/', ' ').replace('”', '').replace('“', '').replace(',', '').replace('?', '') + '.mp4'
fullpath = './downloads/'
print(fullpath + filename)
urllib.request.urlretrieve(recording_data['extStreams'][0]['streamUrl'], fullpath + filename)
upload_creator = UploadAndCreateLink()
upload_creator.upload_and_create_link(fullpath + filename, course_uuid)
if __name__ == "__main__":
collab_service = Collab()
course_uuids = [
'412e921ca89e4e069e1228a5f56d12d6',
'e3b0eab0374f431fb5e88abdccccff44',
'98025492016241b4a6162616e3f29bbe',
'5c02be9bfc6d4234a19513a80ae29867',
'60e296ce62984c4194fecf8c3aa9bda5'
]
start_time = datetime.datetime.now() - datetime.timedelta(hours = 24)
start_time = start_time.strftime('%Y-%m-%dT%H:%M:%SZ')
print(start_time)
for course_uuid in course_uuids:
print("uuid: " + course_uuid)
course_name = collab_service.getCourseName(course_uuid)
print("name: " + str(course_name))
sessions_json = collab_service.get_recordings(course_uuid, start_time)
recording_list= listrecordings(sessions_json)
if recording_list is None:
print("No recordings available for course: " + course_name)
else:
downloadrecording(recording_list, course_name, course_uuid)