a Legendre integral identity I was given the following problem.

For $n\ge2$ natural and $z\in\mathbf{C}\setminus[-1,1]$, prove the 
  Legendre identity
  $$\int_{-1}^{+1}\frac{(1-t^2)^{(n-3)/2}}{(z-t)^n}dt = \frac{\sqrt{\pi}\Gamma(\frac{n-1}{2})}{\Gamma(\frac{n}{2})}\frac{z}{(z^2-1)^{(n+1)/2}}.$$

I have come to multiple problems while tackling it. Also, I found nothing on the literature about it, and I am not even sure it is really related to Legendre in any matter.
My attempts. Residue integration does not seem to be the way to go, since the integration is not any contour at all, and completing it would seem to lead to further computational problems.
As far as induction on $n$ and integration by parts go, I have tried for $n$ odd.
If we call $n=2k+1$ and define the functions $a_\alpha, b_\beta, c_\gamma$ (with $A_\alpha$ the primitive of $a_\alpha$) by the following:


*

*$a_\alpha(t) = \frac{1}{(z-t)^\alpha} \Rightarrow A_\alpha(t) = \frac{1}{\alpha-1}\frac{1}{(z-t)^{\alpha - 1}},$

*$b_\beta(t) = (1-t^2)^\beta \Rightarrow  b'_\beta(t) = -2\beta \,t\, b_{\beta-1}(t) = -2\beta \, c_{\beta-1}(t),$

*$c_\gamma(t) = t(1-t^2)^\gamma \Rightarrow  c'_\gamma(t) = (1+2\gamma)b_\gamma(t) - 2\gamma b_{\gamma-1}(t).$


Then we must find $f(2k+1) = I(a_{2k+1} b_{k-1})$, where $I$ stands for the integration in $[-1,1]$. We would like to prove that $f(2k+3) = \frac{2k}{2k+1}\frac{f(2k+1)}{z^2-1}$, but parting from the left hand side and using integration by parts, one arrive at the formula
$ I(a_{2k+3}b_{k}) = \frac{1}{2k+2}a_{2k+2}b_k|_{-1}^{+1} + \frac{2k }{(2k+2)(2k+1)}a_{2k+1}c_{k-1}|_{-1}^{+1} -\frac{2k(2k-1)}{(2k+2)(2k+1)}I(a_{2k+1}b_{k-1}) + \frac{2k(2k-2)}{(2k+2)(2k+1)}I(a_{2k+1}b_{k-2}).  $
That is, we have the sum of some boundary terms that vanish if $k$ is big enough ($k>1, n>5$) a $f(n)=I(a_{2k+1}b_{k-1})$-term and a problematic $I(a_{2k-1}b_{k-2})$ term, which does not let me find any recurrence. Any further calculation sums up to a myriad of boundary terms and integrals, which seems not to lead anywhere good.
I have calculated the integrals for $n=3,5,7,9$ and they all agree to the given formula, with boundary terms and integrals magically conspiring to vanish the right polynomial terms. I did not even touch the case where $n$ is even.
Other guesses. Facts.
The integral can be expressed also as
$ f(n) = \int_0^{\pi} \frac{(\sin\theta)^{(n-2)/2}}{(z-\cos\theta)^n} d\theta$.
It also does bear some resemblance with Schläfli's integral formula for Legendre polynomials, given by
$$ P_n(z) = \frac{1}{2^n 2\pi i}\int_C \frac{(t^2-1)^n}{(t-z)^{n+1}}dt $$
where $C$ is a regular contour surrounding $z$ counterclockwise. But I don't think the same method applies here.
Thank you.
 A: Consider the Möbius transform:
