-
Notifications
You must be signed in to change notification settings - Fork 0
/
plexize_test.go
725 lines (705 loc) · 16.8 KB
/
plexize_test.go
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
package main
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestParse(t *testing.T) {
ts := []struct {
n string
m, y, s, e, en string
}{
{
"[ www.Speed.cd ] -Sons.of.Anarchy.S07E07.720p.HDTV.X264-DIMENSION",
"Sons Of Anarchy", "", "07", "07", "",
},
{
"[@Difilm] The.Hot.Spot.1990.480p.BluRay.HardSub",
"The Hot Spot", "1990", "", "", "",
},
{
"[@MovieSpecial] Wild.Things.1998.BRRip.HardSub",
"Wild Things", "1998", "", "", "",
},
{
"[720pMkv.Com]_sons.of.anarchy.s05e10.480p.BluRay.x264-GAnGSteR",
"Sons Of Anarchy", "", "05", "10", "",
},
{
"🃏@film_night🃏Venus in Fur 2013 BluRay 720p",
"Venus In Fur", "2013", "", "", "",
},
{
"2047 - Sights of Death (2014) 720p BrRip x264 - YIFY",
"2047 Sights Of Death", "2014", "", "", "",
},
{
"22 Jump Street (2014) 720p BrRip x264 - YIFY",
"22 Jump Street", "2014", "", "", "",
},
{
"9.Songs.2004.720p.BluRay.HardSub.Digimoviez",
"9 Songs", "2004", "", "", "",
},
{
"Akira (2016) - UpScaled - 720p - DesiSCR-Rip - Hindi - x264 - AC3 - 5.1 - Mafiaking - M2Tv",
"Akira", "2016", "", "", "",
},
{
"American.Gods.S01E01.1080p.HEVC.x265-MeGusta",
"American Gods", "", "01", "01", "",
},
{
"american.gods.s01e02.1080p.webrip.hevc.x265-rmteam",
"American Gods", "", "01", "02", "",
},
{
"Annabelle.2014.1080p.PROPER.HC.WEBRip.x264.AAC.2.0-RARBG",
"Annabelle", "2014", "", "", "",
},
{
"Annabelle.2014.HC.HDRip.XViD.AC3-juggs[ETRG]",
"Annabelle", "2014", "", "", "",
},
{
"Ant-Man.2015.3D.1080p.BRRip.Half-SBS.x264.AAC-m2g",
"Ant-Man", "2015", "", "", "",
},
{
"Ben Hur 2016 TELESYNC x264 AC3 MAXPRO",
"Ben Hur", "2016", "", "", "",
},
{
"Bliss.1997.DVDRip.HardSub",
"Bliss", "1997", "", "", "",
},
{
"Brave.2012.R5.DVDRip.XViD.LiNE-UNiQUE",
"Brave", "2012", "", "", "",
},
{
"breaking.bad.s01e01.720p.bluray.x264-reward",
"Breaking Bad", "", "01", "01", "",
},
{
"Caníbal.2013.BluRay.720p.HardSub",
"Caníbal", "2013", "", "", "",
},
{
"Community.s02e20.rus.eng.720p.Kybik.v.Kybe",
"Community", "", "02", "20", "",
},
{
"Dawn.Of.The.Planet.of.The.Apes.2014.1080p.WEB-DL.DD51.H264-RARBG",
"Dawn Of The Planet Of The Apes", "2014", "", "", "",
},
{
"Dawn.of.the.Planet.of.the.Apes.2014.HDRip.XViD-EVO",
"Dawn Of The Planet Of The Apes", "2014", "", "", "",
},
{
"Die.Marquise.von.Sade.1976.720p.BluRay.HardSub.Digimoviez",
"Die Marquise Von Sade", "1976", "", "", "",
},
{
"Dinosaur 13 2014 WEBrip XviD AC3 MiLLENiUM",
"Dinosaur 13", "2014", "", "", "",
},
{
"Doctor.Who.2005.8x11.Dark.Water.720p.HDTV.x264-FoV[rartv]",
"Doctor Who", "2005", "08", "11", "Dark Water",
},
// {
// "doctor_who_2005.8x12.death_in_heaven.720p_hdtv_x264-fov",
// "Doctor Who", "2005", "08", "12", "Death In Heaven",
// },
{
"Double.Lover.2017.720p.BluRay.HardSub.Digimoviez",
"Double Lover", "2017", "", "", "",
},
{
"Downton Abbey 5x06 HDTV x264-FoV [eztv]",
"Downton Abbey", "", "05", "06", "",
},
{
"Dracula.Untold.2014.TS.XViD.AC3.MrSeeN-SiMPLE",
"Dracula Untold", "2014", "", "", "",
},
{
"Eliza Graves (2014) Dual Audio WEB-DL 720p MKV x264",
"Eliza Graves", "2014", "", "", "",
},
{
"Femme.Fatale.2002.720p.BluRay.HardSub.mp4",
"Femme Fatale", "2002", "", "", "",
},
{
"Game of Thrones - 4x03 - Breaker of Chains",
"Game Of Thrones", "", "04", "03", "Breaker Of Chains",
},
{
"Girl House (2015) BluRay 720p-hardsub-(@GalleryMovies)",
"Girl House", "2015", "", "", "",
},
{
"Gotham.S01E05.Viper.WEB-DL.x264.AAC",
"Gotham", "", "01", "05", "Viper",
},
{
"Gotham.S01E07.Penguins.Umbrella.WEB-DL.x264.AAC",
"Gotham", "", "01", "07", "Penguins Umbrella",
},
{
"Guardians of the Galaxy (2014) Dual Audio DVDRip AVI",
"Guardians Of The Galaxy", "2014", "", "", "",
},
{
"Guardians Of The Galaxy 2014 R6 720p HDCAM x264-JYK",
"Guardians Of The Galaxy", "2014", "", "", "",
},
{
"Guardians of the Galaxy (CamRip - 2014)",
"Guardians Of The Galaxy", "2014", "", "", "",
},
{
"Halt.and.Catch.Fire.S04E02.Signal.to.Noise.1080p.AMZN.WEBRip.DDP5.1.x264-NTb[rarbg]",
"Halt And Catch Fire", "", "04", "02", "Signal To Noise",
},
{
"Halt.and.Catch.Fire.S04E06.CONVERT.1080p.WEB.h264-TBS[rarbg]",
"Halt And Catch Fire", "", "04", "06", "",
},
{
"Halt.and.Catch.Fire.S04E10.1080p.WEB.H264-STRiFE[rarbg]",
"Halt And Catch Fire", "", "04", "10", "",
},
{
"Hercules (2014) 1080p BrRip H264 - YIFY",
"Hercules", "2014", "", "", "",
},
{
"Hercules.2014.EXTENDED.1080p.WEB-DL.DD5.1.H264-RARBG",
"Hercules", "2014", "", "", "",
},
{
"Hercules.2014.Extended.Cut.HDRip.XViD-juggs[ETRG]",
"Hercules", "2014", "", "", "",
},
{
"Hercules (2014) WEBDL DVDRip XviD-MAX",
"Hercules", "2014", "", "", "",
},
{
"Hes.Just.Not.That.Into.You.2009,[@Intermedia]",
"Hes Just Not That Into You", "2009", "", "", "",
},
{
"Ice.Age.Collision.Course.2016.READNFO.720p.HDRIP.X264.AC3.TiTAN",
"Ice Age Collision Course", "2016", "", "", "",
},
{
"Interstellar (2014) CAM ENG x264 AAC-CPG",
"Interstellar", "2014", "", "", "",
},
{
"Into The Storm 2014 1080p BRRip x264 DTS-JYK",
"Into The Storm", "2014", "", "", "",
},
{
"Into.The.Storm.2014.1080p.WEB-DL.AAC2.0.H264-RARBG",
"Into The Storm", "2014", "", "", "",
},
{
"Its.Always.Sunny.In.Philadelphia.S05E02.BDRip",
"Its Always Sunny In Philadelphia", "", "05", "02", "",
},
{
"Jack.And.The.Cuckoo-Clock.Heart.2013.BRRip XViD",
"Jack And The Cuckoo-Clock Heart", "2013", "", "", "",
},
{
"Last.Tango.in.Paris.1972.720p.BluRay.HardSub",
"Last Tango In Paris", "1972", "", "", "",
},
{
"Lets.Be.Cops.2014.BRRip.XViD-juggs[ETRG]",
"Lets Be Cops", "2014", "", "", "",
},
{
"Lovelace.2013.720p.BluRay-@TheMovieShare",
"Lovelace", "2013", "", "", "",
},
{
"Lucy 2014 Dual-Audio 720p WEBRip",
"Lucy", "2014", "", "", "",
},
{
"Lucy 2014 Dual-Audio WEBRip 1400Mb",
"Lucy", "2014", "", "", "",
},
{
"Lucy.2014.HC.HDRip.XViD-juggs[ETRG]",
"Lucy", "2014", "", "", "",
},
{
"Malizia.1973.480p.perSub",
"Malizia", "1973", "", "", "",
},
{
"Marvel's.Agents.of.S.H.I.E.L.D.S02E01.Shadows.1080p.WEB-DL.DD5.1",
"Marvel'S Agents Of S H I E L D", "", "02", "01", "Shadows",
},
{
"Marvels Agents of S H I E L D S02E05 HDTV x264-KILLERS [eztv]",
"Marvels Agents Of S H I E L D", "", "02", "05", "",
},
{
"Marvels Agents of S.H.I.E.L.D. S02E06 HDTV x264-KILLERS[ettv]",
"Marvels Agents Of S.H.I.E.L.D.", "", "02", "06", "",
},
{
"Match_Point_2005_hardsub",
"Match Point", "2005", "", "", "",
},
{
"Mektoub.My.Love.Canto.Uno.2017.720p.HardSub",
"Mektoub My Love Canto Uno", "2017", "", "", "",
},
{
"One Shot [2014] DVDRip XViD-ViCKY",
"One Shot", "2014", "", "", "",
},
{
"Red.Sonja.Queen.Of.Plagues.2016.BDRip.x264-W4F[PRiME]",
"Red Sonja Queen Of Plagues", "2016", "", "", "",
},
{
"Return.To.Snowy.River.1988.iNTERNAL.DVDRip.x264-W4F[PRiME]",
"Return To Snowy River", "1988", "", "", "",
},
{
"rick.and.morty.s03e01.720p.hdtv.x264-w4f",
"Rick And Morty", "", "03", "01", "",
},
{
"Silicon.Valley.S04E04.1080p.WEB.h264-TBS",
"Silicon Valley", "", "04", "04", "",
},
{
"Sin.City.A.Dame.to.Kill.For.2014.1080p.BluRay.x264-SPARKS",
"Sin City A Dame To Kill For", "2014", "", "", "",
},
{
"Sister.Emanuelle.DvdRip.HardSub",
"Sister Emanuelle", "", "", "", "",
},
{
"Sons.of.Anarchy.S01E03",
"Sons Of Anarchy", "", "01", "03", "",
},
{
"South Park S18E05 HDTV x264-KILLERS [eztv]",
"South Park", "", "18", "05", "",
},
{
"Teenage.Mutant.Ninja.Turtles.2014.720p.HDRip.x264.AC3.5.1-RARBG",
"Teenage Mutant Ninja Turtles", "2014", "", "", "",
},
{
"Teenage.Mutant.Ninja.Turtles.2014.HDRip.XviD.MP3-RARBG",
"Teenage Mutant Ninja Turtles", "2014", "", "", "",
},
{
"Teenage Mutant Ninja Turtles (HdRip - 2014)",
"Teenage Mutant Ninja Turtles", "2014", "", "", "",
},
{
"Teenage Mutant Ninja Turtles (unknown_release_type - 2014)",
"Teenage Mutant Ninja Turtles", "2014", "", "", "",
},
{
"Teeth_2007",
"Teeth", "2007", "", "", "",
},
{
"The Big Bang Theory S08E06 HDTV XviD-LOL [eztv]",
"The Big Bang Theory", "", "08", "06", "",
},
{
"The.Boss.2016.UNRATED.720p.BRRip.x264.AAC-ETRG",
"The Boss", "2016", "", "", "",
},
{
"The.Dark.Side.of.the.Heart.DVDRip.HardSub",
"The Dark Side Of The Heart", "", "", "", "",
},
{
"The.Duke.of.Burgundy.2014.720p.BluRay.HardSub",
"The Duke Of Burgundy", "2014", "", "", "",
},
{
"The Flash 2014 S01E01 HDTV x264-LOL[ettv]",
"The Flash", "2014", "01", "01", "",
},
{
"The Flash 2014 S01E03 HDTV x264-LOL[ettv]",
"The Flash", "2014", "01", "03", "",
},
{
"The Flash 2014 S01E04 HDTV x264-FUM[ettv]",
"The Flash", "2014", "01", "04", "",
},
{
"The Hateful Eight (2015) 720p BluRay - x265 HEVC - 999MB - ShAaN",
"The Hateful Eight", "2015", "", "", "",
},
{
"The.Jungle.Book.2016.3D.1080p.BRRip.SBS.x264.AAC-ETRG",
"The Jungle Book", "2016", "", "", "",
},
{
"The Missing 1x01 Pilot HDTV x264-FoV [eztv]",
"The Missing", "", "01", "01", "Pilot",
},
{
"The.Platform.2019.720p.WEB-DL.SoftSub",
"The Platform", "2019", "", "", "",
},
{
"The Purge: Election Year (2016) HC - 720p HDRiP - 900MB - ShAaNi",
"The Purge: Election Year", "2016", "", "", "",
},
{
"The.Secret.Life.of.Pets.2016.HDRiP.AAC-LC.x264-LEGi0N",
"The Secret Life Of Pets", "2016", "", "", "",
},
{
"These.Final.Hours.2013.WBBRip XViD",
"These Final Hours", "2013", "", "", "",
},
{
"The Shaukeens (2014) 1CD DvDScr Rip x264 [DDR]",
"The Shaukeens", "2014", "", "", "",
},
{
"The Shaukeens 2014 Hindi (1CD) DvDScr x264 AAC...Hon3y",
"The Shaukeens", "2014", "", "", "",
},
{
"The Simpsons S26E05 HDTV x264 PROPER-LOL [eztv]",
"The Simpsons", "", "26", "05", "",
},
{
"The.Walking.Dead.S05E03.1080p.WEB-DL.DD5.1.H.264-Cyphanix[rartv]",
"The Walking Dead", "", "05", "03", "",
},
{
"The Walking Dead S05E03 720p HDTV x264-ASAP[ettv]",
"The Walking Dead", "", "05", "03", "",
},
{
"The.Wings.of.The.Dove.1997.720p.HardSub",
"The Wings Of The Dove", "1997", "", "", "",
},
{
"They.2017.WEBRip.1080p.YTS.Dream",
"They", "2017", "", "", "",
},
{
"Trainwreck",
"Trainwreck", "", "", "", "",
},
{
"Two and a Half Men S12E01 HDTV x264 REPACK-LOL [eztv]",
"Two And A Half Men", "", "12", "01", "",
},
{
"UFC.179.PPV.HDTV.x264-Ebi[rartv]",
"UFC 179", "", "", "", "",
},
{
"War Dogs (2016) HDTS 600MB - NBY",
"War Dogs", "2016", "", "", "",
},
{
"Wild.Things.2.2004.720p.HardSub",
"Wild Things 2", "2004", "", "", "",
},
{
"WWE Hell in a Cell 2014 HDTV x264 SNHD",
"WWE Hell In A Cell", "2014", "", "", "",
},
{
"WWE Hell in a Cell 2014 PPV WEB-DL x264-WD -={SPARROW}=-",
"WWE Hell In A Cell", "2014", "", "", "",
},
{
"WWE Monday Night Raw 2014 11 10 WS PDTV x264-RKOFAN1990 -={SPARR",
"WWE Monday Night Raw 11 10", "2014", "", "", "",
},
{
"WWE Monday Night Raw 3rd Nov 2014 HDTV x264-Sir Paul",
"WWE Monday Night Raw 3rd Nov", "2014", "", "", "",
},
{
"www.torrenting.com - Silicon.Valley.S04E04.1080p.WEB.h264-TBS",
"Silicon Valley", "", "04", "04", "",
},
{
"X-Men.Days.of.Future.Past.2014.1080p.WEB-DL.DD5.1.H264-RARBG",
"X-Men Days Of Future Past", "2014", "", "", "",
},
{
"filmpokvipNo_Hard_Feelings_2023_1080p_WEBRip_x265_10bit_AAC5_1_YT",
"No Hard Feelings", "2023", "", "", "",
},
{
"Venus in Fur.2013",
"Venus In Fur", "2013", "", "", "",
},
{
"Mission_Impossible_Dead_Reckoning_Part_One_2023_1080P_Amzn_Web",
"Mission Impossible Dead Reckoning Part One", "2023", "", "", "",
},
{
"The_Swan_2023_10bit_1080p_x265_WEB-DL",
"The Swan", "2023", "", "", "",
},
}
for _, tt := range ts {
pf := &plexFile{name: tt.n, mov: movie{}}
pf.parse()
if pf.mov.name != tt.m {
t.Errorf("name: %s\ngot: %s\nwant: %s", tt.n, pf.mov.name, tt.m)
}
if pf.mov.year != tt.y {
t.Errorf("year: %s\ngot: %s\nwant: %s", tt.n, pf.mov.year, tt.y)
}
if pf.mov.season != tt.s {
t.Errorf("season: %s\ngot: %s\nwant: %s", tt.n, pf.mov.season, tt.s)
}
if pf.mov.episode != tt.e {
t.Errorf("episode: %s\ngot: %s\nwant: %s", tt.n, pf.mov.episode, tt.e)
}
if pf.mov.epiName != tt.en {
t.Errorf("episode name: %s\ngot: %s\nwant: %s", tt.n, pf.mov.epiName, tt.en)
}
}
}
func TestPlexName(t *testing.T) {
ts := []struct {
m, y, s, e, en string
n string
}{
{
"", "", "", "", "",
"",
},
{
"foo", "", "", "", "",
"foo",
},
{
"foo", "1986", "", "", "",
"foo (1986)",
},
{
"bar", "", "03", "07", "",
"bar - s03e07",
},
{
"bar", "2014", "03", "07", "",
"bar (2014) - s03e07",
},
{
"baz", "", "11", "22", "blah",
"baz - s11e22 - blah",
},
{
"baz", "2020", "11", "22", "blah",
"baz (2020) - s11e22 - blah",
},
}
for _, tt := range ts {
pf := &plexFile{mov: movie{name: tt.m, year: tt.y, season: tt.s, episode: tt.e, epiName: tt.en}}
pn := pf.plexName()
if pn != tt.n {
t.Errorf("got: %s\nwant: %s", pn, tt.n)
}
}
}
func TestPlexDir(t *testing.T) {
ts := []struct {
m, y, s, e, en string
d string
}{
{
"", "", "", "", "",
"",
},
{
"foo", "", "", "", "",
"foo",
},
{
"foo", "1986", "", "", "",
"foo (1986)",
},
{
"bar", "", "03", "07", "",
"bar",
},
{
"bar", "2014", "03", "07", "",
"bar (2014)",
},
{
"baz", "", "11", "22", "blah",
"baz",
},
{
"baz", "2020", "11", "22", "blah",
"baz (2020)",
},
}
for _, tt := range ts {
pf := &plexFile{mov: movie{name: tt.m, year: tt.y, season: tt.s, episode: tt.e, epiName: tt.en}}
pd := pf.plexDir()
if pd != tt.d {
t.Errorf("got: %s\nwant: %s", pd, tt.d)
}
}
}
func TestSeasonDir(t *testing.T) {
ts := []struct {
m, y, s, e, en string
d string
}{
{
"", "", "", "", "",
"",
},
{
"foo", "", "", "", "",
"",
},
{
"foo", "1986", "", "", "",
"",
},
{
"bar", "", "03", "07", "",
"Season 03",
},
{
"bar", "2014", "03", "07", "",
"Season 03",
},
{
"baz", "", "11", "22", "blah",
"Season 11",
},
{
"baz", "2020", "11", "22", "blah",
"Season 11",
},
}
for _, tt := range ts {
pf := &plexFile{mov: movie{name: tt.m, year: tt.y, season: tt.s, episode: tt.e, epiName: tt.en}}
pd := pf.seasonDir()
if pd != tt.d {
t.Errorf("got: %s\nwant: %s", pd, tt.d)
}
}
}
func TestConvert(t *testing.T) {
const mn = "foo.2020.abc"
const tn = "foo.s01e02.bar.abc"
d, err := testDir(mn, tn)
if err != nil {
t.Fatalf("Cannot create temp directory/file: %v\n", err)
}
defer os.RemoveAll(d)
ts := []struct {
p string
d, s, c bool
o string
n string
}{
{
mn, true, false, false, "",
"Foo (2020).abc",
},
{
mn, true, false, false, "target",
filepath.Join("target", "Foo (2020).abc"),
},
{
mn, true, true, false, "",
filepath.Join("Foo (2020)", "Foo (2020).abc"),
},
{
mn, true, true, false, "target",
filepath.Join("target", "Foo (2020)", "Foo (2020).abc"),
},
{
tn, true, false, false, "",
filepath.Join("Foo", "Season 01", "Foo - s01e02 - Bar.abc"),
},
{
tn, true, false, false, "target",
filepath.Join("target", "Foo", "Season 01", "Foo - s01e02 - Bar.abc"),
},
// Not dry run.
{
mn, false, true, false, filepath.Join(d, "target"),
filepath.Join(d, "target", "Foo (2020)", "Foo (2020).abc"),
},
{
tn, false, false, false, filepath.Join(d, "target"),
filepath.Join(d, "target", "Foo", "Season 01", "Foo - s01e02 - Bar.abc"),
},
}
for _, tt := range ts {
np := convert(tt.p, tt.d, tt.s, tt.c, tt.o)
if np != tt.n {
t.Errorf("got: %s\nwant: %s", np, tt.n)
}
if !tt.d {
d, _ := filepath.Split(np)
if _, err := os.Stat(d); os.IsNotExist(err) {
t.Errorf("dir does not exist: %v\n", err)
}
}
}
}
func BenchmarkParse(b *testing.B) {
pf := &plexFile{name: "Marvel's.Agents.of.S.H.I.E.L.D.S02E01.Shadows.1080p.WEB-DL.DD5.1", mov: movie{}}
for i := 0; i < b.N; i++ {
pf.parse()
}
}
func BenchmarkConvert(b *testing.B) {
const n = "foo.s01e02.bar.abc"
d, err := testDir(n)
if err != nil {
b.Fatalf("Cannot create temp directory/file: %v\n", err)
}
defer os.RemoveAll(d)
for i := 0; i < b.N; i++ {
convert(n, false, false, false, filepath.Join(d, "target"))
}
}
func testDir(paths ...string) (string, error) {
d, err := ioutil.TempDir("", "plexize")
if err != nil {
return "", err
}
for _, p := range paths {
if err := ioutil.WriteFile(filepath.Join(d, p), nil, 0666); err != nil {
return "", err
}
}
return d, nil
}