-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(2.3.0): Refactor Input Formatting (#24)
* move utility files to a seperate folder * moved to utils * remove playlists and local buttons and functionality as it is no longer needed * update requirements as deprecated youtubesearchpython library is no longer used * fix local video file handlging * refactor youtube check functions and rename files
- Loading branch information
Allan Cao
authored
Oct 21, 2022
1 parent
41ff45c
commit e55d1c2
Showing
9 changed files
with
75 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import pkgutil | ||
__path__ = pkgutil.extend_path(__path__, __name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import cv2 | ||
|
||
|
||
tracking_folder = os.path.join( | ||
"assets", | ||
"tracking") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
VALID_VIDEO_FORMATS = ["WEBM", "MPG", "MP2", "MPEG", "MPE", "MPV", "OGG", "MP4", "M4P", "M4V", "AVI", "WMV", "MOV", "QT", "FLV", "SWF", "AVCHD"] | ||
|
||
def clean_for_directory(video_title : str) -> str: | ||
for ch in ['*', '.', '"', '/', '\\', ':', ';', '|', ',']: | ||
if ch in video_title: | ||
video_title = video_title.replace(ch, '') | ||
video_title = video_title.replace(' ', '_') | ||
|
||
return video_title | ||
|
||
def parse_local_files(url : str) -> dict or None: | ||
videos = {} | ||
print(url) | ||
if os.path.isdir(url): | ||
for file in os.listdir(url): | ||
if file.split('.')[-1].upper() in VALID_VIDEO_FORMATS: | ||
# get the file's name | ||
video_name = clean_for_directory(file) | ||
videos[video_name] = os.path.join(url, file) | ||
else: | ||
print(f'Invalid file format: {file}') | ||
elif os.path.isfile(url): | ||
if url.split('.')[-1].upper() in VALID_VIDEO_FORMATS: | ||
video_name = clean_for_directory(url) | ||
videos[video_name] = url | ||
return videos | ||
else: | ||
print(f'Invalid file format: {url}') | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import yt_dlp | ||
from assets.utils.video_file_helper import clean_for_directory | ||
|
||
def is_valid_youtube_url(url) -> bool: | ||
return 'youtube' in url and '/watch?v=' in url | ||
|
||
def is_youtube_playlist(url) -> bool: | ||
return '&list=' in url or '/playlist?list=' in url | ||
|
||
def parse_youtube_url(url : str) -> dict: | ||
videos = {} | ||
ydl_opts = { | ||
'format': '22', | ||
'ignoreerrors': True, | ||
'no_warnings': True | ||
} | ||
with yt_dlp.YoutubeDL(ydl_opts) as ydl: | ||
info = ydl.extract_info(url, download=False) | ||
video_info = ydl.sanitize_info(info) | ||
if video_info['_type'] == 'playlist': | ||
for video in video_info['entries']: | ||
video_name = clean_for_directory(video['title']) | ||
videos[video_name] = video_info['formats'][-1]['url'] | ||
else: | ||
video_name = clean_for_directory(video_info['title']) | ||
videos[video_name] = video_info['formats'][-1]['url'] | ||
return videos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters