{% extends 'base.html' %}

{% block headtitle %}Source - {{ source.name }}{% endblock %}

{% block content %}
<div class="row no-margin-bottom">
  <div class="col s12">
    <h1 class="truncate">Source <strong>{{ source.name }}</strong></h1>
    <p class="truncate"><strong><a href="{{ source.url }}" target="_blank"><i class="fas fa-link"></i> {{ source.url }}</a></strong></p>
    <p class="truncate">Saving to: <strong>{{ source.directory_path }}</strong></p>
  </div>
</div>
<div class="row">
  <div class="col s12 l6 margin-bottom">
    <a href="{% url 'sync:media' %}?filter={{ source.pk }}" class="btn">View media<span class="hide-on-small-only"> linked to this source</span> <i class="fas fa-fw fa-film"></i></a>
  </div>
  <div class="col s12 l6 margin-bottom">
    <a href="{% url 'sync:tasks-completed' %}?filter={{ source.pk }}" class="btn">View tasks<span class="hide-on-small-only"> linked to this source</span> <i class="far fa-fw fa-clock"></i></a>
  </div>
</div>
{% include 'infobox.html' with message=message %}
{% if source.has_failed %}{% include 'errorbox.html' with message='This source has encountered permanent failures listed at the bottom of this page, check its settings' %}{% endif %}
<div class="row">
  <div class="col s12">
    <table class="striped">
      <tr title="The source type">
        <td class="hide-on-small-only">Type</td>
        <td><span class="hide-on-med-and-up">Type<br></span><strong>{{ source.get_source_type_display }}</strong></td>
      </tr>
      <tr title="Name of the souce in TubeSync for your reference">
        <td class="hide-on-small-only">Name</td>
        <td><span class="hide-on-med-and-up">Name<br></span><strong>{{ source.name }}</strong></td>
      </tr>
      <tr title="Number of media items downloaded for the source">
        <td class="hide-on-small-only">Media items</td>
        <td><span class="hide-on-med-and-up">Media items<br></span><strong><a href="{% url 'sync:media' %}?filter={{ source.pk }}">{{ media|length }}</a></strong></td>
      </tr>
      <tr title="Unique key of the source, such as the channel name or playlist ID">
        <td class="hide-on-small-only">Key</td>
        <td><span class="hide-on-med-and-up">Key<br></span><strong>{{ source.key }}</strong></td>
      </tr>
      <tr title="Directory the source will save media to">
        <td class="hide-on-small-only">Directory</td>
        <td><span class="hide-on-med-and-up">Directory<br></span><strong>{{ source.directory }}</strong></td>
      </tr>
      <tr title="Media file name format to use for saving files">
        <td class="hide-on-small-only">Media format</td>
        <td><span class="hide-on-med-and-up">Media format<br></span><strong>{{ source.media_format }}</strong></td>
      </tr>
      <tr title="Example file name for media format">
        <td class="hide-on-small-only">Example filename</td>
        <td><span class="hide-on-med-and-up">Example filename<br></span><strong>{{ source.get_example_media_format }}</strong></td>
      </tr>
      {% if source.download_cap > 0 %}
      <tr title="Do not download videos older than this cap">
        <td class="hide-on-small-only">Download cap</td>
        <td><span class="hide-on-med-and-up">Download cap<br></span><strong>{{ source.get_download_cap_display }}</strong></td>
      </tr>
      {% endif %}
      <tr title="Schedule of how often to index the source for new media">
        <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="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>
      </tr>
      <tr title="When then source was created locally in TubeSync">
        <td class="hide-on-small-only">Created</td>
        <td><span class="hide-on-med-and-up">Created<br></span><strong>{{ source.created|date:'Y-m-d H:i:s' }}</strong></td>
      </tr>
      <tr title="When the source last checked for available media">
        <td class="hide-on-small-only">Last crawl</td>
        <td><span class="hide-on-med-and-up">Last crawl<br></span><strong>{% if source.last_crawl %}{{ source.last_crawl|date:'Y-m-d H:i:s' }}{% else %}Never{% endif %}</strong></td>
      </tr>
      <tr title="Quality and type of media the source will attempt to sync">
        <td class="hide-on-small-only">Source resolution</td>
        <td><span class="hide-on-med-and-up">Source resolution<br></span><strong>{{ source.get_source_resolution_display }}</strong></td>
      </tr>
      {% if source.is_video %}
      <tr title="Preferred video codec to download">
        <td class="hide-on-small-only">Source video codec</td>
        <td><span class="hide-on-med-and-up">Source video codec<br></span><strong>{{ source.get_source_vcodec_display }}</strong></td>
      </tr>
      {% endif %}
      <tr title="Preferred audio codec to download">
        <td class="hide-on-small-only">Source audio codec</td>
        <td><span class="hide-on-med-and-up">Source audio codec<br></span><strong>{{ source.get_source_acodec_display }}</strong></td>
      </tr>
      <tr title="If available from the source media in 60FPS will be preferred">
        <td class="hide-on-small-only">Prefer 60FPS?</td>
        <td><span class="hide-on-med-and-up">Prefer 60FPS?<br></span><strong>{% if source.prefer_60fps %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      <tr title="If available from the source media in HDR will be preferred">
        <td class="hide-on-small-only">Prefer HDR?</td>
        <td><span class="hide-on-med-and-up">Prefer HDR?<br></span><strong>{% if source.prefer_hdr %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      <tr title="Output file extension">
        <td class="hide-on-small-only">Output extension</td>
        <td><span class="hide-on-med-and-up">Output extension<br></span><strong>{{ source.extension }}</strong></td>
      </tr>
      <tr title="What to do if your source resolution or codecs are unavailable">
        <td class="hide-on-small-only">Fallback</td>
        <td><span class="hide-on-med-and-up">Fallback<br></span><strong>{{ source.get_fallback_display }}</strong></td>
      </tr>
      <tr title="Should media thumbnails be copied over with the media?">
        <td class="hide-on-small-only">Copy thumbnails?</td>
        <td><span class="hide-on-med-and-up">Copy thumbnails?<br></span><strong>{% if source.copy_thumbnails %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      <tr title="Should an NFO file be written with the media?">
        <td class="hide-on-small-only">Write NFO?</td>
        <td><span class="hide-on-med-and-up">Write NFO?<br></span><strong>{% if source.write_nfo %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      <tr title="Should a JSON file be written with the media?">
        <td class="hide-on-small-only">Write JSON?</td>
        <td><span class="hide-on-med-and-up">Write JSON?<br></span><strong>{% if source.write_json %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      {% if source.delete_old_media and source.days_to_keep > 0 %}
      <tr title="Days after which your media from this source will be locally deleted">
        <td class="hide-on-small-only">Delete old media</td>
        <td><span class="hide-on-med-and-up">Delete old media<br></span><strong>After {{ source.days_to_keep }} days</strong></td>
      </tr>
      {% else %}
      <tr title="Media from this source will never be deleted">
        <td class="hide-on-small-only">Delete old media</td>
        <td><span class="hide-on-med-and-up">Delete old media<br></span><strong>No, keep forever</strong></td>
      </tr>
      {% endif %}
      <tr title="Unique ID used for this source in TubeSync">
        <td class="hide-on-small-only">UUID</td>
        <td><span class="hide-on-med-and-up">UUID<br></span><strong>{{ source.uuid }}</strong></td>
      </tr>
    </table>
  </div>
</div>
<div class="row no-margin-bottom padding-top">
  <div class="col s12 l6 margin-bottom">
    <a href="{% url 'sync:update-source' pk=source.pk %}" class="btn">Edit source <i class="fas fa-pen-square"></i></a>
  </div>
  <div class="col s12 l6 margin-bottom">
    <a href="{% url 'sync:delete-source' pk=source.pk %}" class="btn delete-button">Delete source <i class="fas fa-trash-alt"></i></a>
  </div>
</div>
{% if errors %}
<div class="row">
  <div class="col s12">
    <h2>Source has encountered {{ errors|length }} Error{{ errors|length|pluralize }}</h2>
    <div class="collection">
      {% for task in errors %}
        <span class="collection-item error-text">
          <i class="fas fa-exclamation-triangle"></i> <strong>{{ task.verbose_name }}</strong><br>
          Error: &quot;{{ task.error_message }}&quot;<br>
          <i class="far fa-clock"></i> Occured at <strong>{{ task.run_at|date:'Y-m-d H:i:s' }}</strong>
        </span>
      {% endfor %}
    </div>
  </div>
</div>
{% endif %}
{% endblock %}
