def get_sessions(folder_id): url = 'https://scs.hosted.panopto.com/Panopto/PublicAPI/4.1/ListSessions'\ + '?FolderId=%s' % folder_id req = urlopen(url) res = json.loads(req.read()) video_list = [(e['Id'], valid_name('%s.mp4' % e['Name'])) for e in res['Results']] return video_list if __name__ == '__main__': all_flag = read_args(argv) video_list = get_sessions(CSAPP_FOLDER_ID) idx = 0 if all_flag: for uuid, filename in video_list: try: fetch_video(filename, uuid) except HTTPError: stderr.write('Error: fail to download %s\n' % filename) exit(0) for idx, (uuid, filename) in enumerate(video_list): print '%d) %s' % (idx, filename) indices = raw_input('Please input the indices of the video to download (separate by space): ') for idx in indices.split(): uuid, filename = video_list[int(idx)] fetch_video(filename, uuid)
def usage(): print 'Usage: %s [-a]' % argv[0] def get_sessions(folder_id): url = 'https://scs.hosted.panopto.com/Panopto/PublicAPI/4.1/ListSessions'\ + '?FolderId=%s' % folder_id print "Fetching video list, please wait..." req = urlopen(url) res = json.loads(req.read()) video_list = [(e['Id'], '%s.mp4' % e['Name']) for e in res['Results']] return video_list if __name__ == '__main__': all_flag = read_args(argv) video_list = get_sessions(CSAPP_FOLDER_ID) idx = 0 if all_flag: for video in video_list: try: fetch_video(video[1], video[0]) except HTTPError: stderr.write('Error: fail to download %s\n' % video[1]) exit(0) for idx in xrange(len(video_list)): print '%d) %s' % (idx, video_list[idx][1]) idx = input('Please input the index of the video to download: ') video = video_list[idx] fetch_video(video[1], video[0])