add playlist_index and playlist_title as media format options, fix paths for files in media format subdirs post download, resolves #13

pull/29/head
meeb 2020-12-19 17:33:08 +11:00
parent 1b092fe955
commit 97fa62d12b
5 changed files with 1226 additions and 8 deletions

1183
tubesync/spam Normal file

File diff suppressed because it is too large Load Diff

View File

@ -385,6 +385,8 @@ class Source(models.Model):
'title_full': 'Some Media Title Name', 'title_full': 'Some Media Title Name',
'key': 'SoMeUnIqUiD', 'key': 'SoMeUnIqUiD',
'format': '-'.join(fmt), 'format': '-'.join(fmt),
'playlist_index': 1,
'playlist_title': 'Some Playlist Title',
'ext': self.extension, 'ext': self.extension,
'resolution': self.source_resolution if self.source_resolution else '', 'resolution': self.source_resolution if self.source_resolution else '',
'height': '720' if self.source_resolution else '', 'height': '720' if self.source_resolution else '',
@ -398,7 +400,7 @@ class Source(models.Model):
def get_example_media_format(self): def get_example_media_format(self):
try: try:
return self.media_format.format(**self.example_media_format_dict) return self.media_format.format(**self.example_media_format_dict)
except Exception: except Exception as e:
return '' return ''
def index_media(self): def index_media(self):
@ -514,7 +516,16 @@ class Media(models.Model):
Source.SOURCE_TYPE_YOUTUBE_CHANNEL_ID: 'dislike_count', Source.SOURCE_TYPE_YOUTUBE_CHANNEL_ID: 'dislike_count',
Source.SOURCE_TYPE_YOUTUBE_PLAYLIST: 'dislike_count', Source.SOURCE_TYPE_YOUTUBE_PLAYLIST: 'dislike_count',
}, },
'playlist_index': {
Source.SOURCE_TYPE_YOUTUBE_CHANNEL: 'playlist_index',
Source.SOURCE_TYPE_YOUTUBE_CHANNEL_ID: 'playlist_index',
Source.SOURCE_TYPE_YOUTUBE_PLAYLIST: 'playlist_index',
},
'playlist_title': {
Source.SOURCE_TYPE_YOUTUBE_CHANNEL: 'playlist_title',
Source.SOURCE_TYPE_YOUTUBE_CHANNEL_ID: 'playlist_title',
Source.SOURCE_TYPE_YOUTUBE_PLAYLIST: 'playlist_title',
},
} }
STATE_UNKNOWN = 'unknown' STATE_UNKNOWN = 'unknown'
STATE_SCHEDULED = 'scheduled' STATE_SCHEDULED = 'scheduled'
@ -853,6 +864,8 @@ class Media(models.Model):
'title_full': self.title, 'title_full': self.title,
'key': self.key, 'key': self.key,
'format': '-'.join(display_format['format']), 'format': '-'.join(display_format['format']),
'playlist_index': self.playlist_index,
'playlist_title': self.playlist_title,
'ext': self.source.extension, 'ext': self.source.extension,
'resolution': display_format['resolution'], 'resolution': display_format['resolution'],
'height': display_format['height'], 'height': display_format['height'],
@ -954,11 +967,18 @@ class Media(models.Model):
field = self.get_metadata_field('formats') field = self.get_metadata_field('formats')
return self.loaded_metadata.get(field, []) return self.loaded_metadata.get(field, [])
@property
def playlist_index(self):
field = self.get_metadata_field('playlist_index')
return self.loaded_metadata.get(field, 0)
@property
def playlist_title(self):
field = self.get_metadata_field('playlist_title')
return self.loaded_metadata.get(field, '')
@property @property
def filename(self): def filename(self):
# If a media_file has been downloaded use its existing name
if self.media_file:
return os.path.basename(self.media_file.name)
# Otherwise, create a suitable filename from the source media_format # Otherwise, create a suitable filename from the source media_format
media_format = str(self.source.media_format) media_format = str(self.source.media_format)
media_details = self.format_dict media_details = self.format_dict
@ -986,9 +1006,6 @@ class Media(models.Model):
@property @property
def directory_path(self): def directory_path(self):
# If a media_file has been downloaded use its existing directory
if self.media_file:
return os.path.dirname(self.media_file.name)
# Otherwise, create a suitable filename from the source media_format # Otherwise, create a suitable filename from the source media_format
media_format = str(self.source.media_format) media_format = str(self.source.media_format)
media_details = self.format_dict media_details = self.format_dict

View File

@ -63,6 +63,16 @@
<td>Media format string</td> <td>Media format string</td>
<td>720p-avc1-mp4a</td> <td>720p-avc1-mp4a</td>
</tr> </tr>
<tr>
<td>{playlist_index}</td>
<td>Playlist index of media, if it's in a playlist</td>
<td>12</td>
</tr>
<tr>
<td>{playlist_title}</td>
<td>Playlist title of media, if it's in a playlist</td>
<td>Some Playlist</td>
</tr>
<tr> <tr>
<td>{ext}</td> <td>{ext}</td>
<td>File extension</td> <td>File extension</td>

View File

@ -9,6 +9,8 @@
"average_rating": 1.2345, "average_rating": 1.2345,
"dislike_count": 123, "dislike_count": 123,
"like_count": 456, "like_count": 456,
"playlist_index": 789,
"playlist_title": "test playlist",
"uploader": "test uploader", "uploader": "test uploader",
"categories":[ "categories":[
"test category 1", "test category 1",

View File

@ -532,6 +532,12 @@ class FilepathTestCase(TestCase):
self.source.media_format = 'test-{format}' self.source.media_format = 'test-{format}'
self.assertEqual(self.source.get_example_media_format(), self.assertEqual(self.source.get_example_media_format(),
'test-1080p-vp9-opus') 'test-1080p-vp9-opus')
self.source.media_format = 'test-{playlist_index}'
self.assertEqual(self.source.get_example_media_format(),
'test-1')
self.source.media_format = 'test-{playlist_title}'
self.assertEqual(self.source.get_example_media_format(),
'test-Some Playlist Title')
self.source.media_format = 'test-{ext}' self.source.media_format = 'test-{ext}'
self.assertEqual(self.source.get_example_media_format(), self.assertEqual(self.source.get_example_media_format(),
'test-' + self.source.extension) 'test-' + self.source.extension)