|
8 | 8 | from rest_framework import views as drf_views |
9 | 9 | from rest_framework.response import Response |
10 | 10 |
|
11 | | -from app import fork_services_podcast |
| 11 | +from app import fork_services_podcast, helpers |
12 | 12 | from app.forms import PodcastShowTrackerForm |
13 | 13 | from app.log_safety import safe_url |
14 | 14 | from app.models import PodcastEpisode, PodcastShow, PodcastShowTracker, Status |
@@ -174,20 +174,6 @@ class PodcastLookupView(drf_views.APIView): |
174 | 174 | # week in pocketcasts.lookup_by_itunes_id. |
175 | 175 | _FEED_CACHE_SECONDS = 15 * 60 |
176 | 176 |
|
177 | | - @staticmethod |
178 | | - def _format_duration(seconds): |
179 | | - """Format a duration in seconds as "1h 9m" or "46m". |
180 | | -
|
181 | | - Matches the format `podcast_views.py` sends for every already-imported |
182 | | - episode, so a preview episode's duration reads the same as a tracked |
183 | | - one's. |
184 | | - """ |
185 | | - if not seconds: |
186 | | - return "" |
187 | | - hours = seconds // 3600 |
188 | | - minutes = (seconds % 3600) // 60 |
189 | | - return f"{hours}h {minutes}m" if hours > 0 else f"{minutes}m" |
190 | | - |
191 | 177 | def _read_feed(self, itunes_id, itunes_data, rss_feed_url): |
192 | 178 | """Return (metadata, episodes) for a feed, caching the pair briefly.""" |
193 | 179 | cache_key = f"podcast_lookup_feed_{itunes_id}" |
@@ -215,7 +201,7 @@ def _feed_episodes(self, rss_feed_url): |
215 | 201 | { |
216 | 202 | "title": episode.get("title", ""), |
217 | 203 | "published": episode.get("published"), |
218 | | - "duration": self._format_duration(episode.get("duration")), |
| 204 | + "duration": helpers.seconds_to_hm(episode.get("duration")), |
219 | 205 | "duration_seconds": episode.get("duration"), |
220 | 206 | "episode_number": episode.get("episode_number"), |
221 | 207 | "season_number": episode.get("season_number"), |
|
0 commit comments