This article—The Problem With Sex According to Buddhism—provides a good overview of how traditional Buddhism has viewed sexual behavior. Generally, the modern way of looking at it is sexual behavior should not harm anyone and should not lead to unwanted entanglements.
Overcoming excessive or obsessive desire for anything, not just sex, is an important part of Buddhist practice. Most of the time most of us know what is excessive in most situations. Guidance from a “wise friend” can help when there is doubt.
Contemplating the “uncleanness” of any excessive desire has been praised through the centuries by countless Buddhist practitioners. Contemplating the “uncleanness” of something means to contemplate its negative aspects. If you cannot get over your obsession for motorcycles, for example, contemplate their expense, danger, the trouble of maintaining them, etc. This kind of contemplation will tend to decrease desire by balancing it with real-world considerations.
The “uncleanness” contemplation is intended to be used to overcome excessive desire or greed. It is not advised for anyone experiencing depression or despair as it may worsen these conditions. More on this topic can be found here.