瀏覽代碼

Minor changes to delete videos

sleepytaco 3 年之前
父節點
當前提交
ec8d849396

+ 18 - 8
apps/main/models.py

@@ -1,6 +1,8 @@
 import datetime
+import time
 
 import googleapiclient.errors
+import humanize
 from django.db import models
 from django.db.models import Q
 from google.oauth2.credentials import Credentials
@@ -115,7 +117,7 @@ class PlaylistManager(models.Manager):
 
         # if its been a week since the last full scan, do a full playlist scan
         # basically checks all the playlist video for any updates
-        if playlist.last_full_scan_at + datetime.timedelta(hours=24) < datetime.datetime.now(pytz.utc):
+        if playlist.last_full_scan_at + datetime.timedelta(hours=1) < datetime.datetime.now(pytz.utc):
             print("DOING A FULL SCAN")
             current_video_ids = [video.video_id for video in playlist.videos.all()]
 
@@ -512,7 +514,7 @@ class PlaylistManager(models.Manager):
                 playlist_duration_in_seconds = calculateDuration(vid_durations)
 
                 playlist.playlist_duration_in_seconds = playlist_duration_in_seconds
-                playlist.playlist_duration = str(timedelta(seconds=playlist_duration_in_seconds))
+                playlist.playlist_duration = humanize.precisedelta(timedelta(seconds=playlist_duration_in_seconds)).upper()
 
                 if len(video_ids) != len(vid_durations):  # that means some videos in the playlist are deleted
                     playlist.has_unavailable_videos = True
@@ -782,7 +784,7 @@ class PlaylistManager(models.Manager):
         playlist_duration_in_seconds = calculateDuration(vid_durations)
 
         playlist.playlist_duration_in_seconds = playlist_duration_in_seconds
-        playlist.playlist_duration = str(timedelta(seconds=playlist_duration_in_seconds))
+        playlist.playlist_duration = humanize.precisedelta(timedelta(seconds=playlist_duration_in_seconds)).upper()
 
         if len(video_ids) != len(vid_durations):  # that means some videos in the playlist are deleted
             playlist.has_unavailable_videos = True
@@ -996,7 +998,7 @@ class PlaylistManager(models.Manager):
         playlist_duration_in_seconds = calculateDuration(vid_durations)
 
         playlist.playlist_duration_in_seconds = playlist_duration_in_seconds
-        playlist.playlist_duration = str(timedelta(seconds=playlist_duration_in_seconds))
+        playlist.playlist_duration = humanize.precisedelta(timedelta(seconds=playlist_duration_in_seconds)).upper()
 
         if len(video_ids) != len(vid_durations) or len(
                 unavailable_videos) != 0:  # that means some videos in the playlist became private/deleted
@@ -1018,7 +1020,8 @@ class PlaylistManager(models.Manager):
         credentials = self.getCredentials(user)
         playlist = Playlist.objects.get(playlist_id=playlist_id)
 
