import urllib2
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-846c1dbd158b> in <module>
----> 1 import urllib2

ModuleNotFoundError: No module named 'urllib2'
import urllib.request as urllib2
urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-17909f13d3f4> in <module>
----> 1 urllib2.urlopem('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE')

AttributeError: module 'urllib.request' has no attribute 'urlopem'
urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE')
<http.client.HTTPResponse at 0x7f225c0386a0>
import json
 
  File "<ipython-input-6-326402734fcb>", line 1
    print json.load(urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE')
             ^
SyntaxError: invalid syntax
print json.load(urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE'))
  File "<ipython-input-7-8b7766c7a9e4>", line 1
    print json.load(urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE'))
             ^
SyntaxError: invalid syntax
print json.load(urllib2.urlopen(https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE))
  File "<ipython-input-8-162f2843d237>", line 1
    print json.load(urllib2.urlopen(https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE))
             ^
SyntaxError: invalid syntax
response = urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE')
html=response.read()
print (html)
b'{\n "kind": "youtube#videoListResponse",\n "etag": "\\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/3jdRB-NXSAfUQj7e_FmBbivkK1o\\"",\n "pageInfo": {\n  "totalResults": 1,\n  "resultsPerPage": 1\n },\n "items": [\n  {\n   "kind": "youtube#video",\n   "etag": "\\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/NUd32t1_moLGAwVuu-ZujlkaiWM\\"",\n   "id": "gwLej8heN5c",\n   "status": {\n    "uploadStatus": "processed",\n    "privacyStatus": "public",\n    "license": "creativeCommon",\n    "embeddable": true,\n    "publicStatsViewable": true\n   }\n  }\n ]\n}\n'
import urllib.request as urllib2
import json
selected_env='mydev2'
response = urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE')
data = list(json.load(response))


print(data) 
['kind', 'etag', 'pageInfo', 'items']
pip install youtube-python
import urllib.request as urllib2
import json
response = urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE')
data = list(json.load(response))

for item in json.load(response)['items']: print(item['status']['license'] == 'creativeCommon')
  File "<ipython-input-117-c4b03bf4314d>", line 1
    pip install youtube-python
              ^
SyntaxError: invalid syntax
pip install youtube-python
Collecting youtube-python
  Downloading https://files.pythonhosted.org/packages/92/30/94917cecaff1deb5a5761b7ef6010f680f831b352d47d216638cd6d5fa3a/youtube-python-1.0.13.tar.gz
Requirement already satisfied: requests in /srv/paws/lib/python3.6/site-packages (from youtube-python)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /srv/paws/lib/python3.6/site-packages (from requests->youtube-python)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /srv/paws/lib/python3.6/site-packages (from requests->youtube-python)
Requirement already satisfied: idna<2.9,>=2.5 in /srv/paws/lib/python3.6/site-packages (from requests->youtube-python)
Requirement already satisfied: certifi>=2017.4.17 in /srv/paws/lib/python3.6/site-packages (from requests->youtube-python)
Building wheels for collected packages: youtube-python
  Running setup.py bdist_wheel for youtube-python ... error
  Complete output from command /srv/paws/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-c47ihu1x/youtube-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpvobde53ipip-wheel- --python-tag cp36:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help
  
  error: invalid command 'bdist_wheel'
  
  ----------------------------------------
  Failed building wheel for youtube-python
  Running setup.py clean for youtube-python
Failed to build youtube-python
Installing collected packages: youtube-python
  Running setup.py install for youtube-python ... done
Successfully installed youtube-python-1.0.13
Note: you may need to restart the kernel to use updated packages.
from youtube import API
api = API(api_key='AIzaSyARTYmUrNCi5eMbMO-SPrzaDhkL1-VPDUE')
video = api.get('videos', id='B7FJV9KIn58')
import json
import re
import urllib.request

from pytube import YouTube

class Helper:
    def __init__(self):
        pass

    def title_to_underscore_title(self, title: str):
        title = re.sub('[\W_]+', "_", title)
        return title.lower()

    def id_from_url(self, url: str):
        return url.rsplit("/", 1)[1]

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

s = "https://youtu.be/C0PuCgQrxZU"
t = "Neural Networks in Python: Part 1 -- Part A"
helper = Helper()
print(helper.id_from_url(s))
print(helper.title_to_underscore_title(t))
#video_id = "C0PuCgQrxZU"
#url = f"https://www.googleapis.com/youtube/v3/videos?part=snippet&id={video_id}&key={api_key}"

#json_url = urllib.request.urlopen(url)
#data = json.loads(json_url.read())

#print(data)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-01a954e04667> in <module>
      3 import urllib.request
      4 
----> 5 from pytube import YouTube
      6 
      7 class Helper:

ModuleNotFoundError: No module named 'pytube'
pip install PyTube
Collecting PyTube
  Using cached https://files.pythonhosted.org/packages/d5/67/087f4771284110bf4c742d101fa8f4019529d55a2850cd383349c41f9930/pytube-9.5.0-py3-none-any.whl
Installing collected packages: PyTube
Successfully installed PyTube-9.5.0
Note: you may need to restart the kernel to use updated packages.
import json
import re
import urllib.request

from pytube import YouTube

class Helper:
    def __init__(self):
        pass

    def title_to_underscore_title(self, title: str):
        title = re.sub('[\W_]+', "_", title)
        return title.lower()

    def id_from_url(self, url: str):
        return url.rsplit("/", 1)[1]

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

s = "https://youtu.be/C0PuCgQrxZU"
t = "Neural Networks in Python: Part 1 -- Part A"
helper = Helper()
print(helper.id_from_url(s))
print(helper.title_to_underscore_title(t))
#video_id = "C0PuCgQrxZU"
#url = f"https://www.googleapis.com/youtube/v3/videos?part=snippet&id={video_id}&key={api_key}"

#json_url = urllib.request.urlopen(url)
#data = json.loads(json_url.read())

#print(data)
C0PuCgQrxZU
neural_networks_in_python_part_1_part_a
import json
import re
import urllib.request

from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

video_id = "83RUhxsfLWs"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

response = urllib.request.urlopen(url)
data = json.loads(response.read())

print(data)

for item in json.loads(response.read())['items']: print(item['status']['license'] == 'creativeCommon')
{'kind': 'youtube#videoListResponse', 'etag': '"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/MewTmEk6eVr7bfAVR9FfZ5Ca2FA"', 'pageInfo': {'totalResults': 1, 'resultsPerPage': 1}, 'items': [{'kind': 'youtube#video', 'etag': '"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/ePPN2XwrH5k8OoNce4d83nQCMZk"', 'id': '83RUhxsfLWs', 'status': {'uploadStatus': 'processed', 'privacyStatus': 'public', 'license': 'creativeCommon', 'embeddable': True, 'publicStatsViewable': True}}]}
---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-13-9a86d82c1006> in <module>
     15 print(data)
     16 
---> 17 for item in json.loads(response.read())['items']: print(item['status']['license'] == 'creativeCommon')

/usr/lib/python3.6/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    352             parse_int is None and parse_float is None and
    353             parse_constant is None and object_pairs_hook is None and not kw):
--> 354         return _default_decoder.decode(s)
    355     if cls is None:
    356         cls = JSONDecoder

/usr/lib/python3.6/json/decoder.py in decode(self, s, _w)
    337 
    338         """
--> 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    340         end = _w(s, end).end()
    341         if end != len(s):

/usr/lib/python3.6/json/decoder.py in raw_decode(self, s, idx)
    355             obj, end = self.scan_once(s, idx)
    356         except StopIteration as err:
--> 357             raise JSONDecodeError("Expecting value", s, err.value) from None
    358         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
import json
import re
import urllib.request

from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

#video_id = "83RUhxsfLWs"
#url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

#json_url = urllib.request.urlopen(url)
#data = json.loads(json_url.read())

#print(data)

video_id = "83RUhxsfLWs"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())


print(data['items'])
[{'kind': 'youtube#video', 'etag': '"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/ePPN2XwrH5k8OoNce4d83nQCMZk"', 'id': '83RUhxsfLWs', 'status': {'uploadStatus': 'processed', 'privacyStatus': 'public', 'license': 'creativeCommon', 'embeddable': True, 'publicStatsViewable': True}}]
import requests
import json
request = requests.get("http://api.roblox.com/Marketplace/ProductInfo?assetId=1834225941").text
a = json.loads(request)
print(a['Sales'])
3160
import json
import re
import urllib.request

from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

#video_id = "83RUhxsfLWs"
#url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

#json_url = urllib.request.urlopen(url)
#data = json.loads(json_url.read())

#print(data)

video_id = "83RUhxsfLWs"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())


print(data['items'])
for item in json.load(json_url.read())['items']: print(item['status']['license'] == 'creativeCommon')
[{'kind': 'youtube#video', 'etag': '"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/ePPN2XwrH5k8OoNce4d83nQCMZk"', 'id': '83RUhxsfLWs', 'status': {'uploadStatus': 'processed', 'privacyStatus': 'public', 'license': 'creativeCommon', 'embeddable': True, 'publicStatsViewable': True}}]
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-28-12f20a76339d> in <module>
     23 
     24 print(data['items'])
---> 25 for item in json.load(json_url.read())['items']: print(item['status']['license'] == 'creativeCommon')

/usr/lib/python3.6/json/__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    294 
    295     """
--> 296     return loads(fp.read(),
    297         cls=cls, object_hook=object_hook,
    298         parse_float=parse_float, parse_int=parse_int,

AttributeError: 'bytes' object has no attribute 'read'
import urllib.request as urllib2
import json
response = urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8')
data = list(json.load(response))
for item in json.load(response)['items']: print(item['status']['license'] == 'creativeCommon')
---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-32-860684d8f2f3> in <module>
      3 response = urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=gwLej8heN5c&part=status&key=AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8')
      4 data = list(json.load(response))
----> 5 for item in json.load(response)['items']: print(item['status']['license'] == 'creativeCommon')

/usr/lib/python3.6/json/__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    297         cls=cls, object_hook=object_hook,
    298         parse_float=parse_float, parse_int=parse_int,
--> 299         parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
    300 
    301 

/usr/lib/python3.6/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    352             parse_int is None and parse_float is None and
    353             parse_constant is None and object_pairs_hook is None and not kw):
--> 354         return _default_decoder.decode(s)
    355     if cls is None:
    356         cls = JSONDecoder

/usr/lib/python3.6/json/decoder.py in decode(self, s, _w)
    337 
    338         """
--> 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    340         end = _w(s, end).end()
    341         if end != len(s):

/usr/lib/python3.6/json/decoder.py in raw_decode(self, s, idx)
    355             obj, end = self.scan_once(s, idx)
    356         except StopIteration as err:
--> 357             raise JSONDecodeError("Expecting value", s, err.value) from None
    358         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
import json
import re
import urllib.request

from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

#video_id = "83RUhxsfLWs"
#url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

#json_url = urllib.request.urlopen(url)
#data = json.loads(json_url.read())

#print(data)

video_id = "83RUhxsfLWs"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())


print(data['items'])
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-0ed24067cba2> in <module>
      3 import urllib.request
      4 
----> 5 from pytube import YouTube
      6 
      7 api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

ModuleNotFoundError: No module named 'pytube'
pip install PyTube
Collecting PyTube
  Using cached https://files.pythonhosted.org/packages/d5/67/087f4771284110bf4c742d101fa8f4019529d55a2850cd383349c41f9930/pytube-9.5.0-py3-none-any.whl
Installing collected packages: PyTube
Successfully installed PyTube-9.5.0
Note: you may need to restart the kernel to use updated packages.
import json
import re
import urllib.request

from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

#video_id = "83RUhxsfLWs"
#url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

#json_url = urllib.request.urlopen(url)
#data = json.loads(json_url.read())

#print(data)

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
    value = item.get('items')
    print (value)
    if value in ['creativeCommon', 'Y', 'yes', 'Yes', 'YES']:
     print ("this will do the calculation")
    else:
     print ("this will not do the calculation")
    
None
this will not do the calculation
import json
import re
import urllib.request

from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

#video_id = "83RUhxsfLWs"
#url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

#json_url = urllib.request.urlopen(url)
#data = json.loads(json_url.read())

#print(data)

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
    value = item.get('items')
    print (value)
    if value in ['creativeCommon', 'Y', 'yes', 'Yes', 'YES']:
     print ("this will do the calculation")
    else:
     print ("this will not do the calculation")
None
this will not do the calculation
import json
import re
import urllib.request

from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

#video_id = "83RUhxsfLWs"
#url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

#json_url = urllib.request.urlopen(url)
#data = json.loads(json_url.read())

#print(data)

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
    value = item.get('items')
    print (value)
for x in data:
if x.value == value:
        print "i found it!"
        break
else:
    x = None
  File "<ipython-input-27-44fc246c2e4f>", line 27
    if x.value == value:
     ^
IndentationError: expected an indented block
import json
import re
import urllib.request
from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
    value = item.get('items')
    print (item.get('license'))
    if value in ['creativeCommon', 'CREATIVECOMMON']:
     print ("this is creativeCommon")
    else:
     print ("this is not creativeCommon")
None
this is not creativeCommon
dictionary = {'george' : 16, 'amber' : 19}
search_age = "10"
for age in dictionary.values():
    if age is 10:
        name = dictionary[age]
        print (name)
import json
import re
import urllib.request
from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
    value = item['status']['license']
    
    if value in ['creativeCommon']:
     print ("this is creativeCommon")
    else:
     print ("this is not creativeCommon")
this is creativeCommon
import json
import re
import urllib.request
from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
 value = item['status']['license']
if value in ['creativeCommon', 'CREATIVECOMMON']:
      print ("this is creativeCommon")
else:
      print ("this is not creativeCommon")
this is creativeCommon
import json
import re
import urllib.request
from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
 value = item['status']['license']
if value in ['creativeCommon', 'CREATIVECOMMON']:
      print ("this is creativeCommon")
else:
      print ("this is not creativeCommon")
this is creativeCommon
import json
import re
import urllib.request
from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
 value = item['status']['license']
if value in ['creativeCommon', 'CREATIVECOMMON']:
      print ("this is creativeCommon")
else:
      print ("this is not creativeCommon")
this is creativeCommon
import urllib.request as urllib2
import json
response = urllib2.urlopen('https://www.googleapis.com/youtube/v3/videos?id=X-x7eZOdBFM&part=status&key=AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8')
data = json.load(response)
for item in data['items']: print(item['status']['license'] == 'creativeCommon')
if True:
 print("creative", "commons")

        
False
creative commons
import re

test_links = """
    
    
https://www.youtube.com/watch?v=hAiwz2QX-zQ    
"""

pattern = r'(?:https?:\/\/)?(?:[0-9A-Z-]+\.)?(?:youtube|youtu|youtube-nocookie)\.(?:com|be)\/(?:watch\?v=|watch\?.+&v=|embed\/|v\/|.+\?v=)?([^&=\n%\?]{11})'

video_id = re.findall(pattern, test_links, re.MULTILINE | re.IGNORECASE)

print(result)
['5Y6HSHwhVlY', 'hrQxU86T0RM', '2dH7lJyKtjo']
import json
import re
import urllib.request
from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
 value = item['status']['license']
if value in ['creativeCommon', 'CREATIVECOMMON']:
      print ("this is creativeCommon")
else:
 print ("this is not creativeCommon")
this is creativeCommon
pip install pytube
Collecting pytube
  Using cached https://files.pythonhosted.org/packages/d5/67/087f4771284110bf4c742d101fa8f4019529d55a2850cd383349c41f9930/pytube-9.5.0-py3-none-any.whl
Installing collected packages: pytube
Successfully installed pytube-9.5.0
Note: you may need to restart the kernel to use updated packages.
import json
import re
import urllib.request
from pytube import YouTube

api_key = "AIzaSyA6lRsQinNw6IW39Y8IDs2Y-KmQc1RLQ_8"

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
 value = item['status']['license']
if value in ['creativeCommon', 'CREATIVECOMMON']:
      print ("this is creativeCommon")
else:
 print ("this is not creativeCommon")
this is creativeCommon
import re

test_links = 'https://www.youtube.com/watch?v=hAiwz2QX-zQ ''   


pattern = r'(?:https?:\/\/)?(?:[0-9A-Z-]+\.)?(?:youtube|youtu|youtube-nocookie)\.(?:com|be)\/(?:watch\?v=|watch\?.+&v=|embed\/|v\/|.+\?v=)?([^&=\n%\?]{11})'

video_id = re.findall(pattern, test_links, re.MULTILINE | re.IGNORECASE)

print(result)
  File "<ipython-input-60-43186b9e34ca>", line 3
    test_links = 'https://www.youtube.com/watch?v=hAiwz2QX-zQ ''
                                                                   ^
SyntaxError: EOL while scanning string literal
import re

test_links = """
    
    'https://www.youtube.com/watch?v=hAiwz2QX-zQ',
    'https://www.youtube.com/watch?v=fSj5D3s35a0',
"""

pattern = r'(?:https?:\/\/)?(?:[0-9A-Z-]+\.)?(?:youtube|youtu|youtube-nocookie)\.(?:com|be)\/(?:watch\?v=|watch\?.+&v=|embed\/|v\/|.+\?v=)?([^&=\n%\?]{11})'

video_id = re.findall(pattern, test_links, re.MULTILINE | re.IGNORECASE)

print(result)
['5Y6HSHwhVlY', 'hrQxU86T0RM', '2dH7lJyKtjo']
import re

test_links = """




Official NEFFEX Merch: https://www.redbubble.com/people/neffex/shop

https://www.youtube.com/watch?v=CYDP_8UTAus
{{From YouTube|1=CYDP_8UTAus|2=NEFFEX - Fight Back [Official Video]}}
|author=[https://www.youtube.com/user/neffexmusic NEFFEX Music]



"""

pattern = r'(?:https?:\/\/|{{From YouTube)?(?:[0-9A-Z-]+\.)?(?:youtube|youtu|youtube-nocookie|\|1)\.(?:com|be|=)\/(?:watch\?v=|watch\?.+&v=|embed\/|v\/|.+\?v=)?([^&=\n%\?]{11})'

result = re.findall(pattern, test_links, re.MULTILINE | re.IGNORECASE)

print(result)
['CYDP_8UTAus', 'user/neffex']