$$\omega(t) = \left(\frac{z-1}{2}\right)\left(\frac{t+1}{z-t}\right)
\quad\iff\quad
t(\omega) = \frac{(2\omega-1)z+1}{z+(2\omega-1)}
$$
The forward transform $t \mapsto \omega$ map the points $-1, 1$ and $z$ appear in the integrand to $0, 1$ and $\infty$ respectively. In terms of $\omega$, we have:
$$
1-t^2 = \frac{4\omega(1-\omega)(z^2-1)}{(z + (2\omega-1))^2},\;\;
z - t = \frac{z^2-1}{z + (2\omega-1)}\;\;\text{ and }\;\;
dt    = \frac{2(z^2-1)}{(z + (2\omega-1))^2}d\omega
$$
As a result, the integral becomes
$$ \int_{0}^1 \Big(4\omega(1-\omega)\Big)^{\frac{n-3}{2}} \Big(z^2-1\Big)^{\frac{n-3}{2} - n + 1} \Big(z+(2\omega-1)\Big)^{-2(\frac{n-3}{2})+n-2} 2 d\omega\\
= \frac{2^{n-2}}{(z^2-1)^{\frac{n+1}{2}}} \int_0^1 \Big(\omega(1-\omega)\Big)^{\frac{n-3}{2}} \Big(z + (2\omega -1)\Big) d\omega\tag{*1}
$$
Notice in R.H.S, the factor $\omega(1-\omega)$ is invariant under the change $\omega \mapsto 1 - \omega$ while $( 2 \omega - 1 )\mapsto - (2\omega - 1)$. This means the
last $(2\omega - 1)$ term in $(*1)$ contribute nothing. The integral can be further simplified and we can express it in terms of Gamma functions:
$$\frac{2^{n-2}z}{(z^2-1)^{\frac{n+1}{2}}} \int_0^1 \Big(\omega(1-\omega)\Big)^{\frac{n-1}{2}-1} d\omega
= \left(  2^{n-2}\frac{\Gamma(\frac{n-1}{2})^2}{\Gamma(n-1)} \right) \frac{z}{(z^2-1)^{\frac{n+1}{2}}}\tag{*2}
$$
Using the duplication formula for Gamma function:
$$\Gamma(z)\Gamma(z+\frac12) = 2^{1-2z}\sqrt{\pi}\,\Gamma(2z)$$
one can turn the coefficient in $(*2)$ into the desired form:
$$2^{n-2}\frac{\Gamma(\frac{n-1}{2})^2}{\Gamma(n-1)}
= 2^{n-2}2^{1-(n-1)}\sqrt{\pi}\frac{\Gamma(\frac{n-1}{2})^2}{\Gamma(\frac{n-1}{2})\Gamma(\frac{n}{2})}
= \frac{\sqrt{\pi}\,\Gamma(\frac{n-1}{2})}{\Gamma(\frac{n}{2})}
$$
A: Here is how to get started with contour integration for even $n$:
First fix a branch of $\sqrt{1-z^2}$  (i.e. Branch cut for $\sqrt{1-z^2}$ - Can I use the branch cut of $\sqrt{z}$?)
which is analytic except on the slit $[-1,1]$.
Let $f(z) = \frac{ (\sqrt{1-z^2})^{n-3} }{ (\xi - z)^n}$ and integrate it above and below the cut via the bone contour (e.g. Showing that $\displaystyle\int_{-a}^{a} \frac{\sqrt{a^2-x^2}}{1+x^2}dx = \pi\left (\sqrt{a^2+1}-1\right)$.)
(Here I replaced $z$ by $\xi$ and $t$ by $z$, sorry!)
Then twice the desired integral is equal to the residue at $z=\xi$ minus the residue at $\infty$ times $2\pi i$. The residue at infinity vanishes, when applying the formula ($\mathrm{Res}_{z=0} \frac{-1}{z^2}f(1/z)$) as the numerator and denominator differ by $|z|^3$.
So what remains is the residue at $z=\xi$, which is a pole of order $n$. The formula for the residue is $\frac{d^{n-1}}{dz^{n-1}} \left[(z-\xi)^n f(z)\right]_{z=\xi}$.
From here it is very interesting... I wasn't sure of a good way to systematically differentiate $(1-z^2)^{(n-3)/2}$, but verifying relations in wolfram alpha shows something very interesting. Terms do not cancel, but at the $(n-1)$-th derivative ($n$ even), only a single term survives.
Another method might be to try Laurent expansion by writing $\sqrt{1-(z-\xi + \xi)^2} = \sqrt{1-\xi^2} \sqrt{ 1 - \frac{(z-\xi)^2 + 2\xi(z-\xi)}{1-\xi^2}}$.
Also gross.

(earlier comment removed because wrong). About odd case and integration by parts, taking derivatives of the numerator and antiderivatives of the denominator, don't the boundary terms vanish? When plugging in end points the $1-t^2$ gives you zero. So maybe for the odd case repeated integration by parts gives the answer? Okay, it seems to for low cases, but it's still very ugly and hard to organize! Need some more beautiful method.
