I think I have done something like that before. What I did was make it so each code block would be written out to a file, e.g. course-notes/script-%d.py and a link would be put in the exported pdf right after that block. I do not know how you could get the captions though.
In the header I have this:
#+LATEX_HEADER: \newcommand{\LaunchBinary}[2]{%
#+LATEX_HEADER: % #1: layer name,
#+LATEX_HEADER: % #2: link text
#+LATEX_HEADER: \leavevmode%
#+LATEX_HEADER: \pdfstartlink attr{/C [0.9 0 0] /Border [0 0 2]} user {
#+LATEX_HEADER: /Subtype /Link
#+LATEX_HEADER: /A <<
#+LATEX_HEADER: /F <<
#+LATEX_HEADER: /DOS (#1)
#+LATEX_HEADER: /Mac (#1)
#+LATEX_HEADER: /Unix (#1)
#+LATEX_HEADER: >>
#+LATEX_HEADER: /S /Launch
#+LATEX_HEADER: >>
#+LATEX_HEADER: } #2%
#+LATEX_HEADER: \pdfendlink%
#+LATEX_HEADER: }
Then this code for the export. (I pasted it from my build file, so there may be an extra parenthesis at the end)
(setq counter 0)
(defun ox-mrkup-filter-src-block (text back-end info)
(setq counter (+ counter 1))
(let ((filename (format "course-notes-scripts/script-%d.py" counter)))
(with-temp-buffer
(insert (mapconcat 'identity (butlast (cdr (split-string text "\n" t))) "\n"))
(write-region (point-min) (point-max) filename))
(format "%s
\\LaunchBinary{%s}{Open the python script (%s).}
" text filename filename)))
(let ((org-export-filter-src-block-functions '(ox-mrkup-filter-src-block)))
(org-latex-export-to-latex async subtreep visible-only body-only
'(:with-author t
:with-date t
:with-title t
:with-timestamps t
:with-todo-keywords t
:with-toc nil))))
maybe that is close to what you want?