-        num_deleted = 0
+        #new_playlist_duration_in_seconds = playlist.playlist_duration_in_seconds
+        #new_playlist_video_count = playlist.video_count
         with build('youtube', 'v3', credentials=credentials) as youtube:
             for playlist_item_id in playlist_item_ids:
                 pl_request = youtube.playlistItems().delete(
@@ -1035,7 +1038,16 @@ class PlaylistManager(models.Manager):
                     pass
 
                 # playlistItem was successfully deleted if no HttpError, so delete it from db
-                # playlist.videos.get(playlist_item_id=playlist_item_id).delete()  # updatePlaylist will be called so unecessary for now
+                #video = playlist.videos.get(playlist_item_id=playlist_item_id)
+                #new_playlist_video_count -= 1
+                #new_playlist_duration_in_seconds -= video.duration_in_seconds
+                #video.delete()
+
+        #playlist.video_count = new_playlist_video_count
+        #playlist.playlist_duration_in_seconds = new_playlist_duration_in_seconds
+        #playlist.playlist_duration = humanize.precisedelta(timedelta(seconds=new_playlist_duration_in_seconds)).upper()
+        #playlist.save(update_fields=['video_count', 'playlist_duration', 'playlist_duration_in_seconds'])
+        #time.sleep(2)
 
     def updatePlaylistDetails(self, user, playlist_id, details):
         """
@@ -1112,8 +1124,6 @@ class Playlist(models.Model):
     has_duplicate_videos = models.BooleanField(default=False)  # duplicate videos will not be shown on site
 
     has_playlist_changed = models.BooleanField(default=False)  # determines whether playlist was modified online or not
-    playlist_changed_text = models.CharField(max_length=420,
-                                             default="")  # user friendly text to display what changed and how much changed
 
     # for UI
     view_in_grid_mode = models.BooleanField(default=False)  # if False, videso will be showed in a list

+ 6 - 1
apps/main/templates/intercooler/playlist_updates.html

@@ -1,15 +1,20 @@
 
 {% load humanize %}
 {% load static %}
-    <br>
     <div class="alert alert-success alert-dismissible fade show" role="alert">
       <h4 class="alert-heading">Updates</h4>
       <p>{{ playlist_changed_text|linebreaksbr }}</p>
       <hr>
       <p class="mb-0">Tip: Sort By Updates to see what changed in this playlist. Deleted videos will not show up there. Updates can be seen for 12 hrs.</p>
+        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
+        <div class="d-flex justify-content-center">
+        <a class="btn btn-primary mt-2" href="{% url 'playlist' playlist_id %}">Refresh</a>
+    </div>
     </div>
 
+<!--
     <div class="d-flex justify-content-center">
         <a class="btn btn-primary" href="{% url 'playlist' playlist_id %}">Back</a>
     </div>
+    -->
       <meta http-equiv="refresh" content="100" />

+ 2 - 2
apps/main/templates/intercooler/videos.html

@@ -41,7 +41,7 @@
                             </a>
                             <br>
                             <span class="badge bg-dark">VIDEO UNAVAILABLE</span>
-                            {% if video.video_details_modified %}<span class="badge bg-danger">UPDATED - {% if video.was_deleted_on_yt %}WENT PRIVATE/DELETED{% else %}NEWLY ADDED{% endif %}</span>{% endif %}
+                            {% if video.video_details_modified %}<span class="badge bg-danger">{% if video.was_deleted_on_yt %}WENT PRIVATE/DELETED{% else %}ADDED{% endif %} {{ video.updated_at|naturaltime|upper }}</span>{% endif %}
                             <br><br>
                         {% else %}
                             {{ video.video_position }}.
@@ -54,7 +54,7 @@
                           {% if video.view_count %}<span class="badge bg-info">{{ video.view_count|intword|intcomma }} views</span>{% endif %}
 
                             {% if video.is_duplicate %}<span class="badge bg-primary">duplicate</span>{% endif %}
-                            {% if video.video_details_modified %}<span class="badge bg-danger">UPDATED - {% if video.was_deleted_on_yt %}WENT PRIVATE/DELETED{% else %}NEWLY ADDED{% endif %}</span>{% endif %}<br>
+                            {% if video.video_details_modified %}<span class="badge bg-danger">{% if video.was_deleted_on_yt %}WENT PRIVATE/DELETED{% else %}ADDED{% endif %} {{ video.created_at|naturaltime|upper }}</span>{% endif %}<br>
                             <br>
                         {% endif %}
 

+ 6 - 14
apps/main/templates/view_playlist.html

@@ -5,33 +5,26 @@
 
 {% block content %}
 
-
     <div id="view_playlist">
 
-    <div hx-get="{% url 'update_playlist' playlist.playlist_id 'checkforupdates' %}" hx-trigger="load" hx-swap="outerHTML">
 
-    </div>
 
     {% if playlist.has_playlist_changed %}
-
         <div hx-get="{% url 'update_playlist' playlist.playlist_id 'auto' %}" hx-trigger="load" hx-swap="outerHTML">
-            <div class="alert alert-success alert-dismissible fade show" role="alert">
-                {{ playlist.playlist_changed_text|linebreaksbr|default:"Looks like the playlist on YouTube was modified!" }}
-
-                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
-            </div>
             <div class="d-flex justify-content-center mt-4 mb-3" id="loading-sign">
                 <img src="{% static 'svg-loaders/circles.svg' %}" width="40" height="40">
                 <h5 class="mt-2 ms-2">Updating playlist '{{ playlist.name }}', please wait!</h5>
             </div>
         </div>
     {% else %}
-    <br>
+    <div hx-get="{% url 'update_playlist' playlist.playlist_id 'checkforupdates' %}" hx-trigger="load" hx-swap="outerHTML" class="sticky-top" style="top: 0.5rem;" id="checkforupdates">
+
+    </div>
 
     <div class="list-group-item list-group-item-action active">
         <div class="d-flex w-100 justify-content-between">
             <span>
-                <h2 class="mb-1">{{ playlist.name }} <small>{% if playlist.user_label %}a.k.a <kbd>{{ playlist.user_label }}</kbd>{% endif %}</small>
+                <h2 class="mb-1">{{ playlist.name }} <small>{% if playlist.user_label %}<span class="h3" style="border-bottom: 3px #ffffff dashed;">a.k.a {{ playlist.user_label }}</span>{% endif %}</small>
                     <small>
 
                         <input class="form-control me-1 visually-hidden" id="pl-{{ playlist.playlist_id }}" value="{{ playlist.playlist_id }}">
@@ -269,7 +262,6 @@
 
     <div class="table-responsive" id="videos-div">
         <br>
-
         {% if videos %}
         <div class="list-group" id="video-checkboxes">
           {% for video in videos %}
@@ -312,7 +304,7 @@
                             </a>
                             <br>
                             <span class="badge bg-dark">VIDEO UNAVAILABLE</span>
-                            {% if video.video_details_modified %}<span class="badge bg-danger">UPDATED - {% if video.was_deleted_on_yt %}WENT PRIVATE/DELETED{% else %}NEWLY ADDED{% endif %}</span>{% endif %}
+                            {% if video.video_details_modified %}<span class="badge bg-danger">WENT PRIVATE/DELETED {{ video.updated_at|naturaltime|upper }}</span>{% endif %}
                             <br><br>
                         {% else %}
                             {{ video.video_position }}.
@@ -325,7 +317,7 @@
                           {% if video.view_count %}<span class="badge bg-info">{{ video.view_count|intword|intcomma }} views</span>{% endif %}
 
                             {% if video.is_duplicate %}<span class="badge bg-primary">duplicate</span>{% endif %}
-                            {% if video.video_details_modified %}<span class="badge bg-danger">UPDATED - {% if video.was_deleted_on_yt %}WENT PRIVATE/DELETED{% else %}NEWLY ADDED{% endif %}</span>{% endif %}<br>
+                            {% if video.video_details_modified %}<span class="badge bg-danger">{% if video.was_deleted_on_yt %}WENT PRIVATE/DELETED{% else %}ADDED{% endif %} {{ video.created_at|naturaltime|upper }}</span>{% endif %}<br>
                             <br>
                         {% endif %}
 

+ 42 - 37
apps/main/views.py

@@ -313,10 +313,14 @@ def delete_videos(request, playlist_id, command):
             f'<div class="spinner-border text-light" role="status" hx-post="/from/{playlist_id}/delete-videos/start" hx-trigger="load" hx-swap="outerHTML"></div>')
     elif command == "start":
         Playlist.objects.deletePlaylistItems(request.user, playlist_id, video_ids)
-        playlist = request.user.profile.playlists.get(playlist_id=playlist_id)
-        playlist.has_playlist_changed = True
-        playlist.save(update_fields=['has_playlist_changed'])
-        return HttpResponse(f'Done! Refreshing page...<meta http-equiv="refresh" content="1" />')
+        #playlist = request.user.profile.playlists.get(playlist_id=playlist_id)
+        #playlist.has_playlist_changed = True
+        #playlist.save(update_fields=['has_playlist_changed'])
+        return HttpResponse(f"""
+        <div hx-get="/playlist/{playlist_id}/update/checkforupdates" hx-trigger="load delay:4s" hx-target="#checkforupdates" class="sticky-top" style="top: 0.5rem;">
+Done! Playlist on UnTube will update in 3s...
+        </div>
+        """)
 
 
 @login_required
@@ -567,57 +571,58 @@ def update_playlist(request, playlist_id, type):
 
             print("CHANGES", deleted_videos, unavailable_videos, added_videos)
 
-            playlist_changed_text = ["The following modifications happened to this playlist on YouTube:"]
+            #playlist_changed_text = ["The following modifications happened to this playlist on YouTube:"]
             if deleted_videos != 0 or unavailable_videos != 0 or added_videos != 0:
-                if added_videos > 0:
-                    playlist_changed_text.append(f"{added_videos} new video(s) were added")
-                if deleted_videos > 0:
-                    playlist_changed_text.append(f"{deleted_videos} video(s) were deleted")
-                if unavailable_videos > 0:
-                    playlist_changed_text.append(f"{unavailable_videos} video(s) went private/unavailable")
-
-                playlist.playlist_changed_text = "\n".join(playlist_changed_text)
-                playlist.has_playlist_changed = True
-                playlist.save()
+                pass
+                #if added_videos > 0:
+                #    playlist_changed_text.append(f"{added_videos} new video(s) were added")
+                #if deleted_videos > 0:
+                #    playlist_changed_text.append(f"{deleted_videos} video(s) were deleted")
+                #if unavailable_videos > 0:
+                #    playlist_changed_text.append(f"{unavailable_videos} video(s) went private/unavailable")
+
+                #playlist.playlist_changed_text = "\n".join(playlist_changed_text)
+                #playlist.has_playlist_changed = True
+                #playlist.save()
             else:  # no updates found
                 return HttpResponse("""
+                <div id="checkforupdates" class="sticky-top" style="top: 0.5em;">
                 <div class="alert alert-success alert-dismissible fade show visually-hidden" role="alert">
                     No new updates!
                 </div>
+                <br>
+                </div>
                 """)
         elif result[0] == -1:  # playlist changed
             print("!!!Playlist changed")
 
-            current_playlist_vid_count = playlist.video_count
-            new_playlist_vid_count = result[1]
+            #current_playlist_vid_count = playlist.video_count
+            #new_playlist_vid_count = result[1]
 
-            print(current_playlist_vid_count)
-            print(new_playlist_vid_count)
-
-            if current_playlist_vid_count > new_playlist_vid_count:
-                playlist.playlist_changed_text = f"Looks like {current_playlist_vid_count - new_playlist_vid_count} video(s) were deleted from this playlist on YouTube!"
-            else:
-                playlist.playlist_changed_text = f"Looks like {new_playlist_vid_count - current_playlist_vid_count} video(s) were added to this playlist on YouTube!"
+            #print(current_playlist_vid_count)
+            #print(new_playlist_vid_count)
 
-            playlist.has_playlist_changed = True
-            playlist.save()
-            print(playlist.playlist_changed_text)
+            # playlist.has_playlist_changed = True
+            #playlist.save()
+            #print(playlist.playlist_changed_text)
         else:  # no updates found
             return HttpResponse("""
-            <div class="alert alert-success alert-dismissible fade show visually-hidden" role="alert">
+            <div id="checkforupdates" class="sticky-top" style="top: 0.5em;">
+            <div class="alert alert-success alert-dismissible fade show visually-hidden sticky-top" role="alert" style="top: 0.5em;">
                 No new updates!
             </div>
+            <br>
+            </div>
             """)
 
         return HttpResponse(f"""
-        <div hx-get="/playlist/{playlist_id}/update/auto" hx-trigger="load" hx-target="#view_playlist">
+        <div hx-get="/playlist/{playlist_id}/update/auto" hx-trigger="load" hx-target="this" class="sticky-top" style="top: 0.5em;">
+            
             <div class="alert alert-success alert-dismissible fade show" role="alert">
-                {playlist.playlist_changed_text}
-                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
-            </div>
-            <div class="d-flex justify-content-center mt-4 mb-3" id="loading-sign">
+            <div class="d-flex justify-content-center" id="loading-sign">
                 <img src="/static/svg-loaders/circles.svg" width="40" height="40">
-                <h5 class="mt-2 ms-2">Updating playlist '{playlist.name}', please wait!</h5>
+                <h5 class="mt-2 ms-2">Changes detected on YouTube, updating playlist '{playlist.name}'...</h5>
+            </div>
             </div>
         </div>
         """)
@@ -643,9 +648,9 @@ def update_playlist(request, playlist_id, type):
         playlist.delete()
         return HttpResponse(
             f"""
-                    <div class="d-flex justify-content-center mt-4 mb-3" id="loading-sign">
-                        <h5 class="mt-2 ms-2">Looks like the playlist '{playlist_name}' was deleted on YouTube. It has been removed from UnTube as well.</h5>
-                    </div>
+                <div class="d-flex justify-content-center mt-4 mb-3" id="loading-sign">
+                    <h5 class="mt-2 ms-2">Looks like the playlist '{playlist_name}' was deleted on YouTube. It has been removed from UnTube as well.</h5>
+                </div>
             """)
 
     print("Updated playlist")

+ 1 - 1
apps/users/templates/settings.html

@@ -116,7 +116,7 @@
 
                         <div class="mb-3 form-check form-switch">
                         <input class="form-check-input" name="auto refresh playlists" type="checkbox" id="flexSwitchCheckDefault">
-                        <label class="form-check-label" for="flexSwitchCheckDefault">Automatically refresh playlists on visit</label>
+                        <label class="form-check-label" for="flexSwitchCheckDefault">Automatically refresh playlists on visit (this can abruptly refresh the page)</label>
                         </div>
 
                         <div class="mb-3 form-check form-switch">

+ 17 - 0
requirements.txt

@@ -7,7 +7,19 @@ cryptography==3.4.7
 defusedxml==0.7.1
 Django==3.2.3
 django-allauth==0.44.0
+django-appconf==1.0.4
+django-classy-tags==2.0.0
+django-cms==3.8.0
 django-crispy-forms==1.11.2
+django-filer==2.0.2
+django-formtools==2.3
+django-js-asset==1.2.2
+django-mptt==0.12.0
+django-polymorphic==3.0.0
+django-sekizai==2.0.0
+django-treebeard==4.5.1
+djangocms-admin-style==2.0.2
+easy-thumbnails==2.7.1
 ecdsa==0.14.1
 google-api-core==1.28.0
 google-api-python-client==2.7.0
@@ -17,10 +29,14 @@ google-auth-oauthlib==0.4.4
 googleapis-common-protos==1.53.0
 gunicorn==20.1.0
 httplib2==0.19.1
+humanize==3.10.0
 idna==2.10
 install==1.3.4
+isodate==0.6.0
+jsonfield==3.1.0
 oauthlib==3.1.0
 packaging==20.9
+Pillow==8.2.0
 protobuf==3.17.1
 pyasn1==0.4.8
 pyasn1-modules==0.2.8
@@ -37,6 +53,7 @@ six==1.16.0
 social-auth-app-django==4.0.0
 social-auth-core==3.3.3
 sqlparse==0.4.1
+Unidecode==1.1.2
 uritemplate==3.0.1
 urllib3==1.26.5
 whitenoise==5.2.0

+ 20 - 15
templates/base.html

@@ -11,7 +11,6 @@
         <title>UnTube</title>
 
         <style type="text/css">
-
             body {
                 background: linear-gradient(-45deg, #B2A3FF, #84bcf3, #AE876B, #B0E7AE);
                 //background: linear-gradient(-45deg, #0645a4, #2480cd, #84bcf3, #b7d6f7);
@@ -47,10 +46,13 @@
         <link href="https://fonts.googleapis.com/css2?family=Fredoka+One&family=Open+Sans&display=swap" rel="stylesheet">
 
         <link href="{% static 'fontawesome-free-5.15.3-web/css/all.min.css' %}" rel="stylesheet">
+        <link href="{% static 'jquery-toast-plugin/dist/jquery.toast.min.css' %}" rel="stylesheet">
         <link href="{% static 'bootstrap5.0.1/css/bootstrap.min.css' %}" rel="stylesheet">
 
     </head>
-    <body class="bg-dark text-white"  style="font-family: 'Fredoka One', monospace; filter: contrast(80%);">
+    <body class="text-dark" style="font-family: 'Fredoka One', monospace; filter: contrast(80%);">
+
+
         {% if user.profile.show_import_page %}
             <meta http-equiv="refresh" content="0;url={{ domain }}import/init" />
         {% endif %}
@@ -116,19 +118,17 @@
             </div>
         </nav>
 
-        <div class="container-fluid text-dark">
-        <div class="row">
-            <main class="ms-lg-auto px-lg-5">
-    {% block content %}
-    {% endblock %}
-            </main>
-      </div>
-
-
-    </div>
 
 
+        <div class="container-fluid text-dark">
 
+            <div class="row">
+                <main class="ms-lg-auto px-lg-5">
+                {% block content %}
+                {% endblock %}
+                </main>
+            </div>
+        </div>
 
         <br>
 
@@ -136,14 +136,19 @@
         <script src="{% static 'htmx/htmx.min.js' %}" type="application/javascript"></script>
         <script src="{% static 'clipboard.js/clipboard.min.js' %}" type="application/javascript"></script>
         <script src="{% static 'jquery3.6.0/js/jquery-3.6.0.min.js' %}" type="application/javascript"></script>
+        <script src="{% static 'jquery-toast-plugin/dist/jquery.toast.min.js' %}" type="application/javascript"></script>
         <script src="{% static 'bootstrap5.0.1/js/bootstrap.bundle.js' %}" type="application/javascript"></script>
         <!-- <script src="{% static 'htmx/extensions/class-tools.js' %}" type="application/javascript"></script> -->
 
 
         <script type="application/javascript">
-            $(document).ready(function() {
-                $(".toast").toast('show');
-            });
+              $( document ).ready(function() {
+                  var msg = "Small Message";
+                 // var msg = "Lengthy Message is here. MMMMMmmmmmmmmmmmM";
+                  $(".msgText").text(msg);
+                    $(".alert").show();
+                });
+
             document.body.addEventListener('htmx:configRequest', (event) => {
             event.detail.headers['X-CSRFToken'] = '{{ csrf_token }}';
           })