pepoとネットワークを語ろう

40年前からこれまでとこれからのネットワークを語る

Linuxスクリプトでpodcastのmp3ファイルをゲット!その3

2010-12-15 08:04:06 | Linux

いろいろなpodcastのサイトを見てみると少しenclosureの書き方がマチマチなので少し改良して見た

#!/bin/sh
# licence GPLv2 ; this scripts designed by IZAMUKARERA 2010.12.12 update 2010.12.14
# get podcast mp3
# XMLにpodcastのURLを登録
#XML=http://podcast.1242.com/ps/index.xml
#XML=http://podcasts.voanews.com/podcastxml_local.cfm?id=1631
XML=http://www3.nhk.or.jp/rj/podcast/rss/english.xml
#XML=http://www.cnn.com/services/podcasting/newscast/rss.xml
# CTは保存世代数(古い順に消去)
CT=4
# DEVはMP3プレーヤーのデバイス名
DEV=/dev/sdb1
MNT=/mnt/music
MDIR=$MNT/podcast
DIR=/tmp/music
RAND=`echo -e $RANDOM`
TMP=$DIR/${RAND}.xml
[ ! -e $DIR ] && mkdir -p $DIR
wget $XML -O $TMP
URL=`cat $TMP |awk '/enclosure/{split($0,I,"\"")
  for ( J in I ) {
    if (I[J] ~ /\.mp3$/) {
      printf I[J]" "
    }
  }
}'`
for FIL in $URL
do
  MP3=`echo $FIL |awk '{s=split($0,I,"/"); printf I[s]}'`
  [ -f $DIR/$MP3 ] && continue
  wget $FIL -O $DIR/$MP3
  [ ! -s $DIR/$MP3 ] && rm -f $DIR/$MP3
done
rm -f $TMP
[ ! -e $MNT ] && mkdir -p $MNT
mount $DEV $MNT -t vfat >/dev/null 2>&1
[ `mount |grep $DEV |wc -l` -eq 1 ] && MDEV=OK || MDEV=NG
if [ $MDEV = "OK" ];then
  [ ! -e $MDIR ] && mkdir -p $MDIR
  MFIL=`ls -tr $MDIR`
  MCT=`echo $MFIL | wc -w`
  if [ $MCT -gt $CT ];then
    I=`expr $MCT - $CT`
    for J in $MFIL
    do
#      echo "rm -f $MDIR/$J"
      rm -f $MDIR/$J
      I=`expr $I - 1`
      [ $I -eq 0 ] && break
    done
  fi
  MFIL=`ls -tr $DIR`
  for MM in $MFIL
  do
    if [ -s $DIR/$MM ];then
      mv -f $DIR/$MM $MDIR
    fi
  done
fi

[ $MDEV = "OK" ] && umount $DEV

これでどうだ  

pepo


Linuxスクリプトでpodcastのmp3ファイルをゲット!その2

2010-12-14 08:30:02 | Linux

 さて、wgetでpodcastのmp3ファイルをゲットするスクリプトが出来たので

少し欲をだして自動的にファイルを更新するようにした

ストーリーとしてはこうだ

mp3プレーヤーを寝る前にLinuxマシンのUSBへ差し込む

cronで指定した時間に自動的に最新のmp3ファイルをwget

朝になったら抜き取り、通勤電車の中で新しいニュース等が聞く

それと古いニュースは要らないので、世代管理数を指定して古いファイルmp3順に削除する

#!/bin/sh
# licence GPLv2 ; this scripts designed by IZAMUKARERA 2010.12.12
# get podcast mp3
# XMLにpodcastのURLを登録
XML=http://www3.nhk.or.jp/rj/podcast/rss/english.xml
#XML=http://www.cnn.com/services/podcasting/newscast/rss.xml
# CTは保存世代数(古い順に消去)
CT=4
# DEVはMP3プレーヤーのデバイス名
DEV=/dev/sdb1
MNT=/mnt/music
MDIR=$MNT/podcast
DIR=/tmp/music
RAND=`echo -e $RANDOM`
TMP=$DIR/${RAND}.xml
[ ! -e $DIR ] && mkdir -p $DIR
wget $XML -O $TMP

