forked from ankitsejwal/Lyndor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove.py
More file actions
executable file
·78 lines (59 loc) · 2.58 KB
/
move.py
File metadata and controls
executable file
·78 lines (59 loc) · 2.58 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
''' Rename videos and subtitle, also write content.md '''
import os, re, shutil, sys
import save
from colorama import *
def assign_folder(folder):
''' return folder path '''
os.chdir(folder)
path = os.getcwd()
return path
def vid_srt_to_chapter(url, course_folder):
''' move videos and subtitles to correct chapter folder '''
soup = save.create_soup(url)
chapters = soup.find_all("h4", class_="ga")
ul_video = soup.find_all('ul', class_="row toc-items")
chapter_count = 0
video_count = 0
print('\n')
for li in ul_video:
chapter_name = chapters[chapter_count].text
if chapter_name[1] == '.':
chapter_name = str(chapter_count).zfill(2) + '. ' + chapter_name[3:]
elif chapter_name[2] == '.':
chapter_name = str(chapter_count).zfill(2) + '. ' + chapter_name[4:]
else:
chapter_name = str(chapter_count).zfill(2) + '. ' + chapter_name
chapter_name = re.sub('[,:?><"/\\|*]', ' ', chapter_name)
chapter_count += 1
os.chdir(course_folder)
group = li.find_all('a', class_='video-name')
print('🔰 Moving files inside: ' + str(chapter_name))
for video in group:
video_count += 1
video_name = str(video_count).zfill(2) + ' - ' + video.text.strip() + '.mp4'
video_name = re.sub('[?]', '', video_name)
video_name = re.sub('[/]', '_', video_name)
video_name = re.sub('["]', '\'', video_name)
video_name = re.sub('[:><\\|*]', ' -', video_name)
subtitle_name = str(video_count).zfill(2) + ' - ' + video.text.strip() + '.en.srt'
subtitle_name = re.sub('[?]', '', subtitle_name)
subtitle_name = re.sub('[/]', '_', subtitle_name)
subtitle_name = re.sub('["]', '\'', subtitle_name)
subtitle_name = re.sub('[:><\\|*]', ' -', subtitle_name)
try:
shutil.move(video_name, chapter_name)
except:
print('🤕 File not found: ' + str(video_name))
try:
shutil.move(subtitle_name, chapter_name)
except:
pass
print('\n🥂 videos/subtitles moved to appropriate chapters successfully.')
def hms_string(sec_elapsed):
''' format elapsed time '''
hour = int(sec_elapsed / (60 * 60))
minutes = int((sec_elapsed % (60 * 60)) / 60)
seconds = sec_elapsed % 60.
return "{}:{:>02}:{:>05.2f}".format(hour, minutes, seconds)