dc-path-folder 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dc_path_folder-0.1.0/PKG-INFO +35 -0
- dc_path_folder-0.1.0/README.md +24 -0
- dc_path_folder-0.1.0/_path_folder/__init__.py +3 -0
- dc_path_folder-0.1.0/_path_folder/path_folder.py +155 -0
- dc_path_folder-0.1.0/dc_path_folder.egg-info/PKG-INFO +35 -0
- dc_path_folder-0.1.0/dc_path_folder.egg-info/SOURCES.txt +8 -0
- dc_path_folder-0.1.0/dc_path_folder.egg-info/dependency_links.txt +1 -0
- dc_path_folder-0.1.0/dc_path_folder.egg-info/top_level.txt +1 -0
- dc_path_folder-0.1.0/setup.cfg +4 -0
- dc_path_folder-0.1.0/setup.py +15 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dc-path-folder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight Khmer greeting utility for Python
|
|
5
|
+
Author: Dai Chao Online
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Dynamic: author
|
|
8
|
+
Dynamic: description
|
|
9
|
+
Dynamic: description-content-type
|
|
10
|
+
Dynamic: summary
|
|
11
|
+
|
|
12
|
+
# DC Path Folder
|
|
13
|
+
|
|
14
|
+
**Credit:** Original development by **Dai Chao Online**
|
|
15
|
+
|
|
16
|
+
DC Path Folder is a lightweight Python package for managing device file paths and videos.
|
|
17
|
+
It’s designed for developers who want fast setup, simple APIs, and clean folder handling for Android automation and media tasks.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- Save and retrieve device-specific paths
|
|
22
|
+
- Count and scan video files in folders
|
|
23
|
+
- Pick random videos and rename them for upload
|
|
24
|
+
- Push files to Android devices via ADB
|
|
25
|
+
- Move and organize videos into target folders
|
|
26
|
+
- Scan and open media on devices
|
|
27
|
+
- Delete local or device files safely
|
|
28
|
+
- Supports Python 3.10+
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Install using pip:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install dc-path-folder
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# DC Path Folder
|
|
2
|
+
|
|
3
|
+
**Credit:** Original development by **Dai Chao Online**
|
|
4
|
+
|
|
5
|
+
DC Path Folder is a lightweight Python package for managing device file paths and videos.
|
|
6
|
+
It’s designed for developers who want fast setup, simple APIs, and clean folder handling for Android automation and media tasks.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Save and retrieve device-specific paths
|
|
11
|
+
- Count and scan video files in folders
|
|
12
|
+
- Pick random videos and rename them for upload
|
|
13
|
+
- Push files to Android devices via ADB
|
|
14
|
+
- Move and organize videos into target folders
|
|
15
|
+
- Scan and open media on devices
|
|
16
|
+
- Delete local or device files safely
|
|
17
|
+
- Supports Python 3.10+
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Install using pip:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install dc-path-folder
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""
|
|
2
|
+
DC VideoManager Toolkit
|
|
3
|
+
Original development by Dai Chao Online
|
|
4
|
+
|
|
5
|
+
A Python utility for managing device video paths, picking random videos,
|
|
6
|
+
pushing to Android devices, and handling local video organization.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
import os
|
|
11
|
+
import json
|
|
12
|
+
import glob
|
|
13
|
+
import subprocess
|
|
14
|
+
import random
|
|
15
|
+
import re
|
|
16
|
+
import shutil
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class DevicePath:
|
|
20
|
+
deviceID: str
|
|
21
|
+
path: str = None
|
|
22
|
+
BASE_DIR = "DevicePaths"
|
|
23
|
+
VIDEO_EXTENSIONS = ('.mp4', '.avi', '.mkv', '.mov', '.wmv', '.flv', '.webm', '.m4v')
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def _ensure_dir(cls):
|
|
27
|
+
os.makedirs(cls.BASE_DIR, exist_ok=True)
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def _device_file(cls, deviceID: str):
|
|
31
|
+
return os.path.join(cls.BASE_DIR, f"{deviceID}.json")
|
|
32
|
+
|
|
33
|
+
def save_data(self):
|
|
34
|
+
self._ensure_dir()
|
|
35
|
+
file_path = self._device_file(self.deviceID)
|
|
36
|
+
if os.path.exists(file_path):
|
|
37
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
38
|
+
data = json.load(f)
|
|
39
|
+
if data["path"] == self.path:
|
|
40
|
+
return False
|
|
41
|
+
|
|
42
|
+
with open(file_path, "w", encoding="utf-8") as f:
|
|
43
|
+
json.dump({"path": self.path}, f, indent=4)
|
|
44
|
+
|
|
45
|
+
return True
|
|
46
|
+
|
|
47
|
+
def get_paths(self):
|
|
48
|
+
file_path = self._device_file(self.deviceID)
|
|
49
|
+
if os.path.exists(file_path):
|
|
50
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
51
|
+
data = json.load(f)
|
|
52
|
+
return data["path"]
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
def video_count(self):
|
|
56
|
+
path = self.get_paths()
|
|
57
|
+
if not path or not os.path.exists(path):
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
return sum(
|
|
61
|
+
1
|
|
62
|
+
for root, _, files in os.walk(path)
|
|
63
|
+
for f in files
|
|
64
|
+
if f.lower().endswith(self.VIDEO_EXTENSIONS)
|
|
65
|
+
)
|
|
66
|
+
@dataclass
|
|
67
|
+
class VideoManager:
|
|
68
|
+
video_extensions = (
|
|
69
|
+
'.mp4', '.avi', '.mkv',
|
|
70
|
+
'.mov', '.wmv', '.flv',
|
|
71
|
+
'.webm', '.m4v'
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def count_videos_in_folder(self, folder_path):
|
|
75
|
+
matched_videos = []
|
|
76
|
+
for pattern in self.video_extensions:
|
|
77
|
+
matched_videos.extend(glob.glob(os.path.join(folder_path, pattern)))
|
|
78
|
+
|
|
79
|
+
return len(matched_videos)
|
|
80
|
+
|
|
81
|
+
def pick_and_rename_random_video(self, folder_path):
|
|
82
|
+
try:
|
|
83
|
+
all_files = os.listdir(folder_path)
|
|
84
|
+
except FileNotFoundError:
|
|
85
|
+
return None, None
|
|
86
|
+
|
|
87
|
+
video_list = [
|
|
88
|
+
f for f in all_files
|
|
89
|
+
if f.lower().endswith((".mp4", ".avi", ".mkv", ".mov", ".flv"))
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
if not video_list:
|
|
93
|
+
return None, None
|
|
94
|
+
|
|
95
|
+
chosen_file = random.choice(video_list)
|
|
96
|
+
old_path = os.path.join(folder_path, chosen_file)
|
|
97
|
+
new_path = os.path.join(folder_path, "upload.mp4")
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
os.rename(old_path, new_path)
|
|
101
|
+
except Exception as err:
|
|
102
|
+
return f"Error: {err}"
|
|
103
|
+
|
|
104
|
+
video_path = new_path
|
|
105
|
+
title = os.path.splitext(chosen_file)[0]
|
|
106
|
+
|
|
107
|
+
try:
|
|
108
|
+
title = title.split("_", 1)[1]
|
|
109
|
+
except IndexError:
|
|
110
|
+
title = title
|
|
111
|
+
|
|
112
|
+
title = re.sub(r"[^a-zA-Z0-9 .\-_]", "", title)
|
|
113
|
+
return video_path, title
|
|
114
|
+
|
|
115
|
+
def push_file_to_device(self, device_id, local_file_path):
|
|
116
|
+
subprocess.check_call(
|
|
117
|
+
f'adb -s {device_id} push "{local_file_path}" /sdcard/',
|
|
118
|
+
shell=True
|
|
119
|
+
)
|
|
120
|
+
return f"Pushed file to device: {local_file_path}"
|
|
121
|
+
|
|
122
|
+
def move_video_to_folder(self, video_path, title):
|
|
123
|
+
base_name = os.path.splitext(video_path)[0]
|
|
124
|
+
target_folder = f"{base_name}ed"
|
|
125
|
+
if not os.path.exists(target_folder):
|
|
126
|
+
os.makedirs(target_folder)
|
|
127
|
+
return f"Created folder: {target_folder}"
|
|
128
|
+
|
|
129
|
+
destination_path = os.path.join(target_folder, f"{title}.mp4")
|
|
130
|
+
shutil.move(video_path, destination_path)
|
|
131
|
+
return f"Moved video to: {destination_path}"
|
|
132
|
+
|
|
133
|
+
def scan_and_open_media(self, device_id, file_path):
|
|
134
|
+
subprocess.check_output(
|
|
135
|
+
f'adb -s {device_id} shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d "file://{file_path}"',
|
|
136
|
+
shell=True
|
|
137
|
+
)
|
|
138
|
+
subprocess.check_output(
|
|
139
|
+
f'adb -s {device_id} shell am start -a android.intent.action.VIEW -d "file://{file_path}" -t "image/*"',
|
|
140
|
+
shell=True
|
|
141
|
+
)
|
|
142
|
+
return f"Scanned and opened file: {file_path}"
|
|
143
|
+
|
|
144
|
+
def delete_device_file(self, device_id, remote_file="/sdcard/upload.mp4"):
|
|
145
|
+
subprocess.check_output(
|
|
146
|
+
f'adb -s {device_id} shell rm {remote_file}',
|
|
147
|
+
shell=True
|
|
148
|
+
)
|
|
149
|
+
return f"Deleted file: {remote_file}"
|
|
150
|
+
|
|
151
|
+
def delete_local_file(self, file_path):
|
|
152
|
+
if os.path.exists(file_path):
|
|
153
|
+
os.remove(file_path)
|
|
154
|
+
return f"Deleted file: {file_path}"
|
|
155
|
+
return f"File not found: {file_path}"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dc-path-folder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight Khmer greeting utility for Python
|
|
5
|
+
Author: Dai Chao Online
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Dynamic: author
|
|
8
|
+
Dynamic: description
|
|
9
|
+
Dynamic: description-content-type
|
|
10
|
+
Dynamic: summary
|
|
11
|
+
|
|
12
|
+
# DC Path Folder
|
|
13
|
+
|
|
14
|
+
**Credit:** Original development by **Dai Chao Online**
|
|
15
|
+
|
|
16
|
+
DC Path Folder is a lightweight Python package for managing device file paths and videos.
|
|
17
|
+
It’s designed for developers who want fast setup, simple APIs, and clean folder handling for Android automation and media tasks.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- Save and retrieve device-specific paths
|
|
22
|
+
- Count and scan video files in folders
|
|
23
|
+
- Pick random videos and rename them for upload
|
|
24
|
+
- Push files to Android devices via ADB
|
|
25
|
+
- Move and organize videos into target folders
|
|
26
|
+
- Scan and open media on devices
|
|
27
|
+
- Delete local or device files safely
|
|
28
|
+
- Supports Python 3.10+
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Install using pip:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install dc-path-folder
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
_path_folder
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
this_directory = Path(__file__).parent
|
|
5
|
+
long_description = (this_directory / "README.md").read_text(encoding="utf-8")
|
|
6
|
+
|
|
7
|
+
setup(
|
|
8
|
+
name="dc-path-folder",
|
|
9
|
+
version="0.1.0",
|
|
10
|
+
packages=find_packages(),
|
|
11
|
+
author="Dai Chao Online",
|
|
12
|
+
description="A lightweight Khmer greeting utility for Python",
|
|
13
|
+
long_description=long_description,
|
|
14
|
+
long_description_content_type="text/markdown",
|
|
15
|
+
)
|