Use the substitution t=tan(x/2). Then dx=1+t22dt and cosx=1+t21−t2.
Change limits: When x=0,t=0. When x=π,t→∞.
Substitute into the integral:
I=∫0∞1−2a(1+t21−t2)+a21+t22dt=∫0∞(1+t2)−2a(1−t2)+a2(1+t2)2dt
Denominator =1+t2−2a+2at2+a2+a2t2=(1−a)2+t2(1+a)2.
I=2∫0∞(1−a)2+t2(1+a)2dt=(1+a)22∫0∞t2+(1+a1−a)2dt
Using the formula ∫x2+k2dx=k1tan−1(kx):
I=(1+a)22⋅1−a1+a[tan−1(t⋅1−a1+a)]0∞=1−a22(2π−0)=1−a2π