|
34 | 34 | "<p align='center'><img src='https://github.com/NeuromatchAcademy/widgets/blob/master/sponsors.png?raw=True'/></p>" |
35 | 35 | ] |
36 | 36 | }, |
37 | | - { |
38 | | - "cell_type": "markdown", |
39 | | - "metadata": { |
40 | | - "execution": {}, |
41 | | - "pycharm": { |
42 | | - "name": "#%% md\n" |
43 | | - } |
44 | | - }, |
45 | | - "source": [ |
46 | | - "## Orientation Video" |
47 | | - ] |
48 | | - }, |
49 | | - { |
50 | | - "cell_type": "code", |
51 | | - "execution_count": null, |
52 | | - "metadata": { |
53 | | - "cellView": "form", |
54 | | - "execution": {}, |
55 | | - "pycharm": { |
56 | | - "name": "#%%\n" |
57 | | - } |
58 | | - }, |
59 | | - "outputs": [], |
60 | | - "source": [ |
61 | | - "# @markdown\n", |
62 | | - "from ipywidgets import widgets\n", |
63 | | - "from IPython.display import YouTubeVideo\n", |
64 | | - "from IPython.display import IFrame\n", |
65 | | - "from IPython.display import display\n", |
66 | | - "\n", |
67 | | - "\n", |
68 | | - "class PlayVideo(IFrame):\n", |
69 | | - " def __init__(self, id, source, page=1, width=400, height=300, **kwargs):\n", |
70 | | - " self.id = id\n", |
71 | | - " if source == 'Bilibili':\n", |
72 | | - " src = f'https://player.bilibili.com/player.html?bvid={id}&page={page}'\n", |
73 | | - " elif source == 'Osf':\n", |
74 | | - " src = f'https://mfr.ca-1.osf.io/render?url=https://osf.io/download/{id}/?direct%26mode=render'\n", |
75 | | - " super(PlayVideo, self).__init__(src, width, height, **kwargs)\n", |
76 | | - "\n", |
77 | | - "\n", |
78 | | - "def display_videos(video_ids, W=400, H=300, fs=1):\n", |
79 | | - " tab_contents = []\n", |
80 | | - " for i, video_id in enumerate(video_ids):\n", |
81 | | - " out = widgets.Output()\n", |
82 | | - " with out:\n", |
83 | | - " if video_ids[i][0] == 'Youtube':\n", |
84 | | - " video = YouTubeVideo(id=video_ids[i][1], width=W,\n", |
85 | | - " height=H, fs=fs, rel=0)\n", |
86 | | - " print(f'Video available at https://youtube.com/watch?v={video.id}')\n", |
87 | | - " else:\n", |
88 | | - " video = PlayVideo(id=video_ids[i][1], source=video_ids[i][0], width=W,\n", |
89 | | - " height=H, fs=fs, autoplay=False)\n", |
90 | | - " if video_ids[i][0] == 'Bilibili':\n", |
91 | | - " print(f'Video available at https://www.bilibili.com/video/{video.id}')\n", |
92 | | - " elif video_ids[i][0] == 'Osf':\n", |
93 | | - " print(f'Video available at https://osf.io/{video.id}')\n", |
94 | | - " display(video)\n", |
95 | | - " tab_contents.append(out)\n", |
96 | | - " return tab_contents\n", |
97 | | - "\n", |
98 | | - "\n", |
99 | | - "video_ids = [('Youtube', 'FwjyhCLeqx0'), ('Bilibili', 'BV1QE421P7EJ')]\n", |
100 | | - "tab_contents = display_videos(video_ids, W=854, H=480)\n", |
101 | | - "tabs = widgets.Tab()\n", |
102 | | - "tabs.children = tab_contents\n", |
103 | | - "for i in range(len(tab_contents)):\n", |
104 | | - " tabs.set_title(i, video_ids[i][0])\n", |
105 | | - "display(tabs)" |
106 | | - ] |
107 | | - }, |
108 | 37 | { |
109 | 38 | "cell_type": "markdown", |
110 | 39 | "metadata": { |
|
207 | 136 | "name": "python", |
208 | 137 | "nbconvert_exporter": "python", |
209 | 138 | "pygments_lexer": "ipython3", |
210 | | - "version": "3.9.19" |
| 139 | + "version": "3.9.22" |
211 | 140 | } |
212 | 141 | }, |
213 | 142 | "nbformat": 4, |
|
0 commit comments