File size: 3,853 Bytes
4bea261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import fs from 'fs';
import path from 'path';
import { createClient } from '@supabase/supabase-js';

// Parse .env manually
const envPath = path.resolve('.env');
if (!fs.existsSync(envPath)) {
  console.error("Error: .env file not found at", envPath);
  process.exit(1);
}

const envContent = fs.readFileSync(envPath, 'utf-8');
const env = {};
envContent.split('\n').forEach(line => {
  const trimmed = line.trim();
  if (trimmed.startsWith('#') || !trimmed) return;
  const match = trimmed.match(/^([^=]+)=(.*)$/);
  if (match) {
    env[match[1].trim()] = match[2].trim();
  }
});

const supabaseUrl = env.PUBLIC_SUPABASE_URL;
const supabaseAnonKey = env.PUBLIC_SUPABASE_ANON_KEY;

if (!supabaseUrl || !supabaseAnonKey) {
  console.error("Error: Supabase URL or Anon Key is missing in .env!");
  process.exit(1);
}

const supabase = createClient(supabaseUrl, supabaseAnonKey);

async function run() {
  try {
    const srtPath = "C:\\Users\\TXA3100\\Desktop\\VIETSUB\\sut_vi.srt";
    if (!fs.existsSync(srtPath)) {
      console.error("Error: SRT file not found at", srtPath);
      process.exit(1);
    }
    const srtContent = fs.readFileSync(srtPath, 'utf-8');

    console.log("Read SRT subtitle successfully. Length:", srtContent.length);

    const movie_json = {
      "_id": "fbi-part-one-id",
      "imdb": { "id": null },
      "lang": "Vietsub",
      "name": "FBI: Part One",
      "slug": "fbi-part-one",
      "time": "120 phút",
      "tmdb": { "id": null, "type": "movie", "season": 1, "vote_count": 0, "vote_average": 0 },
      "type": "single",
      "view": 0,
      "year": 2026,
      "actor": ["FBI Agents"],
      "notify": "",
      "status": "completed",
      "content": "Bộ phim hành động FBI Part One cực kỳ kịch tính và hấp dẫn, đi kèm hệ thống Storyboard dynamic youtube-style mượt mà và chất lượng đa luồng chất lượng cao.",
      "country": [{ "id": "usa", "name": "Mỹ", "slug": "my" }],
      "created": { "time": "2026-05-18T14:40:00.000Z" },
      "quality": "HD",
      "category": [{ "id": "action", "name": "Hành Động", "slug": "hanh-dong" }],
      "chieurap": false,
      "director": ["FBI Directors"],
      "modified": { "time": "2026-05-18T14:40:00.000Z" },
      "showtimes": "",
      "thumb_url": "https://phimimg.com/upload/vod/20260307-1/81572d43eddf1dc784f3f53f6323f46d.jpg",
      "poster_url": "https://phimimg.com/upload/vod/20260307-1/7e5b11b1d5ce3514f6d62787d164b816.jpg",
      "origin_name": "FBI Part One",
      "trailer_url": "",
      "is_copyright": false,
      "sub_docquyen": false,
      "episode_total": "1",
      "episode_current": "Full"
    };

    const episodes_json = [
      {
        "server_name": "Cloudflare R2 Premium",
        "server_data": [
          {
            "name": "Full Movie",
            "slug": "full-movie",
            "filename": "FBI Part One - Full HD - Vietsub",
            "link_m3u8": "https://tphimx-r2-proxy.txagt145.workers.dev/fbi-part-one/master.m3u8",
            "link_embed": "https://tphimx-r2-proxy.txagt145.workers.dev/fbi-part-one/master.m3u8",
            "subtitles_srt": srtContent
          }
        ]
      }
    ];

    console.log("Upserting movie record to public.movies for slug 'fbi-part-one'...");
    
    const { data, error } = await supabase
      .from('movies')
      .upsert({
        slug: 'fbi-part-one',
        movie: movie_json,
        episodes: episodes_json,
        updated_at: new Date().toISOString()
      })
      .select();

    if (error) {
      throw error;
    }

    console.log("Success! Movie 'fbi-part-one' has been successfully registered/updated with SRT subtitles.");
    console.log("Result rows:", data ? data.length : 0);

  } catch (err) {
    console.error("Error executing database upsert:", err);
    process.exit(1);
  }
}

run();