Linux mobile phone DIY. Shell application extension 2. automatically generate a playlist (e680 Series)

Source: Internet
Author: User

Linux mobile phone DIY. Shell application extension 2. automatically generate a playlist (e680 Series)

Papayas

2007-03-20

I. Origin of the problem

Many people ask what is the best player for e680. I just want to say that it is still a built-in RealPlayer.
His advantage lies in the resources used, the seamless connection with mobile phones, and the appropriate media-related parameter settings.
RealPlayer provides strong audio playback capabilities and supports many formats. What is lacking is video playback.
Capability. This is also the main reason why a large number of third-party players exist on the Internet.
Considering the capacity of the mobile phone and the power consumption of Extracting high-quality media files, this type of third-party player is used.
Regret is inevitable. Moreover, websites such as CCTV network TV also provide a large number of suitable files for suppression. Comprehensive Test
It is also reasonable to draw the above conclusion.

However, RealPlayer has a major drawback (at least I think so). It manages the addition and Management of the playlist.
It is very troublesome. There are many ways to solve this problem. Here we still trust shell.

<Linux phone DIY series: http://blog.csdn.net/liwei_cmg/category/241839.aspx>

II. General idea of automatic playback list

The idea is quite simple. The e680g playlist file is/ezxlocal/download/appwrite/. RealPlayer. List.
This is the object of our operation.
Let me first explain the specific operation methods:

1.establish the execution script playerlist.txt.
2. In the current Script directory, manually create several list configuration files, which must be defined as _ *. txt.
This format. In addition, each line of file content is the directory to be included in the list, and the last line must be empty.

For example:
_All.txt

01/MMC/mmca1/music/soft
02/MMC/mmca1/music/Game
03/MMC/mmca1/music/pop
04

_Game.txt

01/MMC/mmca1/music/Game
02

The row number is marked on the left of the above file, which is not found in the actual file.

3. During script execution, all _ *. txt files are traversed in the current directory, and each file generates a playlist.
When processing a file, the system looks for the Directory defined by the file and automatically generates the media file to the list.

4. Start realplay.

Iii. full content of the script file

