d7ca67e4520cc62bd32ba62f1c0d4e1e5392fb72
[audio.git] / src / youtube / tasks.py
1 import os
2 from archive.tasks import AudioFormatTask
3 from .models import YouTube
4
5
6 class YouTubeTask(AudioFormatTask):
7     ext = 'mkv'
8     prefix = 'youtube'
9
10     def encode(self, in_paths, out_path):
11         self.audiobook.project.youtube.prepare_file(in_paths, out_path)
12
13     def set_tags(self, audiobook, filename):
14         pass
15
16     @classmethod
17     def save(cls, audiobook, file_name):
18         """We do not save the video files."""
19         os.unlink(file_name)
20
21     def put(self, user, audiobook, filename):
22         audiobook.project.youtube.publish(audiobook, filename)
23
24     def get_source_file_paths(self, audiobook):
25         if not audiobook.youtube_volume:
26             paths = [audiobook.source_file.path]
27         else:
28             paths = [
29                 a.source_file.path
30                 for a in type(audiobook)
31                 .objects.filter(
32                     slug=audiobook.slug, youtube_volume=audiobook.youtube_volume
33                 )
34                 .order_by("index")
35             ]
36         if audiobook.project.info_flac:
37             paths.append(audiobook.project.info_flac.path)
38         return paths