Skip to content

Commit

Permalink
Merge pull request #523 from FaySmash/tweaked
Browse files Browse the repository at this point in the history
Add support for indexing Streams
  • Loading branch information
meeb authored Aug 7, 2024
2 parents 7d9f200 + 963cae7 commit 9fc98c7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 15 deletions.
20 changes: 20 additions & 0 deletions tubesync/sync/migrations/0025_add_video_type_support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.db import migrations, models

class Migration(migrations.Migration):

dependencies = [
('sync', '0024_auto_20240717_1535'),
]

operations = [
migrations.AddField(
model_name='source',
name='index_videos',
field=models.BooleanField(default=True, help_text='Index video media from this source', verbose_name='index videos'),
),
migrations.AddField(
model_name='source',
name='index_streams',
field=models.BooleanField(default=False, help_text='Index live stream media from this source', verbose_name='index streams'),
),
]
46 changes: 32 additions & 14 deletions tubesync/sync/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ class Source(models.Model):
}
# Format used to create indexable URLs
INDEX_URLS = {
SOURCE_TYPE_YOUTUBE_CHANNEL: 'https://www.youtube.com/c/{key}/videos',
SOURCE_TYPE_YOUTUBE_CHANNEL_ID: 'https://www.youtube.com/channel/{key}/videos',
SOURCE_TYPE_YOUTUBE_CHANNEL: 'https://www.youtube.com/c/{key}/{type}',
SOURCE_TYPE_YOUTUBE_CHANNEL_ID: 'https://www.youtube.com/channel/{key}/{type}',
SOURCE_TYPE_YOUTUBE_PLAYLIST: 'https://www.youtube.com/playlist?list={key}',
}
# Callback functions to get a list of media from the source
Expand Down Expand Up @@ -274,6 +274,16 @@ class IndexSchedule(models.IntegerChoices):
default=True,
help_text=_('Download media from this source, if not selected the source will only be indexed')
)
index_videos = models.BooleanField(
_('index videos'),
default=False,
help_text=_('Index video media from this source')
)
index_streams = models.BooleanField(
_('index streams'),
default=False,
help_text=_('Index live stream media from this source')
)
download_cap = models.IntegerField(
_('download cap'),
choices=CapChoices.choices,
Expand Down Expand Up @@ -475,17 +485,16 @@ def create_url(obj, source_type, key):
return url.format(key=key)

@classmethod
def create_index_url(obj, source_type, key):
def create_index_url(obj, source_type, key, type):
url = obj.INDEX_URLS.get(source_type)
return url.format(key=key)
return url.format(key=key, type=type)

@property
def url(self):
return Source.create_url(self.source_type, self.key)

@property
def index_url(self):
return Source.create_index_url(self.source_type, self.key)
def get_index_url(self, type):
return Source.create_index_url(self.source_type, self.key, type)

@property
def format_summary(self):
Expand Down Expand Up @@ -590,23 +599,32 @@ def is_regex_match(self, media_item_title):
return True
return bool(re.search(self.filter_text, media_item_title))

def index_media(self):
'''
Index the media source returning a list of media metadata as dicts.
'''
def get_index(self, type):
indexer = self.INDEXERS.get(self.source_type, None)
if not callable(indexer):
raise Exception(f'Source type f"{self.source_type}" has no indexer')
response = indexer(self.index_url)
response = indexer(self.get_index_url(type=type))
if not isinstance(response, dict):
return []
entries = response.get('entries', [])
entries = response.get('entries', [])
return entries

def index_media(self):
'''
Index the media source returning a list of media metadata as dicts.
'''
entries = list()
if self.index_videos:
entries += self.get_index('videos')
# Playlists do something different that I have yet to figure out
if self.source_type != Source.SOURCE_TYPE_YOUTUBE_PLAYLIST:
if self.index_streams:
entries += self.get_index('streams')

if settings.MAX_ENTRIES_PROCESSING:
entries = entries[:settings.MAX_ENTRIES_PROCESSING]
return entries


def get_media_thumb_path(instance, filename):
fileid = str(instance.uuid)
filename = f'{fileid.lower()}.jpg'
Expand Down
8 changes: 8 additions & 0 deletions tubesync/sync/templates/sync/source.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ <h1 class="truncate">Source <strong>{{ source.name }}</strong></h1>
<td class="hide-on-small-only">Index schedule</td>
<td><span class="hide-on-med-and-up">Index schedule<br></span><strong>{{ source.get_index_schedule_display }}</strong></td>
</tr>
<tr title="Index videos from this source">
<td class="hide-on-small-only">Index videos?</td>
<td><span class="hide-on-med-and-up">Index videos?<br></span><strong>{% if source.index_videos %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
</tr>
<tr title="Index streams from this source">
<td class="hide-on-small-only">Index streams?</td>
<td><span class="hide-on-med-and-up">Index streams?<br></span><strong>{% if source.index_streams %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
</tr>
<tr title="Download media from this source">
<td class="hide-on-small-only">Download media?</td>
<td><span class="hide-on-med-and-up">Download media?<br></span><strong>{% if source.download_media %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
Expand Down
2 changes: 1 addition & 1 deletion tubesync/sync/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def get_success_url(self):
class EditSourceMixin:
model = Source
fields = ('source_type', 'key', 'name', 'directory', 'filter_text', 'filter_text_invert', 'filter_seconds', 'filter_seconds_min',
'media_format', 'index_schedule', 'download_media', 'download_cap', 'delete_old_media',
'media_format', 'index_schedule', 'index_videos', 'index_streams', 'download_media', 'download_cap', 'delete_old_media',
'delete_removed_media', 'days_to_keep', 'source_resolution', 'source_vcodec',
'source_acodec', 'prefer_60fps', 'prefer_hdr', 'fallback', 'copy_channel_images',
'delete_removed_media', 'delete_files_on_disk', 'days_to_keep', 'source_resolution',
Expand Down

0 comments on commit 9fc98c7

Please sign in to comment.