ソースを参照

Updated settings and added profile page

sleepytaco 3 年 前
コミット
989d43a54a

+ 49 - 48
apps/main/models.py

@@ -113,55 +113,9 @@ class PlaylistManager(models.Manager):
 
         playlist = user.profile.playlists.get(playlist_id=pl_id)
 
-        with build('youtube', 'v3', credentials=credentials) as youtube:
-            pl_request = youtube.playlists().list(
-                part='contentDetails, snippet, id, status',
-                id=pl_id,  # get playlist details for this playlist id
-                maxResults=50
-            )
-
-            # execute the above request, and store the response
-            try:
-                pl_response = pl_request.execute()
-            except googleapiclient.errors.HttpError:
-                print("YouTube channel not found if mine=True")
-                print("YouTube playlist not found if id=playlist_id")
-                return -1
-
-            playlist_items = []
-
-            for item in pl_response["items"]:
-                playlist_items.append(item)
-
-            while True:
-                try:
-                    pl_request = youtube.playlists().list_next(pl_request, pl_response)
-                    pl_response = pl_request.execute()
-                    for item in pl_response["items"]:
-                        playlist_items.append(item)
-                except AttributeError:
-                    break
-
-        for item in playlist_items:
-            playlist_id = item["id"]
-
-            # check if this playlist already exists in database
-            if user.profile.playlists.filter(playlist_id=playlist_id).count() != 0:
-                playlist = user.profile.playlists.get(playlist_id__exact=playlist_id)
-                print(f"PLAYLIST {playlist.name} ALREADY EXISTS IN DB")
-
-                # POSSIBLE CASES:
-                # 1. PLAYLIST HAS DUPLICATE VIDEOS, DELETED VIDS, UNAVAILABLE VIDS
-
-                # check if playlist changed on youtube
-                if playlist.video_count != item['contentDetails']['itemCount']:
-                    playlist.has_playlist_changed = True
-                    playlist.save()
-                    return [-1, item['contentDetails']['itemCount']]
-
         # 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(days=7) < 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()]
 
@@ -172,7 +126,7 @@ class PlaylistManager(models.Manager):
             with build('youtube', 'v3', credentials=credentials) as youtube:
                 pl_request = youtube.playlistItems().list(
                     part='contentDetails, snippet, status',
-                    playlistId=playlist_id,  # get all playlist videos details for this playlist id
+                    playlistId=pl_id,  # get all playlist videos details for this playlist id
                     maxResults=50
                 )
 
@@ -233,6 +187,53 @@ class PlaylistManager(models.Manager):
             deleted_videos = len(current_video_ids)  # left out video ids
 
             return [1, deleted_videos, unavailable_videos, added_videos]
+
+        with build('youtube', 'v3', credentials=credentials) as youtube:
+            pl_request = youtube.playlists().list(
+                part='contentDetails, snippet, id, status',
+                id=pl_id,  # get playlist details for this playlist id
+                maxResults=50
+            )
+
+            # execute the above request, and store the response
+            try:
+                pl_response = pl_request.execute()
+            except googleapiclient.errors.HttpError:
+                print("YouTube channel not found if mine=True")
+                print("YouTube playlist not found if id=playlist_id")
+                return -1
+
+            playlist_items = []
+
+            for item in pl_response["items"]:
+                playlist_items.append(item)
+
+            while True:
+                try:
+                    pl_request = youtube.playlists().list_next(pl_request, pl_response)
+                    pl_response = pl_request.execute()
+                    for item in pl_response["items"]:
+                        playlist_items.append(item)
+                except AttributeError:
+                    break
+
+        for item in playlist_items:
+            playlist_id = item["id"]
+
+            # check if this playlist already exists in database
+            if user.profile.playlists.filter(playlist_id=playlist_id).count() != 0:
+                playlist = user.profile.playlists.get(playlist_id__exact=playlist_id)
+                print(f"PLAYLIST {playlist.name} ALREADY EXISTS IN DB")
+
+                # POSSIBLE CASES:
+                # 1. PLAYLIST HAS DUPLICATE VIDEOS, DELETED VIDS, UNAVAILABLE VIDS
+
+                # check if playlist changed on youtube
+                if playlist.video_count != item['contentDetails']['itemCount']:
+                    playlist.has_playlist_changed = True
+                    playlist.save()
+                    return [-1, item['contentDetails']['itemCount']]
+
         return [0, "no change"]
 
     # Used to check if the user has a vaild YouTube channel

+ 1 - 1
apps/main/templates/view_playlist.html

@@ -304,7 +304,7 @@
                    </div>
                     <div class="ms-4">
                         {{ video.video_position }}.
-                        <a class="link-dark" href="https://www.youtube.com/watch?v={{ video.videoid }}&list={{ video.playlist.playlist_id }}" target="_blank">
+                        <a class="link-dark" href="https://www.youtube.com/watch?v={{ video.video_id }}&list={{ video.playlist.playlist_id }}" target="_blank">
                             {{ video.name|truncatewords:"16" }}
                         </a> by {{ video.channel_name }} <br>
                         <span class="badge bg-secondary">{{ video.duration }}</span>

+ 6 - 1
apps/main/views.py

@@ -532,7 +532,12 @@ def update_playlist(request, playlist_id, type):
                 playlist.playlist_changed_text = "\n".join(playlist_changed_text)
                 playlist.has_playlist_changed = True
                 playlist.save()
-
+            else:  # no updates found
+                return HttpResponse("""
+                <div class="alert alert-success alert-dismissible fade show visually-hidden" role="alert">
+                    No new updates!
+                </div>
+                """)
         elif result[0] == -1:  # playlist changed
             print("!!!Playlist changed")
 

