[mythtv-users] I-pod integration?

jedi jedi at mishnet.org
Wed Oct 21 16:50:12 UTC 2009


On Wed, Oct 21, 2009 at 10:44:40AM -0500, Mark Boyum wrote:
> >
> >    I even have a script that does that... pushes Rhythmbox playlists onto
> > my Archos and into the relevant mythmusic tables.
> >
> > > do, anyway. My entire music library is on by BE and then I
> > > periodically put some of it onto my ipod. I'm probably in the minority
> > > on this, but I don't use playlists either.
> >
> 
> At risk of derailing this thread, could you share the script that moves a
> playlist from Rhythmbox to mythmusic?  Creating a playlist in Rhythmbox is
> much earier in my opinion.

I set this stuff up in 2 parts. One script to pull and one script to push
for each of the datasources I was playing with. Keep in mind that these
were just something I was messing around with one night. 

They are still works in progress.

Use at your own risk.

--------------------------- pull-rbox.sh ---------------------

#!/bin/bash

PLAYLISTS="/home/jedi/Music/Playlists"

PLAYLIST_XML=/home/jedi/.local/share/rhythmbox/playlists.xml

EXCLUDE="Play Queue|My Top Rated|Recently Added|Recently Played"

######################################################################
function _find_end {
    _start=$1
    _ends=$2

    for _end in $_ends; do
	if [ $_end -gt $_start ]; then
	    echo $_end
	    return
	fi
    done
}
function _log {
    echo "$(date) -- $*"
}
######################################################################

cd $PLAYLISTS
echo "<PWD>$PWD"

LISTS=$( cat $PLAYLIST_XML | grep "playlist name" | egrep -v "$EXCLUDE" \
    | sed 's/.*name="//g' | sed 's/".*//g' | tr ' ' '^' )

ENDS=$( cat $PLAYLIST_XML | grep -n "</playlist>" | sed 's/:.*//g' | tr '\n' ' ' )
###echo "<ENDS>$ENDS"

_log "Extracting playlists from Rhythmbox..."

for list in $LISTS; do
    list=$(echo $list | tr '^' ' ' )
    ###echo $list

    out="$list.pls"

    _log "Extracting playlist [$out]..."

    START=$( cat $PLAYLIST_XML | grep -n "playlist name" \
	| grep "$list" | sed 's/:.*//g' )

    ###echo "<START>$START"

    END=$(_find_end "$START" "$ENDS")
    DELTA=$(expr $END - $START )
    ###echo "<DELTA>$DELTA"

    head -$END $PLAYLIST_XML | tail -$DELTA | grep "<location>" \
	| sed 's/<[/]*location>//g' | sed 's/.*file:/file:/g'  \
	| sed 's/%5B/[/g' | sed 's/%5D/]/g' \
	| sed "s/%B4/'/g" | sed 's/&amp;/&/g' > "$out"

done  

_log "Done."

--------------------------- push-mythtv.sh ---------------------

#!/bin/bash

PLAYLISTS="/home/jedi/Music/Playlists"

PLAYLIST_XML=/home/jedi/.local/share/rhythmbox/playlists.xml

EXCLUDE="Play Queue|My Top Rated|Recently Added|Recently Played"

######################################################################
function _find_end {
    _start=$1
    _ends=$2

    for _end in $_ends; do
	if [ $_end -gt $_start ]; then
	    echo $_end
	    return
	fi
    done
}
function _log {
    echo "$(date) -- $*"
}
######################################################################

cd $PLAYLISTS
echo "<PWD>$PWD"

LISTS=$( cat $PLAYLIST_XML | grep "playlist name" | egrep -v "$EXCLUDE" \
    | sed 's/.*name="//g' | sed 's/".*//g' | tr ' ' '^' )

ENDS=$( cat $PLAYLIST_XML | grep -n "</playlist>" | sed 's/:.*//g' | tr '\n' ' ' )
###echo "<ENDS>$ENDS"

_log "Extracting playlists from Rhythmbox..."

for list in $LISTS; do
    list=$(echo $list | tr '^' ' ' )
    ###echo $list

    out="$list.pls"

    _log "Extracting playlist [$out]..."

    START=$( cat $PLAYLIST_XML | grep -n "playlist name" \
	| grep "$list" | sed 's/:.*//g' )

    ###echo "<START>$START"

    END=$(_find_end "$START" "$ENDS")
    DELTA=$(expr $END - $START )
    ###echo "<DELTA>$DELTA"

    head -$END $PLAYLIST_XML | tail -$DELTA | grep "<location>" \
	| sed 's/<[/]*location>//g' | sed 's/.*file:/file:/g'  \
	| sed 's/%5B/[/g' | sed 's/%5D/]/g' \
	| sed "s/%B4/'/g" | sed 's/&amp;/&/g' > "$out"

