Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yt-dlp fix #4

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update main.py
  • Loading branch information
vorozhkog authored Mar 21, 2023
commit 4989610136550a4fd6c948c3fecf684a715901ef
21 changes: 7 additions & 14 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
downloaded_video = None
download_progress = None

# def get_youtube_id(link):

# assert link.startswith("https://www.youtube.com/"), "Invalid YouTube link. Please use desktop format of url starting with 'https://www.youtube.com/...'"
# try:
# # Extract the video ID from the link using regular expressions
# video_id = re.search(r'(?<=v=)[^&#]+', link).group(0)
# except AttributeError:
# # If the regular expression doesn't match, raise an exception with a custom error message
# raise ValueError("Invalid YouTube link.")
def my_hook(d):
global downloaded_video
global download_progress

if d["status"] == "downloading":
if download_progress is None:
Expand Down Expand Up @@ -57,8 +52,8 @@ def main():
global download_progress

remote_path = sly.env.file()
local_save_path = os.path.join("src", sly.fs.get_file_name_with_ext(remote_path))
api.file.download(team_id, remote_path, local_save_path)
local_path = os.path.join("src", sly.fs.get_file_name_with_ext(remote_path))
api.file.download(team_id, remote_path, local_path)

project = api.project.get_or_create(
workspace_id=workspace_id,
Expand All @@ -69,8 +64,7 @@ def main():
dataset = api.dataset.create(project.id, "YouTube Videos", change_name_if_conflict=True)

data = []

with open(local_save_path, "r") as f:
with open(local_path, "r") as f:
data = f.readlines()

output_dir = "data/"
Expand All @@ -83,7 +77,6 @@ def main():
print(f"Start {normalized_url}")
download_progress = None
download(normalized_url, output_dir)
# ln -s /Users/germanvorozko/work-apps/supervisely/supervisely ./supervisely
api.video.upload_path(
dataset_id=dataset.id,
name=sly.fs.get_file_name_with_ext(downloaded_video),
Expand All @@ -96,7 +89,7 @@ def main():
sly.logger.warn(repr(e))
progress.iter_done_report()

sly.fs.silent_remove(local_save_path)
sly.fs.silent_remove(local_path)

print("Done")
if sly.is_production():
Expand Down