URL=`cat $TMP |awk '/enclosure url=/{split($0,I,"\"");{printf I[2]" "} }'`
for FIL in $URL
do
  MP3=`echo $FIL |awk '{s=split($0,I,"/"); printf I[s]}'`
  [ -f $DIR/$MP3 ] && continue
  wget $FIL -O $DIR/$MP3
  [ ! -s $DIR/$MP3 ] && rm -f $DIR/$MP3
done
rm -f $TMP

[ ! -e $MNT ] && mkdir -p $MNT
mount $DEV $MNT -t vfat >/dev/null 2>&1
[ `mount |grep $DEV |wc -l` -eq 1 ] && MDEV=OK || MDEV=NG
if [ $MDEV = "OK" ];then
  [ ! -e $MDIR ] && mkdir -p $MDIR
  MCT=`ls -tr $MDIR`
  if [ `echo $MCT | wc -w` -gt $CT ];then
    I=$CT
    for J in $MCT
      {
        rm -f $MDIR/$J
        I=`expr $I - 1`
        [ $I -eq 0 ] && break
    }
  fi
  MCT=`ls -tr $DIR`
  for MM in $MCT
  {
    if [ -s $DIR/$MM ];then
      mv -f $DIR/$MM $MDIR
    fi
  }
fi

[ $MDEV = "OK" ] && umount $DEV

pepo


Linuxスクリプトでpodcastのmp3ファイルをゲット!

2010-12-06 07:48:28 | Linux

itunesを使っていると、podcastで無料のニュースをMP3で聞けると知って、暫く前からゲットMP3プレヤーで聞いている
しかし、毎回itunesを立ち上げるのも邪魔くさいし、たまの休みにはゲットし損ねるので、linuxで少し手抜き気味ではあるが頭の
体操としてスクリプトを書いてみたよ、全然しらんかったがitunesのpodcastのURLをコピーしてwgetするとこんな中身

[root@~]# wget http://www3.nhk.or.jp/rj/podcast/rss/english.xml
--2010-12-03 12:26:16--  http://www3.nhk.or.jp/rj/podcast/rss/english.xml
Resolving www3.nhk.or.jp... 60.254.185.158, 60.254.185.184
Connecting to www3.nhk.or.jp|60.254.185.158|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1503 (1.5K) [text/xml]
Saving to: `english.xml'

100%[================================================>] 1,503       --.-K/s   in 0.002s

2010-12-03 12:26:16 (730 KB/s) - `english.xml' saved [1503/1503]

wgetでセーブしたenglish.xmlの内容を確認
[root@~]# cat english.xml
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0">
 <channel>
  <copyright>NHK (Japan Broadcasting Corporation)</copyright>
  <description>This is the latest news in English from NHK WORLD RADIO JAPAN. This service is updated twice a day (3 times on weekends). For more information, please go to http://www.nhk.or.jp/english/.</description>
  <itunes:subtitle>This is the latest news in English from NHK WORLD RADIO JAPAN. This service is updated twice a day (3 times on weekends). For more information, please go to http://www.nhk.or.jp/english/.</itunes:subtitle>
  <itunes:author>NHK (Japan Broadcasting Corporation)</itunes:author>
  <itunes:image href="http://www.nhk.or.jp/rj/images/english.jpg"></itunes:image>
  <language>en</language>
  <link>http://www.nhk.or.jp/english/</link>
  <lastBuildDate>Fri, 03 Dec 2010 19:22:09 +0900</lastBuildDate>
  <title>NW English News - NHK WORLD RADIO JAPAN</title>
  <itunes:category text="News"></itunes:category>
  <item>
   <enclosure url="http://www9.nhk.or.jp/rj/podcast/mp3/20101203190100_1_1_english.mp3" length="7202442" type="audio/mpeg"></enclosure>
   <title>NHK WORLD RADIO JAPAN - English News at 19:01 (JST), December 3</title>
   <itunes:author>NHK (Japan Broadcasting Corporation)</itunes:author>
   <itunes:duration>15:00</itunes:duration>
   <itunes:category text="News"></itunes:category>
   <pubDate>Fri, 03 Dec 2010 19:22:09 +0900</pubDate>
  </item>
 </channel>
</rss>

       

