-
-
Save smartest/3991cd4c14a8aa0c4f55 to your computer and use it in GitHub Desktop.
Extract Playlist from Plex Server Linux to m3u
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#echo "#EXTM3U" | |
#sqlite3 /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/com.plexapp.plugins.library.db "select file from media_parts left outer join media_items on media_items.id = media_parts.media_item_id left outer join play_queue_generators on play_queue_generators.metadata_item_id = media_items.metadata_item_id left outer join metadata_items on metadata_items.id = play_queue_generators.playlist_id where play_queue_generators.playlist_id='9567'" | |
WorkDir="`dirname $0`" | |
PlaylistDir="/mnt/Playlists" | |
TheLastLog="${PlaylistDir}/plexlog.inf" | |
plexdb="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" | |
IFS=$'\n' | |
PlaylistTable=`sqlite3 "${plexdb}" "select * from metadata_items where metadata_items.metadata_type='15'"` | |
if [ "$PlaylistTable" = "$(< ${TheLastLog})" ] | |
then | |
# echo "No change..." | |
exit 1 | |
fi | |
echo "${PlaylistTable}" > "${TheLastLog}" | |
m3us=( `ls ${PlaylistDir}/*.m3u` ) | |
PlaylistTitles=(`sqlite3 "${plexdb}" "select title from metadata_items where metadata_items.metadata_type='15'"`) | |
PlaylistIds=(`sqlite3 "${plexdb}" "select id from metadata_items where metadata_items.metadata_type='15'"`) | |
#echo ${PlaylistTitles[@]} | |
for playlistid in "${PlaylistIds[@]}" | |
do | |
title=`sqlite3 "${plexdb}" "select title from metadata_items where metadata_items.id=${playlistid}"` | |
contents=(`sqlite3 "${plexdb}" "select file from media_parts left outer join media_items on media_items.id = media_parts.media_item_id left outer join play_queue_generators on play_queue_generators.metadata_item_id = media_items.metadata_item_id left outer join metadata_items on metadata_items.id = play_queue_generators.playlist_id where play_queue_generators.playlist_id='${playlistid}'"`) | |
m3ufile="${PlaylistDir}/${title}.m3u" | |
m3us=( "${m3us[@]/$m3ufile/}" ) | |
# old=$(<"${m3ufile}") | |
new=$'#EXTM3U\n'${contents[*]} | |
if [ "$new" != "$(< ${m3ufile})" ] | |
then | |
echo "${new}" > "${m3ufile}" | |
# else | |
# echo "same!!!" | |
fi | |
done | |
#echo "${m3us[@]} ---${#m3us[@]}" | |
for f in "${m3us[@]}" | |
do | |
echo "#EXTM3U" > "$f" | |
# rm -f "$f" | |
# echo "$f--" | |
# echo "---" | |
done | |
wget "http://10.0.1.47:9000/rpc/rescan" > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment