{% extends 'base.html' %}{% load static %}

{% block headtitle %}Media - {{ media.key }}{% endblock %}

{% block content %}
<div class="row">
  <div class="col s12">
    <h1 class="truncate">Media <strong>{{ media.key }}</strong> {{ download_state_icon|safe }}</h1>
    {% if media.title %}<h2 class="truncate"><strong>{{ media.title }}</strong></h2>{% endif %}
    <p class="truncate"><strong><a href="{{ media.url }}" target="_blank"><i class="fas fa-link"></i> {{ media.url }}</a></strong></p>
    <p class="truncate">Downloading to: <strong>{{ media.source.directory_path }}</strong></p>
  </div>
</div>
{% if not media.can_download %}{% include 'errorbox.html' with message='Media cannot be downloaded because it has no formats which match the source requirements.' %}{% endif %}
{% if media.skip %}{% include 'errorbox.html' with message='Media is marked to be skipped and will not be downloaded.' %}{% endif %}
{% include 'infobox.html' with message=message %}
<div class="row">
  <div class="col s12 m7">
    <div><i class="fas fa-quote-left"></i></div>
    <p>{% if media.description %}{{ media.description|truncatewords:200 }}{% else %}(Media has no description).{% endif %}</p>
    <div class="right-align"><i class="fas fa-quote-right"></i></div>
  </div>
  <div class="col s12 m5">
    <div class="card mediacard">
      <div class="card-image">
        <img src="{% if media.thumb %}{% url 'sync:media-thumb' pk=media.pk %}{% else %}{% static 'images/nothumb.png' %}{% endif %}">
      </div>
    </div>
  </div>
</div>
{% if task %}
<div class="row">
  <div class="col s12">
    <div class="collection">
      <span class="collection-item">
        {% if task.locked_by_pid_running %}
        <i class="fas fa-running"></i> <strong>{{ task }}</strong><br>
        <i class="far fa-clock"></i> Task started at <strong>{{ task.run_at|date:'Y-m-d H:i:s' }}</strong>
        {% else %}
        <i class="fas fa-stopwatch"></i> <strong>{{ task }}</strong><br>
        <i class="fas fa-redo"></i> Task will run {% if task.run_now %}<strong>immediately</strong>{% else %}at <strong>{{ task.run_at|date:'Y-m-d H:i:s' }}</strong>{% endif %}
        {% endif %}
      </span>
    </div>
  </div>