[root@~]#
必要な行は、enclosure url="http://www9.nhk.or.jp/rj/podcast/mp3/20101202210100_1_1_english.mp3" だけなので、これをwgetすれば良い
crontabに登録すれば定期的に更新されるニュースなどのmp3ファイルを自動で取得できるよ
[root@~]# cat cnn.sh
#!/bin/sh
# licence GPLv2 ; this scripts designed by IZAMUKARERA 2010.12.3
# get podcast mp3
#XML=http://www3.nhk.or.jp/rj/podcast/rss/english.xml
XML=http://www.cnn.com/services/podcasting/newscast/rss.xml
DIR=/tmp/music
RAND=`echo -e $RANDOM`
TMP=/$DIR/${RAND}.xml
[ ! -e $DIR ] && mkdir -p $DIR
wget $XML -O $TMP

URL=`cat $TMP |awk '/enclosure url=/{split($0,I,"\"");{printf I[2]" "} }'`
for FIL in $URL
do
  MP3=`echo $FIL |awk '{s=split($0,I,"/"); printf I[s]}'`
  [ -f $DIR/$MP3 ] && continue
  wget $FIL -O $DIR/$MP3
  [ ! -s $DIR/$MP3 ] && rm -f $DIR/$MP3
done

rm -f $TMP

でわ、実際に起動してみると
[root@~]# ./cnn.sh
--2010-12-03 12:36:02--  http://www.cnn.com/services/podcasting/newscast/rss.xml
Resolving www.cnn.com... 157.166.224.25, 157.166.224.26, 157.166.226.25, ...
Connecting to www.cnn.com|157.166.224.25|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6564 (6.4K) [application/xml]
Saving to: `//tmp/music/21468.xml'

100%[===============================================================>] 6,564       34.1K/s   in 0.2s

2010-12-03 12:36:03 (34.1 KB/s) - `//tmp/music/21468.xml' saved [6564/6564]

--2010-12-03 12:36:03--  http://www.podtrac.com/pts/redirect.mp3/podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-10PM.mp3
Resolving www.podtrac.com... 69.16.232.36
Connecting to www.podtrac.com|69.16.232.36|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-10PM.mp3 [following]
--2010-12-03 12:36:04--  http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-10PM.mp3
Resolving podcasts.cnn.net... 202.229.2.98, 202.229.2.82
Connecting to podcasts.cnn.net|202.229.2.98|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1044773 (1020K) [audio/mpeg]
Saving to: `/tmp/music/CNN-News-12-02-10-10PM.mp3'

100%[===============================================================>] 1,044,773    359K/s   in 2.8s

2010-12-03 12:36:07 (359 KB/s) - `/tmp/music/CNN-News-12-02-10-10PM.mp3' saved [1044773/1044773]

--2010-12-03 12:36:07--  http://www.podtrac.com/pts/redirect.mp3/podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-9PM.mp3
Resolving www.podtrac.com... 69.16.232.36
Connecting to www.podtrac.com|69.16.232.36|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-9PM.mp3 [following]
--2010-12-03 12:36:07--  http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-9PM.mp3
Resolving podcasts.cnn.net... 202.229.2.98
Connecting to podcasts.cnn.net|202.229.2.98|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1044145 (1020K) [audio/mpeg]
Saving to: `/tmp/music/CNN-News-12-02-10-9PM.mp3'

100%[===============================================================>] 1,044,145    361K/s   in 2.8s

2010-12-03 12:36:10 (361 KB/s) - `/tmp/music/CNN-News-12-02-10-9PM.mp3' saved [1044145/1044145]

--2010-12-03 12:36:10--  http://www.podtrac.com/pts/redirect.mp3/podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-8PM.mp3
Resolving www.podtrac.com... 69.16.232.36
Connecting to www.podtrac.com|69.16.232.36|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-8PM.mp3 [following]
--2010-12-03 12:36:11--  http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-8PM.mp3
Resolving podcasts.cnn.net... 202.229.2.98
Connecting to podcasts.cnn.net|202.229.2.98|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1043727 (1019K) [audio/mpeg]
Saving to: `/tmp/music/CNN-News-12-02-10-8PM.mp3'

100%[===============================================================>] 1,043,727    361K/s   in 2.8s

2010-12-03 12:36:13 (361 KB/s) - `/tmp/music/CNN-News-12-02-10-8PM.mp3' saved [1043727/1043727]

