Formulas counting spanning trees in line graphs and their extensions