Let's see.
1) The main structure in both sentences is the same: "venir de + infinitif" (passé récent: recent past).
This structure expresses that "something has just happened/someone has just done something", as for example: Il vient d'arriver: He's just arrived; Je viens de lire le livre: I've just read the book; je viens de me lever: I've just got up.
2) This structure can be used in the past tense, with the same meaning. It usually refers to an action in the past that had just happened before another action. For example: Il venait d’arriver quand le téléphone a sonné: He had just arrived when the phone rang; Je venais de me lever lorsqu’il a commencé à pleuvoir: I had just got up when it started to rain.
In this case, "venir" is conjugated in "indicatif imparfait " (je venais, tu venais, il venait...).
3) So, as to conclude, in your sentences, the main difference is tense (present or past). The fact that you use "le/l'" (pronoun) or "livre" has nothing to do with the construction "venir de + infinitif". It has to do, as in english, with whether or not the object has been mentioned previously. So, all combinations are possible:
Je viens d'acheter un livre.
Te souviens-tu du livre que tu m'avais conseillé?, je viens de l'acheter.
Je venais d'acheter un livre quand un homme derrière moi m'interpella.
Le livre était rangé sur le rayon. Je venais de le mettre à sa place, c'est pour ça que je savais où il se trouvait.