add duration_seconds key to items with duration (closes #215)

This commit is contained in:
sigma67 2022-01-01 19:54:42 +01:00
commit 3436f2dcc4
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
9 changed files with 200 additions and 197 deletions

View file

@ -1,4 +1,5 @@
from .utils import *
from ..helpers import parse_duration
from .songs import *
from typing import List
@ -77,6 +78,7 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
}
if duration:
song['duration'] = duration
song['duration_seconds'] = parse_duration(duration)
if setVideoId:
song['setVideoId'] = setVideoId
if feedback_tokens:

View file

@ -1,4 +1,5 @@
from .utils import *
from ..helpers import parse_duration
import re
@ -30,7 +31,8 @@ def parse_song_runs(runs):
if 'navigationEndpoint' in run: # artist or album
item = {'name': text, 'id': nav(run, NAVIGATION_BROWSE_ID, True)}
if item['id'] and (item['id'].startswith('MPRE') or "release_detail" in item['id']): # album
if item['id'] and (item['id'].startswith('MPRE')
or "release_detail" in item['id']): # album
parsed['album'] = item
else: # artist
parsed['artists'].append(item)
@ -42,6 +44,7 @@ def parse_song_runs(runs):
elif re.match(r"^(\d+:)*\d+:\d+$", text):
parsed['duration'] = text
parsed['duration_seconds'] = parse_duration(text)
elif re.match(r"^\d{4}$", text):
parsed['year'] = text

View file

@ -24,13 +24,12 @@ def parse_uploaded_items(results):
'videoId': videoId,
'title': title,
'duration': duration,
'artists': None,
'album': None,
'duration_seconds': parse_duration(duration),
'artists': parse_song_artists(data, 1),
'album': parse_song_album(data, 2),
'likeStatus': like,
'thumbnails': thumbnails
}
song['artists'] = parse_song_artists(data, 1)
song['album'] = parse_song_album(data, 2)
songs.append(song)