--2010-12-03 12:36:14--  http://www.podtrac.com/pts/redirect.mp3/podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-7PM.mp3
Resolving www.podtrac.com... 69.16.232.36
Connecting to www.podtrac.com|69.16.232.36|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-7PM.mp3 [following]
--2010-12-03 12:36:14--  http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-7PM.mp3
Resolving podcasts.cnn.net... 202.229.2.98
Connecting to podcasts.cnn.net|202.229.2.98|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1047280 (1023K) [audio/mpeg]
Saving to: `/tmp/music/CNN-News-12-02-10-7PM.mp3'

100%[===============================================================>] 1,047,280    360K/s   in 2.8s

2010-12-03 12:36:17 (360 KB/s) - `/tmp/music/CNN-News-12-02-10-7PM.mp3' saved [1047280/1047280]

--2010-12-03 12:36:17--  http://www.podtrac.com/pts/redirect.mp3/podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-6PM.mp3
Resolving www.podtrac.com... 69.16.232.36
Connecting to www.podtrac.com|69.16.232.36|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-6PM.mp3 [following]
--2010-12-03 12:36:17--  http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-6PM.mp3
Resolving podcasts.cnn.net... 202.229.2.98
Connecting to podcasts.cnn.net|202.229.2.98|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1043309 (1019K) [audio/mpeg]
Saving to: `/tmp/music/CNN-News-12-02-10-6PM.mp3'

100%[===============================================================>] 1,043,309    362K/s   in 2.8s

2010-12-03 12:36:20 (362 KB/s) - `/tmp/music/CNN-News-12-02-10-6PM.mp3' saved [1043309/1043309]

--2010-12-03 12:36:20--  http://www.podtrac.com/pts/redirect.mp3/podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-5PM.mp3
Resolving www.podtrac.com... 69.16.232.36
Connecting to www.podtrac.com|69.16.232.36|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-5PM.mp3 [following]
--2010-12-03 12:36:21--  http://podcasts.cnn.net/cnn/services/podcasting/newscast/audio/2010/12/02/CNN-News-12-02-10-5PM.mp3
Resolving podcasts.cnn.net... 202.229.2.98
Connecting to podcasts.cnn.net|202.229.2.98|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1044981 (1020K) [audio/mpeg]
Saving to: `/tmp/music/CNN-News-12-02-10-5PM.mp3'

100%[===============================================================>] 1,044,981    361K/s   in 2.8s

2010-12-03 12:36:24 (361 KB/s) - `/tmp/music/CNN-News-12-02-10-5PM.mp3' saved [1044981/1044981]

[root@~]# ll /tmp/music/
total 6180
-rw-r--r-- 1 root root 1044773 12月  3 12:11 CNN-News-12-02-10-10PM.mp3
-rw-r--r-- 1 root root 1044981 12月  3 07:58 CNN-News-12-02-10-5PM.mp3
-rw-r--r-- 1 root root 1043309 12月  3 08:58 CNN-News-12-02-10-6PM.mp3
-rw-r--r-- 1 root root 1047280 12月  3 09:58 CNN-News-12-02-10-7PM.mp3
-rw-r--r-- 1 root root 1043727 12月  3 10:58 CNN-News-12-02-10-8PM.mp3
-rw-r--r-- 1 root root 1044145 12月  3 11:58 CNN-News-12-02-10-9PM.mp3
おーと、mp3ファイルがぎょうさんゲットできとるわ

pepo


CentOS5.4へruby-1.8.7-p302をrpmパッケージを作成してインストールに挑戦!

2010-12-04 08:30:09 | Linux

CentOS5.4へrubyのruby-1.8.7-p302をrpmパッケージを作成してインストールに挑戦!

途中『tempディレクトリにファイルをコピー』で1時間程だんまりとなるが我慢して待とう

[root@p-4 ~]# tar xvfj ruby-1.8.7-p302.tar.bz2

