Welcome to the Panopto Community

Please note: All new registrants to the Panopto Community Forum must be approved by a forum moderator or admin. As such, if you navigate to a feature that is members-only, you may receive an error page if your registration has not yet been approved. We apologize for any inconvenience and are approving new members as quickly as possible.

Is it possible to iterate all the video sessions from the site using API?

Hi,

I'm tring to download all the captions from all the videos on my site, and so I'm using Session API which can return me the caption download url.

However, the Session API requires me to specify the session id, and so I have to manually click into each video to grab the session id. And btw, is this the correct way to get the caption file?

Best

Tagged:

Best Answers

  • Answer ✓

    Hi Xun,

    There is API which can return list of sessions for a specific folder. This would speed up your work, since in that case you would not need to get session id for every session.

    That is our Folder API (https://demo.hosted.panopto.com/Panopto/api/docs/index.html#/Folders/Folders_GetSessions).

    That should be the correct way, since if captions are present on the session, you should see url to download captions.

    I hope this helps. Please let me know if you have any other questions.

    Thanks,

    Adis

  • Answer ✓

    Hi Xun,

    I have tried just now and I can see this caption being download into the following file.

    See my code sample below:

    from urllib import request
    # Define the remote file to retrieve
    remote_url = 'https://sph.hosted.panopto.com/Panopto/Pages/Transcription/GenerateSRT.ashx?id=c4c986d0-eb6d-4d2f-ab01-ae9f00f2aee9&language=English_USA'
    # Define the local filename to save data
    local_file = 'sph_caption.txt'
    # Download remote and save locally
    request.urlretrieve(remote_url, local_file)
    

    If you wish you can send me your piece of logic so I can check it.

    Thanks,

    Adis

Answers

  • Hi Adis,

    Thank you, it works! Another question is I'm trying to use Python and CaptionDownloadUrl to download the caption into json.

    A sample caption link will be like this (https://sph.hosted.panopto.com/Panopto/Pages/Transcription/GenerateSRT.ashx?id=c4c986d0-eb6d-4d2f-ab01-ae9f00f2aee9&language=English_USA)

    However, I have tried using requests library or urllib.request library, but both returns me an empty string. Therefore, I'm wondering if there is any other method that I can download the caption?

    Thank you!

    Xun

  • Thank you so much Adis! This code works for me!

  • Xun ZhouXun Zhou Tyro
    edited January 2023

    Hi Adis,

    There still seems to be some issues with the caption download url.

    I'm trying to apply your sample code on this caption url(https://sph.hosted.panopto.com/Panopto/Pages/Transcription/GenerateSRT.ashx?id=437f5f12-2777-41e9-96dc-af81014039e3&language=English_USA), and it just returns me an empty text file.

    And btw, since there are hundreds of root folders on my site. Besides moving all the folders to one folder, and retrieve that single folder, do you happen to know any api that can return me a root folder list?

    Best

  • Hi Xun,

    When you try in browser in URL it doesn't return anything, so I guess there is no captions there or we don't have access for this particular URL.

    For getting list of folders maybe you can try:

    https://demo.hosted.panopto.com/Panopto/Api/Docs/index.html#/Folders/Folders_GetChildFolders

    To get a list of all top level folders, use an empty GUID (00000000-0000-0000-0000-000000000000)

    I hope this helps. Please let me know if you have any other questions.

    Thanks,

    Adis

  • Hi Adis,

    You are right, and some caption urls need access token. Therefore, I write some code like this:

    requests_session = requests.Session()
    requests_session.verify = False
    
    oauth2 = PanoptoOAuth2(server, client_id, client_secret, False)
    authorization(requests_session, oauth2)
    
    resp = requests_session.get(url = url)
    if inspect_response_is_unauthorized(resp):
        # Re-authorization
        authorization(requests_session, oauth2)
        # data = resp.json()
        data = resp.text # parse JSON format response
    else:
        data = resp.text
    

    I'm using this code to call the api, and it succeed. However when I replace the api url with caption url, it still returns me empty string. And on the other hand, I can see the caption in Chrome where I'm using my notebook in Chrome.

  • Xun ZhouXun Zhou Tyro
    edited January 2023

    I also tried the following code which is to add the access_token to the header of the request, but it still returns me an empty file

    import urllib.request
    
    
    local_file = 'sph_caption_test.txt'
    
    
    opener = urllib.request.build_opener()
    opener.addheaders = [('Authorization', 'Bearer ' + access_token)]
    urllib.request.install_opener(opener)
    urllib.request.urlretrieve(url, local_file)
    
  • Hi Xun,

    I believe I've answered your question in the post you created.

    I hope this helps. Please let me know if you have any other questions.

    Thanks,

    Asher Finkel

Sign In or Register to comment.