Differential equation satisfying $f(\theta)=\frac{d}{d\theta}\int_0^\theta\frac{dx}{1-\cos\theta\cos x}$ 
Find the differential equation satisfying $$f(\theta)=\frac{d}{d\theta}\int_0^\theta\frac{dx}{1-\cos\theta\cos x}$$

It is solved in my reference (also in this video) as:
$$
f(\theta)=\frac{d}{d\theta}\int_0^\theta\frac{dx}{1-\cos\theta\cos x}=\frac{1}{1-\cos^2\theta}=\csc^2\theta\\
f'(\theta)=-2\csc^2\theta\cot\theta\\
f'(\theta)+2f(\theta)\cot\theta=0
$$
As per my knowledge the Leibniz rule is
$$
\frac{d}{d\theta}\int_{a(\theta)}^{b(\theta)}g(\theta,x)dx=g(\theta,b(\theta))\frac{d}{d\theta}b(\theta)-g(\theta,a(\theta))\frac{d}{d\theta}a(\theta)
$$
iff $g(x,\theta)=g(x)$
So isn't it wrong to approach the problem as in my reference ?
 A: The answer in the video is incorrect. If you do the integral directly and then differentiate, you should get
$$
f(\theta )=-\frac{\pi}{2}\csc \theta \cot \theta.
$$ 
A: The Leibniz integral rule states
$$\frac{d}{d\theta} \left (\int_{a(\theta)}^{b(\theta)}g(\theta,x)\,dx \right) = g\big(\theta,b(\theta)\big)\cdot \frac{d}{d\theta} b(\theta) - g\big(\theta,a(\theta)\big)\cdot \frac{d}{d\theta} a(\theta) \color{blue}{+ \int_{a(\theta)}^{b(\theta)}\frac{\partial}{\partial \theta} g(\theta,x) \,dx}$$
where your problem is defined as
$$f(\theta)=\frac{d}{d\theta}\left (\int_0^\theta\frac{1}{1-\cos\theta\cos x}\,dx\right)$$
therefore
$$g(\theta,x)=\frac{1}{1-\cos\theta\cos x},\quad a(\theta)=\theta,\quad b(\theta)=0$$
and with the tangent half-angle substitution of $t=\tan \frac{x}{2}$ shown inside this question we have that
\begin{align}f(\theta)&=\frac{d}{d\theta}\left (\int_0^\theta\frac{1}{1-\cos\theta\cos x}\,dx\right)
\\&=0-\frac{1}{1-\cos^2{\theta}}-\int_0^\theta\frac{\sin\theta\cos x}{(\cos\theta\cos x- 1)^2}\,dx\\&=
-\csc^2\theta+\csc^2\theta -\frac{\pi}{2}\cot\theta\csc\theta\\&=
-\frac{\pi}{2}\cot\theta\csc\theta
\end{align}
so the derivation made in the video is incorrect as it is missing the third term in the Leibniz rule.
