-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTempCode.cs
138 lines (127 loc) · 5.35 KB
/
TempCode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using ClassTranscribeDatabase;
using ClassTranscribeDatabase.Models;
using ClassTranscribeDatabase.Services;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using TaskEngine.Tasks;
namespace TaskEngine
{
[SuppressMessage("Microsoft.Performance", "CA1812:MarkMembersAsStatic")] // This class is never directly instantiated
class TempCode
{
// Deletes all Videos which don't have a file or have an invalid file (size under 1000 bytes)
private readonly CTDbContext context;
private readonly CreateBoxTokenTask _createBoxTokenTask;
// private readonly UpdateBoxTokenTask _updateBoxTokenTask;
private readonly SceneDetectionTask _sceneDetectionTask;
private readonly PythonCrawlerTask _pythonCrawlerTask;
private readonly ProcessVideoTask _processVideoTask;
// private readonly GenerateVTTFileTask _generateVTTFileTask;
private readonly TranscriptionTask _transcriptionTask;
private readonly ConvertVideoToWavTask _convertVideoToWavTask;
private readonly DownloadMediaTask _downloadMediaTask;
private readonly DownloadPlaylistInfoTask _downloadPlaylistInfoTask;
private readonly RpcClient _rpcClient;
private readonly QueueAwakerTask _queueAwakerTask;
private readonly CleanUpElasticIndexTask _cleanUpElasticIndexTask;
public TempCode(CTDbContext c, CreateBoxTokenTask createBoxTokenTask, //UpdateBoxTokenTask updateBoxTokenTask,
SceneDetectionTask ePubGeneratorTask, ProcessVideoTask processVideoTask,
TranscriptionTask transcriptionTask, ConvertVideoToWavTask convertVideoToWavTask, DownloadMediaTask downloadMediaTask,
DownloadPlaylistInfoTask downloadPlaylistInfoTask, QueueAwakerTask queueAwakerTask,
CleanUpElasticIndexTask cleanUpElasticIndexTask, RpcClient rpcClient,
PythonCrawlerTask pythonCrawlerTask)
{
context = c;
_createBoxTokenTask = createBoxTokenTask;
// _updateBoxTokenTask = updateBoxTokenTask;
_sceneDetectionTask = ePubGeneratorTask;
_processVideoTask = processVideoTask;
// _generateVTTFileTask = generateVTTFileTask;
_transcriptionTask = transcriptionTask;
_convertVideoToWavTask = convertVideoToWavTask;
_downloadMediaTask = downloadMediaTask;
_downloadPlaylistInfoTask = downloadPlaylistInfoTask;
_queueAwakerTask = queueAwakerTask;
_rpcClient = rpcClient;
_cleanUpElasticIndexTask = cleanUpElasticIndexTask;
_pythonCrawlerTask = pythonCrawlerTask;
}
public void CleanUpInvalidVideos()
{
var incompleteVideos = context.Videos.Select(v => new
{
Length = File.Exists(v.Video1.Path) ? new System.IO.FileInfo(v.Video1.Path).Length : -1,
v.Video1.Path,
Video = v
}).ToList().Where(v => v.Length < 1000).OrderBy(v => v.Length).Select(v => new { v.Video, v.Length }).ToList();
foreach (var item in incompleteVideos)
{
if (File.Exists(item.Video.Video1.Path))
{
File.Delete(item.Video.Video1.Path);
}
context.FileRecords.Remove(item.Video.Video1);
if (item.Video.Video2 != null)
{
if (File.Exists(item.Video.Video2.Path))
{
File.Delete(item.Video.Video2.Path);
}
context.FileRecords.Remove(item.Video.Video2);
}
if (item.Video.Audio != null)
{
if (File.Exists(item.Video.Audio.Path))
{
File.Delete(item.Video.Audio.Path);
}
context.FileRecords.Remove(item.Video.Audio);
}
context.Videos.Remove(item.Video);
}
context.SaveChanges();
}
public void UpdateMediaNames()
{
List<Media> medias;
medias = context.Medias.ToList();
foreach (Media media in medias)
{
media.Name = CommonUtils.GetMediaName(media);
Console.WriteLine(media.Name);
}
context.SaveChanges();
}
public void Temp()
{
TempAsync().GetAwaiter().GetResult();
}
private async Task TempAsync()
{
// A dummy awaited function call.
await Task.Delay(0);
// Add any temporary code
_cleanUpElasticIndexTask.Publish("");
}
private async Task TestYoutubeChannelDownload()
{
Playlist p = new Playlist
{
JsonMetadata = new JObject
{
{"isChannel","1" }
},
PlaylistIdentifier = "UCi8e0iOVk1fEOogdfu4YgfA" // change me - too many videos
};
context.Playlists.Add(p);
await context.SaveChangesAsync();
//p.Id = "72336862-244c-4904-a753-2f620ae99633";
_downloadPlaylistInfoTask.Publish(p.Id);
}
}
}