Skip to content

Commit 90d215c

Browse files
authored
Merge pull request #1228 from tcely/patch-6
Use media redownload to implement manual downloads
2 parents 7f0e673 + 49802fb commit 90d215c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

tubesync/sync/models/media__tasks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def download_finished(self, format_str, container, downloaded_filepath=None):
9393
media.download_date = timezone.now()
9494
media.downloaded_filesize = os.path.getsize(filepath)
9595
media.downloaded_container = container
96+
media.manual_skip = False
97+
media.skip = False
9698
if '+' in format_str:
9799
# Seperate audio and video streams
98100
vformat_code, aformat_code = format_str.split('+')

tubesync/sync/templates/sync/media-item.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h1 class="truncate">Media <strong>{{ media.key }}</strong> {{ download_state_ic
99
{% if media.title %}<h2 class="truncate"><strong>{{ media.title }}</strong></h2>{% endif %}
1010
<p class="truncate"><strong><a href="{{ media.url }}" target="_blank"><i class="fas fa-link"></i> {{ media.url }}</a></strong></p>
1111
<p class="truncate">Downloading to: <strong>{{ media.source.directory_path }}</strong></p>
12-
{% if not media.skip and download_state == 'downloaded' %}
12+
{% if download_state == 'downloaded' %}
1313
{% if media.source.is_audio %}
1414
<audio controls src="{% url 'sync:media-content' pk=media.pk %}"></audio>
1515
{% else %}
@@ -19,6 +19,8 @@ <h1 class="truncate">Media <strong>{{ media.key }}</strong> {{ download_state_ic
1919
{% endif %}
2020

2121
<p class="truncate"><a href="{% url 'sync:media-content' pk=media.pk %}" download="{{ media.filename }}"><strong><i class="fas fa-download"></i> Download</strong></a></p>
22+
{% elif media.can_download %}
23+
<p class="truncate"><a href="{% url 'sync:redownload-media' pk=media.pk %}{% querystring manual=True %}"><strong><i class="fas fa-download"></i> Begin Downloading</strong></a> (please be patient)</p>
2224
{% endif %}
2325
</div>
2426
</div>

tubesync/sync/views.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from .tasks import (
3434
map_task_to_instance, get_error_message,
3535
get_running_tasks, get_media_download_task, get_source_completed_tasks,
36-
check_source_directory_exists, index_source, download_media_image,
36+
check_source_directory_exists, index_source, download_media_image, download_media_file,
3737
)
3838
from .choices import (Val, MediaServerType, SourceResolution, IndexSchedule,
3939
YouTube_SourceType, youtube_long_source_types,
@@ -686,6 +686,20 @@ def dispatch(self, request, *args, **kwargs):
686686
return super().dispatch(request, *args, **kwargs)
687687

688688
def form_valid(self, form):
689+
# Try to download manually, when can_download was true
690+
media = self.object
691+
if media.can_download:
692+
TaskHistory.schedule(
693+
download_media_file,
694+
str(media.pk),
695+
override=True,
696+
priority=90,
697+
remove_duplicates=True,
698+
retries=3,
699+
retry_delay=600,
700+
vn_fmt=_('Downloading media (manually) for "{}"'),
701+
vn_args=(media.name,),
702+
)
689703
# If the thumbnail file exists on disk, delete it
690704
if self.object.thumb_file_exists:
691705
delete_file(self.object.thumb.path)

0 commit comments

Comments
 (0)