Trading the Dhamma is wrong, according to Ud 6.2.
But selling a paperback book containing words of the Dhamma is not wrong, if the proceeds meant for the author, goes to charitable causes.
Ven. Ajahn Brahm has published books and has regular talks on YouTube. According to this page:
Ajahn Brahm has authored three popular books that are available
commercially ... the royalties raised from sales of these books goes
to the activities of the Buddhist Society of Western Australia.
Similarly, if videos of talks by Dhamma teachers are monetized on YouTube with ads, it's ok, if the money received by the YouTube channel owner, is then used for charitable causes.
It's only wrong if the money from such activities is used for financial profit and as a means of livelihood.
Of course, YouTube itself, and the book publishing company itself, may make profit, but this is only because they are providing a platform as a paid service. After all, they need money to maintain this platform and pay their employees.
What about the recipient of the Dhamma? Well, it's up to him to discover who is the right teacher and who is the wrong teacher. Sometimes, monks like Devadatta (Iti 89) or Sati (MN 38) are wrong teachers and a lay householder like Citta (SN 41.5) is the right teacher.