done  

_log "Done."jedi at nomad:~/Music/Playlists$ cat push-mythtv.sh
#!/bin/bash

host=$(cat ~/.mythtv/mysql.txt | grep 'DBHostName=' | sed 's/DBHostName=//g')
user=$(cat ~/.mythtv/mysql.txt | grep 'DBUserName=' | sed 's/DBUserName=//g')
pass=$(cat ~/.mythtv/mysql.txt | grep 'DBPassword=' | sed 's/DBPassword=//g')

#############################################################################
function _mysql {
    _query=$1

    echo "$_query" | mysql --user=$user --password=$pass -h lars -D mythconverg

}
#############################################################################


MUSIC="/home/media/Music"

PLAYLISTS="/home/jedi/Music/Playlists"

ARCHOS="/media/archos/Playlists"

KEY="\/Music\/"


########################################################
########################################################
function _log {
    echo "$(date) -- $*"
}
function _get_song_id {

   song=$1

   genre=$( echo $song | awk -F '/' '{print $1}' )
   artist=$( echo $song | awk -F '/' '{print $2}' | sed "s/'/''/g" )
   album=$( echo $song | awk -F '/' '{print $3}' | sed "s/'/''/g" )
   name=$( echo $song | awk -F '/' '{print $4}' | sed "s/'/''/g" )

   album=$( id3 -l "$MUSIC/$song" 2> /dev/null | grep Album \
	    | sed 's/.*Album[ ]*:[ ]*//g' | sed 's/ *Year:.*//g' \
	    | sed "s/'/''/g" )
	
   artist=$( id3 -l "$MUSIC/$song" 2> /dev/null | grep Artist \
	    | sed 's/.*Artist: //g' | sed 's/  *$//g' \
	    | sed "s/'/''/g" )

   query="select song_id 
   from music_songs a,music_artists b,music_albums c
   where  a.artist_id = b.artist_id
   and a.album_id = c.album_id
   and b.artist_id = c.artist_id
   and artist_name='$artist'
   and album_name='$album' 
   and filename='$name' ;"

   song_id=$(_mysql "$query" | tail -1)

   echo "$song_id"

}
########################################################
########################################################

###-------------- Translate the App lists -----------###

cd $PLAYLISTS
FILES=$( ls *pls | tr ' ' '^' )

###echo "<FILES>$FILES"

for file in $FILES; do
    file=$(echo $file | tr '^' ' ' )
    ###echo $file

    _log "Fetching playlist data for [$file]..."

    songlist=""
    SONGS=$(cat "$file" \
	| grep "file:" | sed "s/.*$KEY//g"  | tr ' ' '^' \
	| sed 's/%5B/[/g' | sed 's/%5D/]/g' )
    for song in $SONGS; do

        song_id=$( _get_song_id "$song"	)

	if [ "$song_id" != "" ]; then
	    song_list="$song_list,$song_id"
	fi
    done
    
    ###-------------- Data for the Query ------------------###
    list_title=$(echo $file | sed 's/.pls$//g' )
    song_list=$(echo "$song_list" | sed 's/^,//g' )
    song_count=$(echo "$song_list" | tr ',' '\n' | wc -l ) 

    ###echo "<song_title>$song_title"
    ###echo "<song_list>$song_list"
    ###echo "<song_count>$song_count"


    ###-------------- Is the list already in the DB? -------###
    
    query="select count(*) from music_playlists
           where playlist_name='$list_title';"
    flag=$(_mysql "$query" | tail -1)


    ###-------------- Copy to MythTV DB --------------------###
    if [ "$flag" -eq 1 ]; then
	_log "Updating [$list_title] data in myth database..."

	query="
        update music_playlists 
        set playlist_songs='$song_list',
        songcount=$song_count,
        hostname=''
        where playlist_name='$list_title';"

	#echo "<query>$query"

        _mysql "$query"
    else
	_log "Inserting [$list_title] data in myth database..."
	query="
        delete from music_playlists where playlist_name='$list_title';

        insert into music_playlists (playlist_name,playlist_songs,songcount) 
        values ('$list_title','$song_list',$song_count);"

	_mysql "$query"
    fi
    ###-------------- Copy to MythTV DB --------------------###

    song_list="" ### Clear the list for the next pass ###

done 



More information about the mythtv-users mailing list