</div>
{% endif %}
<div class="row">
  <div class="col s12">
    <table class="striped">
      <tr title="The media source">
        <td class="hide-on-small-only">Source</td>
        <td><span class="hide-on-med-and-up">Source<br></span><strong><a href="{% url 'sync:source' pk=media.source.pk %}">{{ media.source }}</a></strong></td>
      </tr>
      <tr title="The media duration">
        <td class="hide-on-small-only">Duration</td>
        <td><span class="hide-on-med-and-up">Duration<br></span><strong>{{ media.duration_formatted }}</strong></td>
      </tr>
      <tr title="The desired format">
        <td class="hide-on-small-only">Desired format</td>
        <td><span class="hide-on-med-and-up">Desired format<br></span><strong>{{ media.source.format_summary }}</strong></td>
      </tr>
      <tr title="Fallback setting on the source">
        <td class="hide-on-small-only">Fallback</td>
        <td><span class="hide-on-med-and-up">Fallback<br></span><strong>{{ media.source.get_fallback_display }}</strong></td>
      </tr>
      {% if not media.source.download_media %}
      <tr title="Is media marked to be downloaded at the source?">
        <td class="hide-on-small-only">Source download?</td>
        <td><span class="hide-on-med-and-up">Source download?<br></span><strong>{% if media.source.download_media %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      {% endif %}
      {% if media.skip %}
      <tr title="Is the media marked to be skipped?">
        <td class="hide-on-small-only">Skipping?</td>
        <td><span class="hide-on-med-and-up">Skipping?<br></span><strong>{% if media.skip %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      {% else %}
      <tr title="Has the media been downloaded?">
        <td class="hide-on-small-only">Downloaded?</td>
        <td><span class="hide-on-med-and-up">Downloaded?<br></span><strong>{% if media.downloaded %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      {% endif %}
      {% if media.downloaded %}
      <tr title="The filename the media will be downloaded as">
        <td class="hide-on-small-only">Filename</td>
        <td><span class="hide-on-med-and-up">Filename<br></span><strong>{{ media.filename }}</strong></td>
      </tr>
      <tr title="The filename the media will be downloaded as">
        <td class="hide-on-small-only">Directory</td>
        <td><span class="hide-on-med-and-up">Directory<br></span><strong>{{ media.directory_path }}</strong></td>
      </tr>
      <tr title="Size of the file on disk">
        <td class="hide-on-small-only">File size</td>
        <td><span class="hide-on-med-and-up">File size<br></span><strong>{{ media.downloaded_filesize|filesizeformat }}</strong></td>
      </tr>
      <tr title="Codecs used in the downloaded file">
        <td class="hide-on-small-only">Downloaded codecs</td>
        <td><span class="hide-on-med-and-up">Downloaded codecs<br></span><strong>audio:{{ media.downloaded_audio_codec }}{% if media.downloaded_video_codec %}, video:{{ media.downloaded_video_codec }}{% endif %}</strong></td>
      </tr>
      <tr title="Container file format used in the download file">
        <td class="hide-on-small-only">Container</td>
        <td><span class="hide-on-med-and-up">Container<br></span><strong>{{ media.downloaded_container|upper }}</strong></td>
      </tr>
      {% if media.downloaded_video_codec %}
      <tr title="Frames per second in the downloaded file">
        <td class="hide-on-small-only">Downloaded FPS</td>
        <td><span class="hide-on-med-and-up">Downloaded FPS<br></span><strong>{{ media.downloaded_fps }} FPS</strong></td>
      </tr>
      <tr title="Does the downloaded file have high dynamic range?">
        <td class="hide-on-small-only">Downloaded HDR?</td>
        <td><span class="hide-on-med-and-up">Downloaded HDR?<br></span><strong>{% if media.downloaded_hdr %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      {% endif %}
      {% else %}
      <tr title="Can the media be downloaded?">
        <td class="hide-on-small-only">Can download?</td>
        <td><span class="hide-on-med-and-up">Can download?<br></span><strong>{% if media.can_download %}<i class="fas fa-check"></i>{% else %}<i class="fas fa-times"></i>{% endif %}</strong></td>
      </tr>
      {% endif %}
      <tr title="The available media formats">
        <td class="hide-on-small-only">Available formats</td>
        <td><span class="hide-on-med-and-up">Available formats<br></span>
          {% for format in media.formats %}
          <div>
            ID: <strong>{{ format.format_id }}</strong>
            {% if format.vcodec|lower != 'none' %}, {{ format.format_note }} ({{ format.width }}x{{ format.height }}), fps:{{ format.fps|lower }}, video:{{ format.vcodec }} @{{ format.tbr }}k{% endif %}
            {% if format.acodec|lower != 'none' %}, audio:{{ format.acodec }} @{{ format.abr }}k / {{ format.asr }}Hz{% endif %}
            {% if format.format_id == combined_format or format.format_id == audio_format or format.format_id == video_format %}<strong>(matched)</strong>{% endif %}
          </div>
          {% empty %}
          Media has no indexed available formats
          {% endfor %}
        </td>
      </tr>
      <tr title="Best available format for source requirements">
        <td class="hide-on-small-only">Matched formats</td>
        <td><span class="hide-on-med-and-up">Matched formats<br></span>
          Combined: <strong>{% if combined_format %}{{ combined_format }} {% if combined_exact %}(exact match){% else %}(fallback){% endif %}{% else %}no match{% endif %}</strong><br>
          Audio: <strong>{% if audio_format %}{{ audio_format }} {% if audio_exact %}(exact match){% else %}(fallback){% endif %}{% else %}no match{% endif %}</strong><br>
          Video: <strong>{% if video_format %}{{ video_format }} {% if video_exact %}(exact match){% else %}(fallback){% endif %}{% else %}no match{% endif %}
        </strong></td>
      </tr>
    </table>
  </div>
</div>
{% if media.downloaded %}
<div class="row">
  <div class="col s12 l6">
    <a href="{% url 'sync:redownload-media' pk=media.pk %}" class="btn">Redownload media <i class="fas fa-cloud-download-alt"></i></a>
  </div>
  <div class="col s12 l6">
    <a href="{% url 'sync:skip-media' pk=media.pk %}" class="btn delete-button">Delete and skip media <i class="fas fa-times-circle"></i></a>
  </div>
</div>
{% else %}
<div class="row">
  <div class="col s12">
    {% if media.skip %}
      <a href="{% url 'sync:enable-media' pk=media.pk %}" class="btn">Enable (unskip) media <i class="fas fa-cloud-download-alt"></i></a>
    {% else %}
      <a href="{% url 'sync:skip-media' pk=media.pk %}" class="btn delete-button">Skip media <i class="fas fa-times-circle"></i></a>
    {% endif %}
  </div>
</div>
{% endif %}
{% endblock %}
