1# mediatool
2
3mediatool is a lightweight collection of command line utilities, by which you can manage media assets such as images and videos in the system gallery.
4
5## Prerequisites
6
7- The device is connected properly.
8- The developer mode is enabled.
9- You have run the **hdc shell** command to enter the command line execution mode.
10
11## Commands
12
13<!--Del-->
14
15### mediatool send
16
17```shell
18mediatool send <path-to-local-media-file> [-ts] [-tas] [-rf] [-urf]
19```
20
21Sends images, audios, and videos in **\<path-to-local-media-file>** of the device to the media library for storage.  The original file names are used. If **\<path-to-local-media-file>** indicates a folder, all files in the folder are sent to the media library. After a file is successfully saved, the URI of the file is displayed.
22
23By default, a thumbnail is generated in synchronous mode when a media file is being saved to the media library, and the source file in **\<path-to-local-media-file>** is deleted once the saving process is complete.
24
25  | Parameter              | Description            |
26| ---- |--------------- |
27| -ts | Creates a thumbnail in synchronous mode when an image or a video is being saved. The media file is displayed after the thumbnail is generated. However, the saving takes a longer time. This parameter is used by default.|
28| -tas | Creates a thumbnail in asynchronous mode when an image or a video is being saved. This parameter conflicts with **-ts**. The media file is displayed before the thumbnail is generated, and the saving takes a shorter time.|
29| -rf | Deletes the source file after a media file is saved. This parameter is used by default.|
30| -urf | Retains the source file after a media file is saved. This parameter conflicts with **-rf**.|
31
32**Example**
33
34```shell
35> mediatool send /data/tmp/MyImage.jpg
36file://media/Photo/3/IMG_1721381297_001/MyImage.jpg # The image is saved successfully, and the URI of the image is displayed.
37```
38
39### mediatool list
40
41```shell
42mediatool list <resource-uri>
43```
44
45Displays the information of a resource file specified by **\<resource-uri>** in the media library in CSV format.
46For example, if the URI of image A in the media library is **file://media/Photo/3/IMG_1721381297_001/MyImage.jpg**, you can run **mediatool list file://media/Photo/3** or **mediatool list file://media/Photo/3/IMG_1721381297_001/MyImage.jpg** to display the resource information.
47
48The following resource information is contained:
49
50- uri: URI of the media resource.
51- display_name: name of the media resource.
52- data: path of the source file of the media resource on the device.
53
54You can also set **\<resource-uri>** to **all**, which displays the information about all the resource files in the media library.
55
56**Example**
57
58```shell
59# Use a valid URI for query.
60> mediatool list file://media/Photo/3
61Table Name: Photos
62uri, display_name, data
63"file://media/Photo/3/IMG_1721381297_001/MyImage.jpg", "MyImage.jpg", "/storage/cloud/100/files/Photo/2/IMG_1721381297_001.jpg"
64
65# Use an invalid URI for query.
66> mediatool list file://media/Photo/
67[FAIL] uri invalid. uri:file://media/Photo/
68```
69
70<!--DelEnd-->
71
72### mediatool recv
73
74```shell
75mediatool recv <resource-uri> <dest-path>
76```
77
78Exports the source file specified by **\<resource-uri>** in the media library to the device path specified by **\<dest-path>**.
79
80You can set **\<dest-path>** to the path of a file or folder. If it is set to a folder path, the file is exported to the folder and the source file name is used.
81
82If it is set to a file path, do not use the path of an existing file.
83<!--Del-->
84In addition, **\<dest-path>** must be accessible.
85<!--DelEnd-->
86After the file is exported successfully, the path of the exported file is displayed.
87
88You can run the <!--Del-->**mediatool list all** or <!--DelEnd-->[mediatool query](#mediatool-query) command to obtain the media library resource URI.
89
90If **\<resource-uri>** is set to **all**, all resource files in the media library are exported. In this case, **\<dest-path>** must be a folder path.
91
92<!--RP1--><!--RP1End-->
93
94**Example**
95
96```shell
97> mediatool recv file://media/Photo/3 /data/local/tmp/out.jpg
98Table Name: Photos
99/data/local/tmp/out.jpg
100```
101
102### mediatool delete
103
104```shell
105mediatool delete <resource-uri>
106```
107
108Deletes a resource file specified by **\<resource-uri>** from the media library. Since the deleted resource cannot be recovered, exercise caution when using this command.
109
110You can run the <!--Del-->**mediatool list all** or <!--DelEnd-->[mediatool query](#mediatool-query) command to obtain the URI of the media resource.
111
112If **\<resource-uri>** is set to **all**, all resource files in the media library are deleted and all data in the media library is reset.
113
114**Example**
115
116```shell
117> mediatool delete file://media/Photo/3
118[SUCCESS] delete success.
119
120> mediatool delete all # No information is displayed when the delete all command is executed successfully.
121```
122
123### mediatool query
124
125```shell
126mediatool query <display-name> [-p] [-u]
127```
128
129Queries the path or URI of a resource file specified by **\<display-name>** in the media library. By default, the path is returned.
130
131  | Parameter              | Description            |
132| ---- |--------------- |
133| -p | Obtains the path of the media resource file. This parameter is used by default.|
134| -u | Obtains the URI of the media resource. This parameter conflicts with **-p**.|
135
136**Example**
137
138```shell
139# Query the media file that exists.
140> mediatool query MyImage.jpg
141find 1 result:
142path
143/storage/cloud/100/files/Photo/2/IMG_1721381297_001.jpg
144
145# Query the media file that does not exist.
146> mediatool query non_exist.jpg
147find 0 result
148
149# Use a name in incorrect format for query.
150> mediatool query IMG_001
151The displayName format is not correct!
152
153# Query the path of the media resource file.
154> mediatool query MyImage.jpg -p
155find 1 result:
156path
157/storage/cloud/100/files/Photo/2/IMG_1721381297_001.jpg
158
159# Query the URI of the media resource.
160> mediatool query MyImage.jpg -u
161find 1 result:
162uri
163"file://media/Photo/2/IMG_1721381297_001/MyImage.jpg"
164```
165