📜 ⬆️ ⬇️

Remember watched videos on youtube





Faced the fact that youtube.com "forgets" the videos that I watched.
You have to watch a lot of educational channels, and then remember whether I saw it or not.
I watched some lecture and after a few days (months, years) the status of " scanned " disappears.
Or, on the contrary, you will look at 2 minutes of some lecture, you will go to sleep, and in the morning the lecture has the status “viewed”.
')
So I decided to take control of the views on youtube into my own hands.
And store this information, regardless of YouTube.

To watch videos on YouTube from different devices and not be tied to a local computer, I put the site online:
http://memtube.com
And I watch everything from there.
Who has the desire, please join. On the website at any time you can download an Excel file with the history of views:


If you want to make your own website, then the details under the cut.

Screenshots


Sometimes screenshots explain better than the article itself.
Therefore, I cite them first:


You can add channels that interest you.





Implementation in any web programming language


So, we write your youtube with the ability to memorize views and with excellent lecturers.
“Our YouTube” will receive information from the google API and will be a kind of layer between you and YouTube.
And will store information about the views in our database.

I wrote it in python and the flask framework, it turned out 70 lines, a link to the githab at the bottom of the article.
But since it can be recreated in php, perl and in other languages ​​for the web, the general principles are first ...

Work with google API


Get the google API key to youtube. You can here .

Channel Info
To create the site we need to get information about the channel.
Take for example the following link:
www.youtube.com/channel/UC640y4UvDAlya_WOj5U4pfA
UC640y4UvDAlya_WOj5U4pfA is the channel ID.
Access API:

curl 'https://www.googleapis.com/youtube/v3/channels?part=snippet&id=UC640y4UvDAlya_WOj5U4pfA&key=__API' 

And we get this answer in JSON format
 { "kind": "youtube#channelListResponse", "etag": "\"kYnGHzMaBhcGeLrcKRx6PAIUosY/YqjVAeQ4_JORc2ijoBKla3hrDXE\"", "pageInfo": { "totalResults": 1, "resultsPerPage": 1 }, "items": [ { "kind": "youtube#channel", "etag": "\"kYnGHzMaBhcGeLrcKRx6PAIUosY/OE6leaeClJlkthEEiPP5KVJQZPQ\"", "id": "UC640y4UvDAlya_WOj5U4pfA", "snippet": { "title": "nptelhrd", "description": "Your favorite courses available for certification! study, write an exam and get a certificate from the IITs! Check http://nptel.ac.in/noc\n\nThis channel provides technical lectures from seven Indian Institutes of Technology (IITs) and Indian Institute of Science (IISc) Bangalore.\n\nPlease visit the NPTEL Channel List below to view the complete list of courses. (24 Channels)", "publishedAt": "2007-11-28T04:54:13.000Z", "thumbnails": { "default": { "url": "https://yt3.ggpht.com/-VO_A5Tys4WY/AAAAAAAAAAI/AAAAAAAAAAA/mBvvbUvh0A8/s88-ck-no/photo.jpg" }, "medium": { "url": "https://yt3.ggpht.com/-VO_A5Tys4WY/AAAAAAAAAAI/AAAAAAAAAAA/mBvvbUvh0A8/s240-ck-no/photo.jpg" }, "high": { "url": "https://yt3.ggpht.com/-VO_A5Tys4WY/AAAAAAAAAAI/AAAAAAAAAAA/mBvvbUvh0A8/s240-ck-no/photo.jpg" } }, "localized": { "title": "nptelhrd", "description": "Your favorite courses available for certification! study, write an exam and get a certificate from the IITs! Check http://nptel.ac.in/noc\n\nThis channel provides technical lectures from seven Indian Institutes of Technology (IITs) and Indian Institute of Science (IISc) Bangalore.\n\nPlease visit the NPTEL Channel List below to view the complete list of courses. (24 Channels)" } } } ] } 



From here you can pull the 'title' field and use it as a channel name.

Get a list of videos from the channel
 curl 'https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCEBb1b_L6zDS3xTUrIALZOw&order=date&key=__API' 