[root@p-4 ~]# wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p302.tar.bz2
--2010-11-28 13:57:29--  ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p302.tar.bz2
           => `ruby-1.8.7-p302.tar.bz2'
Resolving ftp.ruby-lang.org... 221.186.184.68
Connecting to ftp.ruby-lang.org|221.186.184.68|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD /pub/ruby/1.8 ... done.
==> SIZE ruby-1.8.7-p302.tar.bz2 ... 4184764
==> PASV ... done.    ==> RETR ruby-1.8.7-p302.tar.bz2 ... done.
Length: 4184764 (4.0M)

100%[======================================>] 4,184,764    357K/s   in 11s

2010-11-28 13:57:40 (357 KB/s) - `ruby-1.8.7-p302.tar.bz2' saved [4184764]

[root@p-4 ~]# tar xvfj ruby-1.8.7-p302.tar.bz2
ruby-1.8.7-p302/

[root@p-4 ~]# cd ruby-1.8.7-p302
[root@p-4 ruby-1.8.7-p302]# ./configure
checking build system type... i686-pc-linux-gnu

config.status: creating Makefile
[root@p-4 ruby-1.8.7-p302]# make
gcc -g -O2    -DRUBY_EXPORT -D_GNU_SOURCE=1  -I. -I.    -c array.c
gcc -g -O2    -DRUBY_EXPORT -D_GNU_SOURCE=1  -I. -I.    -c bignum.c
[root@p-4 ruby-1.8.7-p302]# checkinstall

checkinstall 1.6.2, Copyright 2009 Felipe Eduardo Sanchez Diaz Duran
           This software is released under the GNU GPL.

The checkinstallrc file was not found at:
/usr/local/sbin/../checkinstallrc

Assuming default values.

The package documentation directory ./doc-pak does not exist.
Should I create a default set of package docs?  [y]: y

Preparing package documentation...OK

Please choose the packaging method you want to use.
Slackware [S], RPM [R] or Debian [D]? R


Please write a description for the package.
End your description with an empty line or EOF.
>> ruby-1.8.7-p302-pepo
>>

**************************************
**** RPM package creation selected ***
**************************************

This package will be built according to these values:

1 -  Summary: [ ruby-1.8.7-p302-pepo ]
2 -  Name:    [ ruby-1.8.7 ]
3 -  Version: [ p302 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ Applications/System ]
7 -  Architecture: [ i386 ]
8 -  Source location: [ ruby-1.8.7-p302 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ ruby-1.8.7 ]

Enter a number to change any of them or press ENTER to continue:

Installing with make install...

========================= Installation results ===========================
./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb  ./instruby.rb --make="make" --dest-dir="" --extout=".ext" --mflags="" --make-flags="" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --mantype="doc"
installing binary commands
installing command scripts
installing library scripts
installing headers
installing manpages
installing extension objects
installing extension scripts

======================== Installation successful ==========================

Copying documentation directory...
./
./doc/
./doc/shell.rd.ja
./doc/ChangeLog-1.8.0
./doc/shell.rd
./doc/forwardable.rd.ja
./doc/forwardable.rd
./doc/NEWS-1.8.0
./doc/irb/
./doc/irb/irb-tools.rd.ja
./doc/irb/irb.rd
./doc/irb/irb.rd.ja
./ChangeLog
./README.EXT.ja
./README.EXT
./GPL
./README
./NEWS
./README.ja
./COPYING
./COPYING.ja

Copying files to the temporary directory...OK

Stripping ELF binaries...OK

Compressing man pages...OK

Building file list...OK

Building RPM package...OK

NOTE: The package will not be installed

Erasing temporary files...OK

Deleting doc-pak directory...OK

Writing backup package...OK
OK

Deleting temp dir...OK


**********************************************************************

 Done. The new package has been saved to

 /usr/src/redhat/RPMS/i386/ruby-1.8.7-p302-1.i386.rpm
 You can install it in your system anytime using:

      rpm -i ruby-1.8.7-p302-1.i386.rpm

**********************************************************************

[root@p-4 ruby-1.8.7-p302]#

[root@p-4 ruby-1.8.7-p302]# rpm -i /usr/src/redhat/RPMS/i386/ruby-1.8.7-p302-1.i386.rpm

[root@p-4 ruby-1.8.7-p302]# rpm -qa |grep ruby
ruby-1.8.7-p302-1

[root@p-4 ruby-1.8.7-p302]# ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]

pepo