Skip to content

Commit

Permalink
Merge pull request #343 from ArabCoders/master
Browse files Browse the repository at this point in the history
Added support for showing when live stream will start as error message
  • Loading branch information
alexta69 authored Nov 16, 2023
2 parents b30d7d3 + add2a04 commit 9ef37c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 14 additions & 2 deletions app/ytdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import re
from dl_formats import get_format, get_opts, AUDIO_FORMATS
from datetime import datetime

log = logging.getLogger('ytdl')

Expand All @@ -28,7 +29,7 @@ async def cleared(self, id):
raise NotImplementedError

class DownloadInfo:
def __init__(self, id, title, url, quality, format, folder, custom_name_prefix):
def __init__(self, id, title, url, quality, format, folder, custom_name_prefix, error):
self.id = id if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{id}'
self.title = title if len(custom_name_prefix) == 0 else f'{custom_name_prefix}.{title}'
self.url = url
Expand All @@ -38,6 +39,7 @@ def __init__(self, id, title, url, quality, format, folder, custom_name_prefix):
self.custom_name_prefix = custom_name_prefix
self.status = self.msg = self.percent = self.speed = self.eta = None
self.timestamp = time.time_ns()
self.error = error

class Download:
manager = None
Expand Down Expand Up @@ -86,6 +88,7 @@ def put_status_postprocessor(d):
'outtmpl': { "default": self.output_template, "chapter": self.output_template_chapter },
'format': self.format,
'socket_timeout': 30,
'ignore_no_formats_error': True,
'progress_hooks': [put_status],
'postprocessor_hooks': [put_status_postprocessor],
**self.ytdl_opts,
Expand Down Expand Up @@ -216,6 +219,7 @@ def __extract_info(self, url):
'quiet': True,
'no_color': True,
'extract_flat': True,
'ignore_no_formats_error': True,
**self.config.YTDL_OPTIONS,
}).extract_info(url, download=False)

Expand Down Expand Up @@ -246,6 +250,14 @@ async def __add_entry(self, entry, quality, format, folder, custom_name_prefix,
if not entry:
return {'status': 'error', 'msg': "Invalid/empty data was given."}

error = None
if "live_status" in entry and "release_timestamp" in entry and entry.get("live_status") == "is_upcoming":
dt_ts = datetime.fromtimestamp(entry.get("release_timestamp")).strftime('%Y-%m-%d %H:%M:%S %z')
error = f"Live stream is scheduled to start at {dt_ts}"
else:
if "msg" in entry:
error = entry["msg"]

etype = entry.get('_type') or 'video'
if etype == 'playlist':
entries = entry['entries']
Expand All @@ -264,7 +276,7 @@ async def __add_entry(self, entry, quality, format, folder, custom_name_prefix,
return {'status': 'ok'}
elif etype == 'video' or etype.startswith('url') and 'id' in entry and 'title' in entry:
if not self.queue.exists(entry['id']):
dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'], quality, format, folder, custom_name_prefix)
dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'], quality, format, folder, custom_name_prefix, error)
dldirectory, error_message = self.__calc_download_path(quality, format, folder)
if error_message is not None:
return error_message
Expand Down
10 changes: 7 additions & 3 deletions ui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,18 @@
<fa-icon *ngIf="download.value.status == 'finished'" [icon]="faCheckCircle" class="text-success"></fa-icon>
<fa-icon *ngIf="download.value.status == 'error'" [icon]="faTimesCircle" class="text-danger"></fa-icon>
</div>
<span ngbTooltip="{{download.value.msg}}"><a *ngIf="!!download.value.filename; else noDownloadLink" href="{{buildDownloadLink(download.value)}}" target="_blank">{{ download.value.title }}</a></span>
<ng-template #noDownloadLink>{{ download.value.title }}</ng-template>
<span ngbTooltip="{{download.value.msg}} | {{download.value.error}}"><a *ngIf="!!download.value.filename; else noDownloadLink" href="{{buildDownloadLink(download.value)}}" target="_blank">{{ download.value.title }}</a></span>
<ng-template #noDownloadLink>
{{download.value.title}}
<span *ngIf="download.value.msg"><br>{{download.value.msg}}</span>
<span *ngIf="download.value.error"><br>Error: {{download.value.error}}</span>
</ng-template>
</td>
<td>
<button *ngIf="download.value.status == 'error'" type="button" class="btn btn-link" (click)="retryDownload(download.key, download.value)"><fa-icon [icon]="faRedoAlt"></fa-icon></button>
</td>
<td>
<a *ngIf="!!download.value.filename; else noDownloadLink" href="{{buildDownloadLink(download.value)}}" download><fa-icon [icon]="faDownload"></fa-icon></a>
<a *ngIf="download.value.filename" href="{{buildDownloadLink(download.value)}}" download><fa-icon [icon]="faDownload"></fa-icon></a>
</td>
<td>
<a href="{{download.value.url}}" target="_blank"><fa-icon [icon]="faExternalLinkAlt"></fa-icon></a>
Expand Down

0 comments on commit 9ef37c2

Please sign in to comment.