Skip to content

Instantly share code, notes, and snippets.

@AliLozano
Created May 9, 2022 04:38
Show Gist options
  • Save AliLozano/1e3de7942b17a365542e2427577e6c67 to your computer and use it in GitHub Desktop.
Save AliLozano/1e3de7942b17a365542e2427577e6c67 to your computer and use it in GitHub Desktop.
Panopto Downloader.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Panopto Downloader.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyPPNAntQW4ZpvO6B+lkH07v",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/AliLozano/1e3de7942b17a365542e2427577e6c67/panopto-downloader.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "3qlOegqf-tPP",
"outputId": "efed9871-43aa-406f-9374-940767ab3c9c"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (2.23.0)\n",
"Requirement already satisfied: oauthlib in /usr/local/lib/python3.7/dist-packages (3.2.0)\n",
"Requirement already satisfied: requests_oauthlib in /usr/local/lib/python3.7/dist-packages (1.3.1)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests) (2021.10.8)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests) (2.10)\n",
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests) (1.24.3)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests) (3.0.4)\n"
]
}
],
"source": [
"!pip install requests oauthlib requests_oauthlib"
]
},
{
"cell_type": "markdown",
"source": [
"Constants"
],
"metadata": {
"id": "TWv32-6xEgI6"
}
},
{
"cell_type": "code",
"source": [
"import requests\n",
"\n",
"panopto_domain = 'https://loremipsum.hosted.panopto.com'\n",
"\n",
"cookies = {\n",
" '.ASPXAUTH': '-extract this from the session-',\n",
" 'csrfToken': '-extract this from the session-',\n",
"}\n",
"\n",
"headers = {\n",
" 'content-type': 'application/json; charset=UTF-8',\n",
" 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36',\n",
"}"
],
"metadata": {
"id": "-JgvKDw7_oPl"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def get_folder(folder_id):\n",
" \"\"\" Returns a tuple with subfolders and session videos.\n",
" \"\"\"\n",
" json_data = {\n",
" 'queryParameters': {\n",
" 'query': None,\n",
" 'sortColumn': 1,\n",
" 'sortAscending': False,\n",
" 'maxResults': 100,\n",
" 'page': 0,\n",
" 'startDate': None,\n",
" 'endDate': None,\n",
" 'folderID': folder_id,\n",
" 'bookmarked': False,\n",
" 'getFolderData': True,\n",
" 'isSharedWithMe': False,\n",
" 'isSubscriptionsPage': False,\n",
" 'includeArchived': False,\n",
" 'includePlaylists': True,\n",
" },\n",
" }\n",
"\n",
" response = requests.post(panopto_domain + '/Panopto/Services/Data.svc/GetSessions', cookies=cookies, headers=headers, json=json_data)\n",
"\n",
" return response.json()['d']['Subfolders'], response.json()['d']['Results']"
],
"metadata": {
"id": "vbbkkXqPODY8"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"get_folder('--insert id of the folder -- ') # this can be extracted from the url. "
],
"metadata": {
"id": "hsiA87uxAK3X"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import time\n",
"\n",
"\n",
"def get_childs(folder):\n",
" \"\"\" Extract a json with download links and titles\"\"\"\n",
" time.sleep(0.5)\n",
" childs, videos = get_folder(folder)\n",
" videos_result = [ dict(id=v['SessionID'], name=v['SessionName'], url=v['IosVideoUrl']) for v in videos ]\n",
"\n",
" childs_result = []\n",
" for child in childs:\n",
" item = dict(\n",
" id=child['ID'], \n",
" name=child['Name'], \n",
" data=get_childs(child['ID']))\n",
" \n",
" childs_result.append(item)\n",
" \n",
" \n",
" data = dict(id=folder, childs=childs_result, videos=videos_result)\n",
"\n",
" return data\n",
" \n"
],
"metadata": {
"id": "WgxwZ4Q-P752"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"START_FOLDER = '-- get a folder id from the url of your shared folders ---'\n",
"\n",
"data = get_childs(START_FOLDER) # this returns a json with download links and names. "
],
"metadata": {
"id": "7B7C-OZjSuEi"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
""
],
"metadata": {
"id": "Or8SjYrqUOrn"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import json \n",
"with open('data.json', 'w') as f:\n",
" json.dump(data, f) # save it."
],
"metadata": {
"id": "KvPmxSgeYvq7"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def videos_to_url(videos):\n",
" return [v['name'] for v in videos]\n",
"def get_videos(item):\n",
" \"\"\" Get video links for a donload manager like jdownloader\"\"\"\n",
" v = videos_to_url(item['videos'])\n",
" videos = [v for it in item['childs'] for v in get_videos(it['childs'])]\n",
" return v + videos"
],
"metadata": {
"id": "WXUVPwtZzvif"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"for i in get_videos(data):\n",
" print(i) # print links to paste it in a jdownloader, I have to download a lot of videos, then I prefer to don't do it with the python. "
],
"metadata": {
"id": "efd22rjj1_Ic"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# after this, you can create a script to download and rename files or something like that. "
],
"metadata": {
"id": "DPUQilSB2AGm"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment