How to check if video has been deleted or removed in youtube using python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to check if video has been deleted or removed in youtube using python (/thread-9463.html) Pages:
1
2
|
How to check if video has been deleted or removed in youtube using python - Prince_Bhatia - Apr-10-2018 i have a csv file where i have 1000 videos links . I want to check whether these videos still exists or they have been removed or deleted from YouTube. How can i do that in python? Please guide on this RE: How to check if video has been deleted or removed in youtube using python - Larz60+ - Apr-10-2018 show your code, you don;'t even state whether you're using requests, urllib or whatever for access. You should take a look at snippsats tutorials on web scraping here: part1 and part2 using requests, if you get status_code != 200, the file doesn't exist. (you can use exception clause of try, except to capture errors. RE: How to check if video has been deleted or removed in youtube using python - snippsat - Apr-10-2018 You should look YouTube Data API v3. Need a google account then get can get free API key and most also enable API. Then can parse out video id out of csv and check if it's publicStatsViewable True or False.Url is build like this. https://www.googleapis.com/youtube/v3/videos?id={id_of_the_video}&key={your_api_key}&part=status Then can write code. import requests from pprint import pprint id_of_video = 'CUNq2_VjRn4' your_api_key = 'xxxxxxxxxxxxxx' url = f'https://www.googleapis.com/youtube/v3/videos?id={id_of_video}&key={your_api_key}&part=status' url_get = requests.get(url) pprint(url_get.json()) The part needed.>>> url_get.json()['items'][0]['status']['publicStatsViewable'] True RE: How to check if video has been deleted or removed in youtube using python - Prince_Bhatia - Apr-10-2018 hi, Larz60+, I had no idea on how would i start on that so i asked for guidance. HI, snippsat for your help. I had no idea on how to use API. so first i will study and practice all articles provided by Larz60+ on webscraping and then i will study your code. Thank you so much again for giving me a kickstart RE: How to check if video has been deleted or removed in youtube using python - jehoshua - Feb-16-2020 (Apr-10-2018, 05:18 PM)snippsat Wrote: Then can write code. I tried the above code (after entering in 'id_of_video' and 'your_api_key' and got an error .. Quote:url = f'https://www.googleapis.com/youtube/v3/videos?id={id_of_video}&key={your_api_key}&part=status' Then noticed the f, removed it an whilst the script ran okay, this is what was displayed Quote:{'error': {'code': 400, RE: How to check if video has been deleted or removed in youtube using python - snippsat - Feb-16-2020 (Feb-16-2020, 05:34 AM)jehoshua Wrote: Then noticed the I use f-string here,then need Python 3.6 or newer.You should upgrade your Python version. Here with older string formatting. import requests from pprint import pprint id_of_video = 'CUNq2_VjRn4' your_api_key = 'xxxxxxxxxxxxxxx' url = 'https://www.googleapis.com/youtube/v3/videos?id={}&key={}&part=status'.format(id_of_video, your_api_key) url_get = requests.get(url) pprint(url_get.json()) RE: How to check if video has been deleted or removed in youtube using python - jehoshua - Feb-16-2020 (Feb-16-2020, 06:46 AM)snippsat Wrote: I use I'm only on 16.04.6 LTS of Kubuntu and can only go to version 3.5, but found a PPA Quote:sudo add-apt-repository ppa:deadsnakes/ppa It seems I now have 3 versions of python running Quote:$ python -V I assume there is a method to set the default version to 3.7.6 so that running any scripts I can simply do this .. Quote:python script.py (Feb-16-2020, 06:46 AM)snippsat Wrote: Here with older string formatting. Thanks, I will try that with vers 3.5 and then the f -string with version 3.6
RE: How to check if video has been deleted or removed in youtube using python - snippsat - Feb-16-2020 (Feb-16-2020, 08:53 AM)jehoshua Wrote: I assume there is a method to set the default version to 3.7.6 so that running any scripts I can simply do this ..Yes can set alias or mess with update-alternatives link. Or just use python3.7 my_script.py to run and install with eg pip3.7 install requests . I use pyenv Simple Python Version Management then this done automatically to chosen version. RE: How to check if video has been deleted or removed in youtube using python - jehoshua - Feb-16-2020 (Feb-16-2020, 04:15 PM)snippsat Wrote: Yes can set alias or mess with update-alternatives link. I tried everything as per the pyenv Simple Python Version Management thread, but it still would not default as per expected. I would assume this is because I'm using a PPA to force to Python 3.7.6 , and for some reason, Kubuntu just isn't recognising it. It's on my 'to do' list to upgrade to the latest Kubuntu, so will try it again then. Thanks very much for your help. Just a fyi, the output from bash is at https://paste.ubuntu.com/p/9HYXYBS6jW/ RE: How to check if video has been deleted or removed in youtube using python - snippsat - Feb-17-2020 jehoshua Wrote::~$ pyenv global 3.7.2You most first install a version and then set it as global. Example if i want to use 3.8.1 on my Linux Mint 19. # Look at available versions tom@tom:~$ pyenv install --list ..... 3.7.5 3.7.5rc1 3.7.6 3.8.0 3.8-dev 3.8.1 3.9-dev # Install tom@tom:~$ pyenv install 3.8.1 Downloading Python-3.8.1.tar.xz... -> https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tar.xz Installing Python-3.8.1... Installed Python-3.8.1 to /home/tom/.pyenv/versions/3.8.1 # Set as system wide version tom@tom:~$ pyenv global 3.8.1 # Test tom@tom:~$ python Python 3.8.1 (default, Feb 11 2020, 09:18:58) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print(walrus := True) True >>> exit() tom@tom:~$ pip -V pip 19.2.3 from /home/tom/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pip (python 3.8) |