예제 #1
0
 def delete_objects_for_missing_videos(youtube_ids_in_filesystem,
                                       videos_marked_at_all):
     # VideoFile objects say they're available, but that don't actually exist.
     deleted_video_ids = []
     videos_flagged_for_download = set([
         video.youtube_id for video in VideoFile.objects.filter(
             flagged_for_download=True)
     ])
     videos_needing_model_deletion_chunked = break_into_chunks(
         videos_marked_at_all - youtube_ids_in_filesystem -
         videos_flagged_for_download)
     # Disconnect cache-invalidation listener to prevent it from being called multiple times
     for chunk in videos_needing_model_deletion_chunked:
         video_files_needing_model_deletion = VideoFile.objects.filter(
             youtube_id__in=chunk)
         deleted_video_ids += [
             video_file.youtube_id
             for video_file in video_files_needing_model_deletion
         ]
         video_files_needing_model_deletion.delete()
     if deleted_video_ids:
         caching.invalidate_all_caches()
         self.stdout.write(
             "Deleted %d VideoFile models (because the videos didn't exist in the filesystem)\n"
             % len(deleted_video_ids))
     return deleted_video_ids
예제 #2
0
 def delete_objects_for_missing_videos(youtube_ids_in_filesystem, videos_marked_at_all):
     # VideoFile objects say they're available, but that don't actually exist.
     deleted_video_ids = []
     videos_flagged_for_download = set([video.youtube_id for video in VideoFile.objects.filter(flagged_for_download=True)])
     videos_needing_model_deletion_chunked = break_into_chunks(videos_marked_at_all - youtube_ids_in_filesystem - videos_flagged_for_download)
     for chunk in videos_needing_model_deletion_chunked:
         video_files_needing_model_deletion = VideoFile.objects.filter(youtube_id__in=chunk)
         video_files_needing_model_deletion.delete()
         deleted_video_ids += [video_file.video_id for video_file in video_files_needing_model_deletion]
     if deleted_video_ids:
         self.stdout.write("Deleted %d VideoFile models (because the videos didn't exist in the filesystem)\n" % len(deleted_video_ids))
     return deleted_video_ids
예제 #3
0
        def update_objects_to_be_complete(youtube_ids_in_filesystem):
            # Files that exist, are in the DB, but have percent_complete=0, download_in_progress=False
            updated_video_ids = []
            for chunk in break_into_chunks(youtube_ids_in_filesystem):
                video_files_needing_model_update = VideoFile.objects.filter(percent_complete=0, download_in_progress=False, youtube_id__in=chunk)
                video_files_needing_model_update.update(percent_complete=100, flagged_for_download=False)

                updated_video_ids += [i18n.get_video_id(video_file.youtube_id) for video_file in video_files_needing_model_update]

            if updated_video_ids:
                self.stdout.write("Updated %d VideoFile models (to mark them as complete, since the files exist)\n" % len(updated_video_ids))
            return updated_video_ids
예제 #4
0
        def update_objects_to_be_complete(youtube_ids_in_filesystem):
            # Files that exist, are in the DB, but have percent_complete=0, download_in_progress=False
            updated_video_ids = []
            for chunk in break_into_chunks(youtube_ids_in_filesystem):
                video_files_needing_model_update = VideoFile.objects.filter(percent_complete=0, download_in_progress=False, youtube_id__in=chunk)
                video_files_needing_model_update.update(percent_complete=100, flagged_for_download=False)

                updated_video_ids += [i18n.get_video_id(video_file.youtube_id) for video_file in video_files_needing_model_update]

            if updated_video_ids:
                self.stdout.write("Updated %d VideoFile models (to mark them as complete, since the files exist)\n" % len(updated_video_ids))
            return updated_video_ids