And we get this answer in JSON format
 { "kind": "youtube#searchListResponse", "etag": "\"kYnGHzMaBhcGeLrcKRx6PAIUosY/vGlosUUKRoHE50sX08btNSJuUT0\"", "nextPageToken": "CAUQAA", "pageInfo": { "totalResults": 3493, "resultsPerPage": 5 }, "items": [ { "kind": "youtube#searchResult", "etag": "\"kYnGHzMaBhcGeLrcKRx6PAIUosY/f-Aj24y6ay5s_ofPTa82fwx3hP0\"", "id": { "kind": "youtube#video", "videoId": "NtMOab_nhs0" }, "snippet": { "publishedAt": "2015-04-02T00:35:45.000Z", "channelId": "UCEBb1b_L6zDS3xTUrIALZOw", "title": "Octave/MATLAB for Beginners, Part 2: Fitting Data and Plotting", "description": "MIT 22.15 Essential Numerical Methods, Fall 2014 View the complete course: http://ocw.mit.edu/22-15F14 Instructor: Ian Hutchinson Plotting the line that results ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/NtMOab_nhs0/default.jpg" }, "medium": { "url": "https://i.ytimg.com/vi/NtMOab_nhs0/mqdefault.jpg" }, "high": { "url": "https://i.ytimg.com/vi/NtMOab_nhs0/hqdefault.jpg" } }, "channelTitle": "MIT", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"kYnGHzMaBhcGeLrcKRx6PAIUosY/qLJGwF303RMmdl03IbivB2VkIQ4\"", "id": { "kind": "youtube#video", "videoId": "WUxImdA7k8E" }, "snippet": { "publishedAt": "2015-04-02T00:35:45.000Z", "channelId": "UCEBb1b_L6zDS3xTUrIALZOw", "title": "Octave/MATLAB for Beginners, Part 3: Cleaning Up & Saving Plots", "description": "MIT 22.15 Essential Numerical Methods, Fall 2014 View the complete course: http://ocw.mit.edu/22-15F14 Instructor: Ian Hutchinson Cleaning up and saving ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/WUxImdA7k8E/default.jpg" }, "medium": { "url": "https://i.ytimg.com/vi/WUxImdA7k8E/mqdefault.jpg" }, "high": { "url": "https://i.ytimg.com/vi/WUxImdA7k8E/hqdefault.jpg" } }, "channelTitle": "MIT", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"kYnGHzMaBhcGeLrcKRx6PAIUosY/mKjnuWcbJIZE_fKn12kg7B-lrN0\"", "id": { "kind": "youtube#video", "videoId": "LhPZwdhutgU" }, "snippet": { "publishedAt": "2015-04-02T00:35:45.000Z", "channelId": "UCEBb1b_L6zDS3xTUrIALZOw", "title": "Octave/MATLAB for Beginners, Part 1: Starting from Scratch", "description": "MIT 22.15 Essential Numerical Methods, Fall 2014 View the complete course: http://ocw.mit.edu/22-15F14 Instructor: Ian Hutchinson Create adjacent windows ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/LhPZwdhutgU/default.jpg" }, "medium": { "url": "https://i.ytimg.com/vi/LhPZwdhutgU/mqdefault.jpg" }, "high": { "url": "https://i.ytimg.com/vi/LhPZwdhutgU/hqdefault.jpg" } }, "channelTitle": "MIT", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"kYnGHzMaBhcGeLrcKRx6PAIUosY/EteK6EKK5CG4IAAX3JjzWUD0oAQ\"", "id": { "kind": "youtube#playlist", "playlistId": "PLUl4u3cNGP63_OOz8w5qDEoqErZ8Hj-fc" }, "snippet": { "publishedAt": "2015-04-02T00:34:03.000Z", "channelId": "UCEBb1b_L6zDS3xTUrIALZOw", "title": "MIT 22.15 Essential Numerical Methods, Fall 2014", "description": "View the complete course: http://ocw.mit.edu/22-15F14 Instructor: Ian Hutchinson Three short tutorial videos which demonstrate basic operation of Octave software, used in this graduate-level...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/LhPZwdhutgU/default.jpg" }, "medium": { "url": "https://i.ytimg.com/vi/LhPZwdhutgU/mqdefault.jpg" }, "high": { "url": "https://i.ytimg.com/vi/LhPZwdhutgU/hqdefault.jpg" } }, "channelTitle": "MIT", "liveBroadcastContent": "none" } }, { "kind": "youtube#searchResult", "etag": "\"kYnGHzMaBhcGeLrcKRx6PAIUosY/jI4Bwr7emgpt45cnFetFPewI7qU\"", "id": { "kind": "youtube#playlist", "playlistId": "PLUl4u3cNGP62FPGcyFJkzhqq9c5cHCK32" }, "snippet": { "publishedAt": "2015-03-23T21:38:55.000Z", "channelId": "UCEBb1b_L6zDS3xTUrIALZOw", "title": "MIT 8.421 Atomic and Optical Physics I, Spring 2014", "description": "MIT 8.421 Atomic and Optical Physics I, Spring 2014 View the complete course: http://ocw.mit.edu/8-421S14 Instructor: Wolfgang Ketterle This is the first of a ...", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/iwQ49oG-DO8/default.jpg" }, "medium": { "url": "https://i.ytimg.com/vi/iwQ49oG-DO8/mqdefault.jpg" }, "high": { "url": "https://i.ytimg.com/vi/iwQ49oG-DO8/hqdefault.jpg" } }, "channelTitle": "MIT", "liveBroadcastContent": "none" } } ] } 


By default, it will output the last 5 videos from the channel at a time.
To change this, you can add the & maxResults = 10 parameter, for example.
To navigate through the channel pages in JSON are given the following values:
“NextPageToken” and “prevPageToken”.
If you need to go to the next or previous page, then enter the additional parameter & pageToken =
and substitute here the value of "nextPageToken" or "prevPageToken".

Information about a single video
In general, I did not use this request in my site, but it can be useful.
Therefore, I quote it:
 curl 'https://ww.googleapis.com/youtube/v3/videos?part=snippet&id=EhNWzcUwqGbI&key=__API' 


And we get this answer in JSON format
 { "kind": "youtube#videoListResponse", "etag": "\"IHLB7Mi__JPvvG2zLQWAg8l36UU/2kAxpYyny-CEVVbQ2cOjO-XSscQ\"", "pageInfo": { "totalResults": 1, "resultsPerPage": 1 }, "items": [ { "kind": "youtube#video", "etag": "\"IHLB7Mi__JPvvG2zLQWAg8l36UU/vAIAewyN9KKpNPERU4b4tOjuPL4\"", "id": "EhNWzcUqGbI", "snippet": { "publishedAt": "2013-03-16T06:58:52.000Z", "channelId": "UCuLLf8HBxpa-RV1sf9CRmDg", "title": "50 MPH 52v Electric Mountain Bike", "description": "http://voltbicycles.com This is our Alite 1000 Electric Mountain bike powered by a black lighting brushless rear hub electric motor with a 52v battery system. This electric bike will do around 50 MPH and will run 30+ miles on a single charge. \n\nGOING GREEN DOESN'T HAVE TO BE BORING", "thumbnails": { "default": { "url": "https://i.ytimg.com/vi/EhNWzcUqGbI/default.jpg", "width": 120, "height": 90 }, "medium": { "url": "https://i.ytimg.com/vi/EhNWzcUqGbI/mqdefault.jpg", "width": 320, "height": 180 }, "high": { "url": "https://i.ytimg.com/vi/EhNWzcUqGbI/hqdefault.jpg", "width": 480, "height": 360 }, "standard": { "url": "https://i.ytimg.com/vi/EhNWzcUqGbI/sddefault.jpg", "width": 640, "height": 480 }, "maxres": { "url": "https://i.ytimg.com/vi/EhNWzcUqGbI/maxresdefault.jpg", "width": 1280, "height": 720 } }, "channelTitle": "bradscottphotography", "categoryId": "28", "liveBroadcastContent": "none", "localized": { "title": "50 MPH 52v Electric Mountain Bike", "description": "http://voltbicycles.com This is our Alite 1000 Electric Mountain bike powered by a black lighting brushless rear hub electric motor with a 52v battery system. This electric bike will do around 50 MPH and will run 30+ miles on a single charge. \n\nGOING GREEN DOESN'T HAVE TO BE BORING" } } } ] } 



How to deal with the current viewing history?


The current browsing history is stored here:
www.youtube.com/feed/history
Press to the “Still” button until the victorious end until the entire history that is stored there is loaded.
Next, save the html file.
I sketched a small parser on perl, which pulls out the ID of all the videos from the saved history file.
 use strict; use warnings; use utf8; use Mojo::DOM; use File::Slurp; use feature 'say'; my $body = read_file( 'youtube_history.html', binmode => ':utf8' ); my $dom = Mojo::DOM->new($body); for my $e ( $dom->find('div.yt-uix-tile')->each ) { say $e->{'data-context-item-id'}; } 


At the output we get a list of all the IDs on YouTube that were in youtube_history.html.
You can upload it to our local database and thus mark the video as viewed.

It is a little about implementation on flask framework


Link to github:
github.com/Alexmod/memtube
On Habré was a whole series of articles on flask , so I will not dwell in detail.
But if you want to run this file, then put the virtual environment, install all the modules that are needed to start,
and run the command:
 python main.py 

If everything is ok, you will see the following:
  * Running on http://0.0.0.0:5000/ * Restarting with reloader 

The local version of youtube.com is ready.
After the first launch, the video.db file will be created in the same directory, in which information about the views will be stored.

Source: https://habr.com/ru/post/255549/


All Articles