Procházet zdrojové kódy

[tasks] Fix scrobbling tasks

Colin Powell před 9 měsíci
rodič
revize
7c6c1cee6d

+ 4 - 4
vrobbler/apps/scrobbles/models.py

@@ -957,7 +957,7 @@ class Scrobble(TimeStampedModel):
 
         # GeoLocations are a special case scrobble
         if mtype == cls.MediaType.GEO_LOCATION:
-            logger.warn(
+            logger.warning(
                 f"[create_or_update] geoloc requires create_or_update_location"
             )
             scrobble = cls.create_or_update_location(
@@ -981,7 +981,7 @@ class Scrobble(TimeStampedModel):
             scrobble.can_be_updated
             or scrobble_data["playback_status"] == "stopped"
         ):
-            if "log" in scrobble_data.keys():
+            if "log" in scrobble_data.keys() and scrobble.log:
                 scrobble_data["log"] = scrobble.log | scrobble_data["log"]
             return scrobble.update(scrobble_data)
 
@@ -997,7 +997,8 @@ class Scrobble(TimeStampedModel):
             },
         )
 
-        return cls.create(scrobble_data)
+        scrobble = cls.create(scrobble_data)
+        return scrobble
 
     @classmethod
     def create_or_update_location(
@@ -1151,7 +1152,6 @@ class Scrobble(TimeStampedModel):
         cls,
         scrobble_data: dict,
     ) -> "Scrobble":
-        scrobble_data["log"] = {}
         scrobble = cls.objects.create(
             **scrobble_data,
         )

+ 2 - 3
vrobbler/apps/scrobbles/scrobblers.py

@@ -313,11 +313,11 @@ def manual_scrobble_task(url: str, user_id: int):
     if "shortcut" in url:
         source = "Shortcut"
         title = "Generic Shortcut task"
-        description = url.split("/")[-1]
+        description = " ".join(url.split("/")[-1].split("-")).capitalize
     if "todoist" in url:
         source = "Todoist"
         title = "Generic Todoist task"
-        description = url.split("-")[-1]
+        description = " ".join(url.split("/")[-1].split("-")[:-1]).capitalize
 
     task = Task.find_or_create(title)
 
@@ -337,7 +337,6 @@ def manual_scrobble_task(url: str, user_id: int):
             "media_type": Scrobble.MediaType.WEBPAGE,
         },
     )
-
     scrobble = Scrobble.create_or_update(task, user_id, scrobble_dict)
     return scrobble
 

+ 1 - 1
vrobbler/apps/scrobbles/views.py

@@ -44,7 +44,7 @@ from scrobbles.models import (
     RetroarchImport,
     Scrobble,
 )
-from scrobbles.scrobblers import manual_scrobble_from_url
+from scrobbles.scrobblers import *
 from scrobbles.tasks import (
     process_koreader_import,
     process_lastfm_import,

+ 1 - 0
vrobbler/apps/tasks/models.py

@@ -14,6 +14,7 @@ BNULL = {"blank": True, "null": True}
 
 @dataclass
 class TaskLogData(LongPlayLogData):
+    description: Optional[str] = None
     source_id: Optional[str] = None
     serial_scrobble_id: Optional[int] = None
     long_play_complete: Optional[bool] = None

+ 1 - 0
vrobbler/templates/base.html

@@ -290,6 +290,7 @@
                                 {% if scrobble.media_obj.primary_image_url %}<div style="float:left;padding-right:10px;padding-bottom:10px;"><img src="{{scrobble.media_obj.primary_image_url}}" /></div>{% endif %}
                                 <p><a href="{{scrobble.media_obj.get_absolute_url}}">{{scrobble.media_obj.title}}</a></p>
                                 {% if scrobble.media_obj.subtitle %}<p><em><a href="{{scrobble.media_obj.subtitle.get_absolute_url}}">{{scrobble.media_obj.subtitle}}</a></em></p>{% endif %}
+                                {% if scrobble.logdata.description %}<p><em>{{scrobble.logdata.description}}</em></p>{% endif %}
                                 <p><small>{{scrobble.timestamp|naturaltime}} from {{scrobble.source}}</small></p>
                                 <div class="progress-bar" style="margin-right:5px;">
                                     <span class="progress-bar-fill" style="width: {{scrobble.percent_played}}%;"></span>

+ 3 - 3
vrobbler/templates/tasks/task_detail.html

@@ -52,16 +52,16 @@
                 <thead>
                     <tr>
                         <th scope="col">Date</th>
+                        <th scope="col">Description</th>
                         <th scope="col">Source</th>
-                        <th scope="col">ID</th>
                     </tr>
                 </thead>
                 <tbody>
                     {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %}
                     <tr>
                         <td>{{scrobble.timestamp}}</td>
-                        <td>{{scrobble.media_obj.source}}</td>
-                        <td><a href="{{scrobble.source_url_for_user}}">{{scrobble.logdata.source_url_pattern.label}}</a></td>
+                        <td><a href="{{scrobble.source_url_for_user}}">{{scrobble.logdata.description}}</a></td>
+                        <td>{{scrobble.source}}</td>
                     </tr>
                     {% endfor %}
                 </tbody>