예제 #5
0
 def delete_objects_for_missing_videos(youtube_ids_in_filesystem, videos_marked_at_all):
     # VideoFile objects say they're available, but that don't actually exist.
     deleted_video_ids = []
     videos_flagged_for_download = set([video.youtube_id for video in VideoFile.objects.filter(flagged_for_download=True)])
     videos_needing_model_deletion_chunked = break_into_chunks(videos_marked_at_all - youtube_ids_in_filesystem - videos_flagged_for_download)
     # Disconnect cache-invalidation listener to prevent it from being called multiple times
     for chunk in videos_needing_model_deletion_chunked:
         video_files_needing_model_deletion = VideoFile.objects.filter(youtube_id__in=chunk)
         deleted_video_ids += [video_file.youtube_id for video_file in video_files_needing_model_deletion]
         video_files_needing_model_deletion.delete()
     if deleted_video_ids:
         caching.invalidate_all_caches()
         self.stdout.write("Deleted %d VideoFile models (because the videos didn't exist in the filesystem)\n" % len(deleted_video_ids))
     return deleted_video_ids
예제 #6
0
파일: api_views.py 프로젝트: SG345/ka-lite
def start_video_download(request):
    """
    API endpoint for launching the videodownload job.
    """
    youtube_ids = OrderedSet(simplejson.loads(request.body or "{}").get("youtube_ids", []))

    # One query per video (slow)
    video_files_to_create = [id for id in youtube_ids if not get_object_or_None(VideoFile, youtube_id=id)]

    # OK to do bulk_create; cache invalidation triggered via save download
    for lang_code, lang_youtube_ids in divide_videos_by_language(video_files_to_create).iteritems():
        VideoFile.objects.bulk_create([VideoFile(youtube_id=id, flagged_for_download=True, language=lang_code) for id in lang_youtube_ids])

    # OK to update all, since we're not setting all props above.
    # One query per chunk
    for chunk in break_into_chunks(youtube_ids):
        video_files_needing_model_update = VideoFile.objects.filter(download_in_progress=False, youtube_id__in=chunk).exclude(percent_complete=100)
        video_files_needing_model_update.update(percent_complete=0, cancel_download=False, flagged_for_download=True)

    force_job("videodownload", _("Download Videos"), locale=request.language)

    return JsonResponseMessageSuccess(_("Launched video download process successfully."))
예제 #7
0
def start_video_download(request):
    """
    API endpoint for launching the videodownload job.
    """
    youtube_ids = OrderedSet(simplejson.loads(request.raw_post_data or "{}").get("youtube_ids", []))

    # One query per video (slow)
    video_files_to_create = [id for id in youtube_ids if not get_object_or_None(VideoFile, youtube_id=id)]

    # OK to do bulk_create; cache invalidation triggered via save download
    for lang_code, lang_youtube_ids in divide_videos_by_language(video_files_to_create).iteritems():
        VideoFile.objects.bulk_create([VideoFile(youtube_id=id, flagged_for_download=True, language=lang_code) for id in lang_youtube_ids])

    # OK to update all, since we're not setting all props above.
    # One query per chunk
    for chunk in break_into_chunks(youtube_ids):
        video_files_needing_model_update = VideoFile.objects.filter(download_in_progress=False, youtube_id__in=chunk).exclude(percent_complete=100)
        video_files_needing_model_update.update(percent_complete=0, cancel_download=False, flagged_for_download=True)

    force_job("videodownload", _("Download Videos"), locale=request.language)

    return JsonResponseMessageSuccess(_("Launched video download process successfully."))
예제 #8
0
 def delete_objects_for_missing_videos(youtube_ids_in_filesystem,
                                       videos_marked_at_all):
     # VideoFile objects say they're available, but that don't actually exist.
     deleted_video_ids = []
     videos_flagged_for_download = set([
         video.youtube_id for video in VideoFile.objects.filter(
             flagged_for_download=True)
     ])
     videos_needing_model_deletion_chunked = break_into_chunks(
         videos_marked_at_all - youtube_ids_in_filesystem -
         videos_flagged_for_download)
     for chunk in videos_needing_model_deletion_chunked:
         video_files_needing_model_deletion = VideoFile.objects.filter(
             youtube_id__in=chunk)
         video_files_needing_model_deletion.delete()
         deleted_video_ids += [
             video_file.video_id
             for video_file in video_files_needing_model_deletion
         ]
     if deleted_video_ids:
         self.stdout.write(
             "Deleted %d VideoFile models (because the videos didn't exist in the filesystem)\n"
             % len(deleted_video_ids))
     return deleted_video_ids