01 #! /Bin/bash
02
03 # current path
04 path_current =/MMC/mmca1/soft/playerlist
05 # log files
06 file_log = $ path_current/log.txt
07
08 # pre-defined files
09 file_define = $ path_current/define.txt
10
11
12 echo $> $ path_current/tmpproc.txt
13
14 # Instruction Set
15 file_busybox =/MMC/mmca1/tmp/busybox
16
17 # create a playlist Header
18 file_listhead = $ path_current/tmplisthead. Head
19 echo "[allplaylist]"> $ file_listhead
20
21
22 CD $ path_current
23 # traverse cyclic Variables
24 ilistcount = 0
25 # traverse the local list configuration file
26
27 For installlist in 'ls _ *. txt'
28 do
29
30 # playlist name
31 listname =$ {installlist #*_}
32 listname =$ {listname % .*}
33
34 # echo $ listname
35
36 ilistcount = $ ($ ilistcount + 1 ))
37 echo "$ ilistcount = pl-$ listname"> $ file_listhead
38
39 # temporary cyclic Variables
40 I = 0
41
42 # Number of file lines
43 vfilelen = '$ file_busybox WC $ path_current/$ installlist | $ file_busybox awk' {print $1 }''
44 echo "line:" $ vfilelen
45
46 # rm $ path_current/tmp $ listname. List
47 echo "[pl-$ listname]"> $ path_current/tmp $ listname. List
48 While test $ I-lt $ vfilelen
49 do
50
51 I =$ ($ I + 1 ))
52
53 # List Directory
54 echo $ path_current/$ installlist
55 listdir = 'sed-n "$ I p" $ path_current/$ installlist'
56
57 echo $ listdir
58 find $ listdir-name '*. [M, M, W, w] [p, p, M, m] [3, a, a] '> "$ path_current/tmp $ listname. list"
59
60 done
61
62 $ file_busybox awk 'in in {FS = "," }{ if (Nr = 1) printf $0 "/N"; if (NR! = 1) printf NR-1 "=" $0 "/N";} '$ path_current/tmp $ listname. List> $ path_current/tmpfile
63
64 listcount = '$ file_busybox WC $ path_current/tmpfile | $ file_busybox awk' {print $1 }''
65 listcount = $ ($ ListCount-1 ))
66 echo "counter =" $ listcount> $ path_current/tmpfile
67 MV-F $ path_current/tmpfile $ path_current/tmp $ listname. List
68
69 done
70
71 listcount = '$ file_busybox WC $ file_listhead | $ file_busybox awk' {print $1 }''
72 listcount = $ ($ ListCount-1 ))
73 echo "counter =" $ listcount> $ file_listhead
74
75
76 cat $ file_listhead> $ path_current/RealPlayer
77 cat $ file_define> $ path_current/RealPlayer
78 cat $ path_current/*. List> $ path_current/RealPlayer
79
80 CP-F $ path_current/RealPlayer/ezxlocal/download/appwrite/. RealPlayer. List

Iv. Script File explanation

The script mainly uses shell commands such as WC, awk, and sed to process files. Like random Bell,
The busybox instruction set is still used. The following describes the script execution process in detail:

1. Create a playlist header <17 rows>

That is, the content of the tmplisthead. Head file will eventually be the starting part of the playlist:

[Allplaylist]
1 = pl-all
2 = pl-game
Counter = 2

In the process of traversing all _ *. txt, <-69 rows>, the alias name will be extracted first, for example, _all.txt
The list name is all. <> To complete this operation, $ {installlist # * _} is used #*_}
The variable truncation method is applicable to bash. Other shells have not been tested.

<37> line: combines the obtained playlist names into recognizable content of the e680 RealPlayer,
And write it into tmplisthead. Head.

<73> row. At this time, the traversal process is completed and the last counter = I statement is generated.

2. Create a fixed part of the playlist <09>

The pre-defined file config.txt contains:

[Bookmark]
Counter = 0
[Currentplaylist]
Counter = 0
Currentitem = 0
Currentplaylistname =
[History]
Counter = 0

We don't care about this content, and we won't modify it.

3. dynamically create a playlist <27-69>

In the main loop, the script first obtains a _ *. txt file, reads the file content, and computes the file line.
Number <43 rows>. Then traverse each row of the file (which belongs to the inner loop <48-60 rows> ). For this file
Process the playlist for each row of contents <58 rows>. After the inner loop ends
The playlist file TMP *. List is processed twice to conform to the RealPlayer format <62>.

Every _ *. txt file generates TMP *. List.


4. Final file content combination <-80 rows>

At this time, the work is much simpler. It only integrates all the intermediate files to generate the Final playlist,
And forcibly copy to a fixed directory. The valid media file extension is temporarily written to the script.
<58 rows>. If you are interested, you can change it to dynamic configuration. Whether it is the Linux mobile DIY. Shell
Application extension 1. Random incoming call ringtones and the configuration files are extremely simple
Independent files, which can also be improved.


5. Important supplements

Up to now, all configuration files involved in the shell series must be in Common Unix format, no
It will not run properly. (Note: The difference between the Unix format and the common Windows DOS format lies in the carriage return,
UNIX is 0x0d, DOS is 0x0a + 0x0d. If Windows DOS is used on the mobile phone
It looks normal, but it is garbled by using shell commands .)
It is very easy to obtain the Common Unix format. Echo 'A'> a.txt under the Telnet command line,
The a.txt file is in the valid UNIX format. And e680 mobile phone file format are U8-Unix, is
It is coded in UTF-8.
Use the phone notepad to create a text file with the content "one, two, three". Run the cat command in the Telnet window to check
"?" Is displayed. 123 ", which obviously shows the encoding incompatibility. Opening the display with ultraedit is a U8-UNIX Cell
But the content is normal.

"One, two, three" common binary content in UNIX format:

D2 BB B6 Fe C8 FD

"One Two Three" UTF-8 format binary content:

FF Fe 00 4E 8C 4E 09 4E

This difference is obviously relatively large, when we operate the file through shell, once the file involves UTF-8 encoding
An error occurs. To solve this problem, you must perform encoding conversion. This part will be discussed in the future.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.