+ 25 - 1
apps/users/templates/index.html

@@ -12,6 +12,30 @@
 
     <title>UnTube</title>
 
+      <style type="text/css">
+
+            body {
+                background: linear-gradient(-45deg, #B2A3FF, #84bcf3, #AE876B, #B0E7AE);
+                //background: linear-gradient(-45deg, #0645a4, #2480cd, #84bcf3, #b7d6f7);
+                //background: linear-gradient(-45deg, #AE876B, #ABA27B, #A7BC8A, #A3D69A);
+                background-size: 400% 400%;
+                animation: gradient 10s ease infinite;
+                }
+
+            @keyframes gradient {
+                0% {
+                    background-position: 0% 50%;
+                }
+                50% {
+                    background-position: 100% 50%;
+                }
+                100% {
+                    background-position: 0% 50%;
+                }
+            }
+
+      </style>
+
       <link href="https://fonts.googleapis.com/css2?family=Fredoka+One&family=Open+Sans&display=swap" rel="stylesheet">
 
     <!-- Bootstrap core CSS -->
@@ -45,7 +69,7 @@
       </main>
 
       <footer class="mastfoot mt-auto">
-        <div class="inner">
+        <div class="inner text-white">
           <h6>Made with <span style="color: #e25555;">&hearts;</span> in Django</h6>
         </div>
       </footer>

+ 7 - 3
apps/users/templates/profile.html

@@ -12,13 +12,17 @@
           <div class="card bg-dark text-white">
             <div class="card-body">
               <div class="d-flex flex-column align-items-center text-center">
-                <img src="https://robohash.org/{{ user.username }}.png?set=set{{ user.profile.robohash_set }}" alt="{{ user.username }}" class="border border-5 border-primary rounded-circle" width="150">
+                <img src="https://robohash.org/{{ user.username }}.png?set=set{{ user.profile.robohash_set }}" alt="{{ user.username }}" class="border border-5 border-success rounded-circle" width="150">
                 <div class="mt-3">
                   <h4>{{ user.get_full_name }}</h4>
                   <p class="text-white-50 mb-1">{{ user.profile.user_summary }}</p>
                   <p class="text-white-50 font-size-sm">{{ user.profile.user_location }}</p>
+
+                    <!--
                   <button class="btn btn-primary">Follow</button>
-                  <button class="btn btn-outline-primary">Message</button>
+                  <button class="btn btn-outline-primary">Message</button> -->
+                    <a class="btn btn-outline-success" href="{% url 'settings' %}">Settings</a>
+
                 </div>
               </div>
             </div>
@@ -44,7 +48,7 @@
               </li>
               <li class="list-group-item bg-dark d-flex justify-content-between align-items-center flex-wrap">
                 <h6 class="mb-0 text-white">Imported YouTube Playlists</h6>
-                <span class="text-white-50">Yes</span>
+                  <small><a class="btn btn-success">Import</a></small>
               </li>
             </ul>
           </div>

+ 20 - 28
apps/users/templates/settings.html

@@ -63,6 +63,7 @@
 
             </div>
           </div>
+
         </div>
         <div class="col-md-8">
 
@@ -103,33 +104,6 @@
                   </div>
               <hr>
 
-              <div class="row">
-                <div class="col-sm-3">
-                  <h6 class="mb-0">Access Token</h6>
-                </div>
-                <div class="col-sm-9 text-white-50">
-                    {{ user.profile.access_token }}
-                </div>
-              </div>
-              <hr>
-              <div class="row">
-                <div class="col-sm-3">
-                  <h6 class="mb-0">Refresh Token</h6>
-                </div>
-                <div class="col-sm-9 text-white-50">
-                    {{ user.profile.refresh_token }}
-                </div>
-              </div>
-              <hr>
-            <div class="row">
-                <div class="col-sm-3">
-                  <h6 class="mb-0">Expires At</h6>
-                </div>
-                <div class="col-sm-9 text-white-50">
-                    {{ user.profile.expires_at }}
-                </div>
-              </div>
-              <hr>
                 <div class="row">
                     <div class="col-sm-3">
                         <h6 class="mb-0">Preferences</h6>
@@ -157,7 +131,7 @@
                         </div>
                     </div>
                 </div>
-
+                <hr>
             </div>
 
 
@@ -172,6 +146,24 @@
             </div>
           </div>
 
+                  <div class="card mt-3 bg-dark ">
+
+    <ul class="list-group list-group-flush">
+      <li class="list-group-item bg-dark d-flex justify-content-between align-items-center flex-wrap">
+        <h6 class="mb-0 text-white">Access Token</h6>
+        <span class="text-white-50">{{ user.profile.access_token }}</span>
+      </li>
+      <li class="list-group-item bg-dark d-flex justify-content-between align-items-center flex-wrap">
+        <h6 class="mb-0 text-white">
+        Refresh Token</h6>
+        <span class="text-white-50">{{ user.profile.refresh_token }}</span>
+      </li>
+      <li class="list-group-item bg-dark d-flex justify-content-between align-items-center flex-wrap">
+        <h6 class="mb-0 text-white">Expires At</h6>
+        <span class="text-white-50">{{ user.profile.expires_at }}</span>
+      </li>
+    </ul>
+  </div>
 
 
         </div>

+ 2 - 0
templates/base.html

@@ -84,9 +84,11 @@
                             <a class="nav-link" href="{% url 'manage_playlists' %}">Manage</a>
                         </li>
 
+                        <!--
                         <li class="nav-item">
                             <a class="nav-link" href="{% url 'settings' %}">Settings</a>
                         </li>
+                        -->
                     </ul>