This app was mentioned in 1 comment, with an average of 2.00 upvotes
I don't know if the tickets can sold out, but you should try the renfe ticket app. It works decently (for a transportation app in spain) and you can pay with PayPal now (you have to authorize a card before and even with spanish cars it was a little confusing).
Android app: https://play.google.com/store/apps/details?id=com.renfe.wsm&hl=es
iOs app: https://itunes.apple.com/es/app/renfeticket/id727555862?mt=8