History in code (as we showed trailers on the Movie Navigator) Youtube is currently blocked in Russia.
Therefore, all Russian users who do not use a VPN when working with our Cinema Navigator were left without trailers (all trailers we showed with YouTube, and no alternative options were supposed).
We thought and decided to connect the possibility of using trailers from VKontakte (there are already almost all Russified trailers).
What had to be done was clear in principle. And I rolled up my sleeves and climbed into the js code in the Movie Navigator, which is the trailer. The code turned out to be quite short (~200 lines), but very confusing, with a lot of historical strata and a lot of unused functionality. As a result, it was easier to re-write it.
Looking at the code, I remembered how the story of the trailers on the Movie Navigator developed, and it seemed very instructive to me.
This little piece of code, like a drop of water, reflects the story of how IT companies and politicians have spoiled the lives of developers and users over the past 5 years.
So, history.
1. At one time, YouTube had a useful feature - the ability to embed players into third-party sites not for a specific video with its unique ID, but for a search query. As a result, YouTube itself formed a playlist, and opened it in the player, providing the opportunity to go through the videos right there.
When we launched the Movie Navigator (February 2019), we used this function – when generating pages, a search query such as “film {Name} {year} trailer” was substituted in the src frame with a trailer. So there was no code at all. And in general, everything worked more or less.
2. Not yet have user complaints started. In the window of the player, some bullshit was often shown first, and the necessary trailers were often not even a long leaf of the playlist (well, not everyone knew that it could be flipped).
It turned out that YouTube searches are rather strange and very sensitive to the order of the words in the query. And for different films – different. So that he would immediately give out what you need - sometimes it was better to write the word "trailer" in front, sometimes it was better not to write a year. . .
That's where programming started. We decided that we would generate a bundle of possible search queries for Russian and English titles, and allow users to vote and go through them by browsing (the wrong trailer / that trailer), and build the order of display according to the vote.
They did, and it worked for a year. Until it stopped working. The trailers stopped showing at all.
3. It turned out that Google simply closed this option (search query in the YouTube frame:). And now, to get a list of videos on request, you need to use YouTube-API.
And to do this, you need to register with Google developers console, get approval, create a project, get a key and then you can use the API.
Anyway, it took me a couple of days to get through all this and finish the code. At the same time, his logic has changed greatly.
It made sense to store video identifiers obtained through the API in the database, and show them before climbing with requests to the API. Voting and leafing remained, but now it began to refer not to a search query, but to a specific video. Requests, however, also had to go through, as not any queries at all gave a relevant result - with the advent of the Youtube API did not get smarter. .
I did, I did. It worked. And it worked exactly half an hour.
4. It turned out that in the free API, Google has a limit on this request – something like no more than 100 pieces a day. And as the limit ended (and it ended quickly), everything stopped working for a day.
Fuck him, I thought. After all, in a matter of months for most popular movies, trailers will pump up.
But here we made it possible to manually add trailers. And users started adding them quite actively.
5. In parallel, I sent a request to Google for an increase in the free limit (there is such a possibility, as it turned out). In response, I was sent Application Form on 5 pages with a lot of stupid questions. I answered them as best I could and sent them.
A week later, I received a response like “we still don’t understand what your project is” and a new Application Form – already on 8 pages, with a week to answer.
And then I spit, and I realized that you couldn't break Google's bureaucracy. We have to find another way out.
And Google's bureaucracy, it turns out, spat on me. A month later, I received a letter that since I did not respond and my project is still somewhat incomprehensible, the free limit for me was reduced.
6. I was playing with pirate player integrator yohoho to ensure that I and my family could watch movies directly on the Movie Navigator.
For everyone to open it was cranky, you could get under the distribution. I already regularly received threatening letters from copyright holders about references to pirates in the “Watch” window.
And yohoho had a mode where it wasn't movies that were requested, but trailers. And I hooked up the trailer showing with yohoho if the trailers weren't among the saved ones and the API request to Youtube didn't work.
It's better. Almost all right.
7. Until yohoho shut down Roskomnadzor.
He went to various places for a while until he died. It got worse, but by that time users had already established themselves to add trailers, so it was tolerable.
8. And here comes 2022.
And when the Youtube API stopped working after some time, it turned out that the key for requests to the API should be regularly renewed, and Google blocked the entrance to the developers console for Russian IP (and somehow even the VPN did not help).
As a result, all my cunning trailer mining technique fell off. Only a custom add-on remains.
But most popular movies by then had already received trailers, so somehow it was possible to live with it.
9. But there was not only bad news, but also good news.
I connected to the (unofficial) Movie Search API to update the data, and it turned out that Kinopoisk knew a bunch of trailers (also from YouTube) and the API gave them away.
I started taking them from there, and it was fine.
9. Until YouTube was blocked.
And then I started doing what was actually written in the beginning - connecting the player with VK. There was a lot to add in the back and at the front.
I laid down a simple logic for showing trailers - users with Russian ip show only VK-trailers (I already knew how to define the country by ip), and with non-Russian - everything. Because if you have a Russian IP, you will not see YouTube, and if you go through a VPN, then the IP will not be Russian.
Uploaded, tested, and shouted at active users - asking them to add VK trailers where there are none. Users responded. And not just adding trailers.
10. The first day there were complaints from people who had seen the trailers before, but now they haven’t.
It turned out that the underlying logic was wrong. Because there are Yubust-type devices that, while not being a VPN, allow you to fully watch YouTube. The IP remains Russian. There are many people who use them (only Yubust has more than 1 million installations).
This, too, had to take into account - to leave youtube trailers for Russian users, but show them in rotation after VK-sh.
It also turned out that for some unknown reason VK does not allow all rollers to be embedded. That is, it gives them embed, but shows a window with an error. As a result, you needed a record - who exactly added this or that trailer, and a feature for removal available to the one who added.
And it turned out that from some countries, in particular Latvia and Ukraine, VK is not available. But I haven't done anything about that yet.
P.S. I strongly suspect that the story did not end there. Because neither IT companies nor politicians, obviously, are going to stop in their main business - to complicate people's lives.
close