Skip to content

Commit

Permalink
Fix incomplete URL substring sanitation (ultralytics#7056)
Browse files Browse the repository at this point in the history
Resolves code scanning alert in ultralytics#7055
  • Loading branch information
glenn-jocher committed Mar 20, 2022
1 parent 248c428 commit 282a2d3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from multiprocessing.pool import Pool, ThreadPool
from pathlib import Path
from threading import Thread
from urllib.parse import urlparse
from zipfile import ZipFile

import cv2
Expand Down Expand Up @@ -301,7 +302,7 @@ def __init__(self, sources='streams.txt', img_size=640, stride=32, auto=True):
for i, s in enumerate(sources): # index, source
# Start thread to read frames from video stream
st = f'{i + 1}/{n}: {s}... '
if 'youtube.com/' in s or 'youtu.be/' in s: # if source is YouTube video
if urlparse(s).hostname in ('youtube.com', 'youtu.be'): # if source is YouTube video
check_requirements(('pafy', 'youtube_dl==2020.12.2'))
import pafy
s = pafy.new(s).getbest(preftype="mp4").url # YouTube URL
Expand Down

0 comments on commit 282a2d3

Please sign in to comment.