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

Handle restricted/unavailable videos [and list them in "Tasks" view, when downloading (stale!) playlists] #179

Merged
merged 6 commits into from
Jun 11, 2024

Conversation

deldesir
Copy link
Collaborator

@deldesir deldesir commented Jun 11, 2024

This PR handles various issues related to restricted/unavailable videos. Those videos won't fail an entire playlist anymore.
N.B This PR should also fix the hanging upon redownloading a failed video.

Tested on Ubuntu 24.04 with playlist https://www.youtube.com/playlist?list=PLfiHW0cuXSvQSZHsA5zpo3JdrY5EJp1yT

image

Unavailable videos do not have a duration
@deldesir deldesir marked this pull request as draft June 11, 2024 03:05
@holta holta added bug Something isn't working enhancement New feature or request labels Jun 11, 2024
@deldesir deldesir changed the title Handle restricted/failed videos Handle restricted/unavailable videos Jun 11, 2024
@deldesir deldesir requested a review from holta June 11, 2024 03:52
@deldesir deldesir marked this pull request as ready for review June 11, 2024 03:52
@deldesir deldesir self-assigned this Jun 11, 2024
@holta
Copy link
Member

holta commented Jun 11, 2024

  1. Ruff-like CI (GitHub Actions) will definitely be needed in coming weeks, e.g. so that increasingly more than just linting (like a5b6f90) happens more automatically.

  2. @deldesir: Will the problem below (3 kinds of errors on a fresh test: (1) 'NoneType' object cannot be interpreted as an integer (2) 'NoneType' object is not subscriptable (3) Download appears to be stuck #167 (comment)) be addressed in a separate PR?

it appears playlists/channels are blocked from downloading if even a single YouTube video is "unavailable" or "owner of this video has [NOT] granted you access".

  • Can this strict approach be made more pragmatic — for educators wanting the bulk of the playlist/channel downloaded — even despite a few videos no longer being available?
  • (Instead of blocking the full download!)

@deldesir
Copy link
Collaborator Author

  1. Ruff-like CI (GitHub Actions) will definitely be needed in coming weeks, e.g. so that increasingly more than just linting like a5b6f90) happens more automatically.

Yes.

  1. @deldesir: Will the problem below (3 kinds of errors on a fresh test: (1) 'NoneType' object cannot be interpreted as an integer (2) 'NoneType' object is not subscriptable (3) Download appears to be stuck #167 (comment)) be addressed in a separate PR?

it appears playlists/channels are blocked from downloading if even a single YouTube video is "unavailable" or "owner of this video has [NOT] granted you access".

  • Can this strict approach be made more pragmatic — for educators wanting the bulk of the playlist/channel downloaded — even despite a few videos no longer being available?
  • (Instead of blocking the full download!)

This PR deals with these issues specifically. As a debugging aid, I list all unavailable videos that used to block a playlist download at the bottom of the task message. I think this is useful to test the reliability of this PR. You can see an example in the tasks page of LRN2 with @nzola's playlist of playlists.

@holta holta merged commit cf0303a into iiab:master Jun 11, 2024
@deldesir
Copy link
Collaborator Author

deldesir commented Jun 11, 2024

I will disable the listing of unavailable videos in the tasks page before this PR is merged. Let me know what you think.

Update: Oops, already merged. If the list needs to go away, let me know please.

@holta
Copy link
Member

holta commented Jun 11, 2024

I will disable the listing of unavailable videos in the tasks page before this PR is merged. Let me know what you think.

"Tasks" view list of unavailable videos seems very useful, no?

Example below from https://box/live/tasks on server LRN2:

image

@deldesir
Copy link
Collaborator Author

I don't find them useful per se, especially when they are more than a couple. I was thinking of putting the bookshelf title link here instead.

@holta
Copy link
Member

holta commented Jun 11, 2024

I don't find them useful per se, especially when they are more than a couple.

Librarians & Archivists & Curators very much want to know how many videos (and which videos) were "disappeared" by hosting sites like Google/YouTube.

That info needs to be available without too much hassle, and http://box/books > "Tasks" view is a very good place for it in my opinion.

Regardless whether video(s) disappeared due to censorship, copyright, privacy, geo-block, or any other reason (-:

I was thinking of putting the bookshelf title link here instead.

Certainly, that should also be included somewhere in "Tasks" view, yes please if possible!

@holta holta changed the title Handle restricted/unavailable videos Handle restricted/unavailable videos [and list them in "Tasks" view, when downloading playlists] Jun 11, 2024
@holta holta changed the title Handle restricted/unavailable videos [and list them in "Tasks" view, when downloading playlists] Handle restricted/unavailable videos [and list them in "Tasks" view, when downloading (stale!) playlists] Jun 11, 2024
@holta
Copy link
Member

holta commented Jun 11, 2024

@codewiz

Can you give this PR a quick review for suggestions?

(Even though it was merged urgently earlier this morning, to help users & testers!)

Comment on lines +70 to +73
requested_urls = {row[0]: {"duration": row[1]} if row[1] is not None and row[1] > 0 else self.unavailable.append(row[0]) for row in rows}
for url in self.unavailable:
requested_urls.pop(url)
return requested_urls
Copy link

@codewiz codewiz Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally untested code that seems simpler and more readable than the list comprehension with conditionals.

requested_urls = {}
for path, duration in rows:
    if duration is not None and duration > 0:
      requested_urls[path] = {"duration": duration};
   else:
      self.unavailable.append(path)
   return requested_urls

Copy link
Member

@holta holta Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deldesir I'm in favor of simple + more readable if you can consider?!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return
self.message = f"{self.media_url_link} failed: Video not available."
conn.execute("DELETE FROM media WHERE path = ?", (self.media_url,))
self.stat = STAT_FAIL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets overridden with STAT_FINISH_SUCCESS at line 178. Is it ok?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, previously this line was skipped when requested_urls is empty, now it's executed every time:

self._add_download_tasks_to_worker(requested_urls)

Are there any unwanted side-effects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. STAT_FINISH_SUCCESS and STAT_FAIL both end the task.

Copy link
Collaborator Author

@deldesir deldesir Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, previously this line was skipped when requested_urls is empty, now it's executed every time:

self._add_download_tasks_to_worker(requested_urls)

Are there any unwanted side-effects?

This one send every requested_url to the download task. It could be done in a single task, but was discarded in favor of individual task for every download. See #99

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list of requested URLs is retrieved from xklb-metadata.db. It's basically a search for every row which have no text in its error column and path is a URL.

This list can be empty if these conditions are not met.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list of requested URLs is retrieved from xklb-metadata.db. It's basically a search for every row which have no text in its error column and path is a URL.

This list can be empty if these conditions are not met.

My original question was: is it ok to call _add_download_tasks_to_worker() even when requested_urls is an empty list?

I looked at the body of _add_download_tasks_to_worker(), and it does nothing when called with an empty list.

So... OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants