Any help with a batch script please?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Hitcher Offline
Skilled Skinner
Posts: 9,976
Joined: Aug 2007
Reputation: 67
Location: Eastleigh, UK
Post: #1
I'm trying to combine the contents of the addon.xml files into one using a batch file.

I've got as far as getting the correct info but can't output it to another xml.

Here's what I'm using to get the contents (skipping the first line of each) -

Code:
@echo off
FOR /F "skip=1 delims=" %%A IN (plugin.video.iplayer\addon.xml skin.foundation\addon.xml skin.xeebo\addon.xml xbmc.repo.hitcher\addon.xml) DO ECHO %%A
pause

This results in -

Code:
<addon id="plugin.video.iplayer"
       name="iPlayer"
       version="2.4.13"
       provider-name="BuZz, Dink">
    <requires>
        <import addon="xbmc.python" version="1.0"/>
    </requires>
    <extension point="xbmc.python.pluginsource"
               library="default.py">
        <provides>video audio</provides>
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <summary>Watch TV and listen to radio from the BBC's iPlayer website</summary>
        <description>This XBMC plugin enables (UK only) the playing of TV and Radio catchup content
from the BBC IPlayer website. Live radio and TV feeds are also supported.</description>
    </extension>
</addon>
<addon
        id="skin.foundation"
        version="2.0.1"
        name="Foundation"
        provider-name="Hitcher">
        <requires>
                <import addon="xbmc.gui" version="3.00"/>
        </requires>
        <extension
    point="xbmc.gui.skin"
    defaultthemename="textures.xbt"
    debugging="false"
    effectslowdown="0.75">
                <res width="1280" height="720" aspect="16:9" default="true" folder="720p" />
                <res width="1920" height="1080" aspect="16:9" default="true" folder="1080i" />
        </extension>
        <extension point="xbmc.addon.metadata">
                <platform>all</platform>
                <summary>Created by Hitcher / Textures courtesy of Jezz_X</summary>
                <description>'Foundation' is a basic, fully functional XBMC skin designed to be used
as a base for creating a new skin; or simply as a learning tool for the beginner.</description>
        </extension>
</addon>
<addon
        id="skin.xeebo"
        version="4.0.0"
        name="XeeBo"
        provider-name="Hitcher">
        <requires>
                <import addon="xbmc.gui" version="3.00"/>
                <import addon="script.playalbum" version="0.0.3"/>
                <import addon="script.watchlist" version="0.0.4"/>
                <import addon="script.favourites" version="3.1.0"/>
                <import addon="script.randomitems" version="3.0.2"/>
                <import addon="script.globalsearch" version="0.1.5"/>
                <import addon="script.artwork.downloader" version="1.0.3"/>
                <import addon="script.tv.show.next.aired" version="3.0.2"/>
        </requires>
        <extension
                point="xbmc.gui.skin"
                defaultthemename="Textures.xbt"
                effectslowdown="1.00"
                debugging="false">
                <res width="1280" height="720" aspect="16:9" default="true" folder="720p" />
        </extension>
        <extension point="xbmc.addon.metadata">
                <platform>all</platform>
                <minversion app="xbmc">28000</minversion>
                <summary>Boxee style skin</summary>
                <description>Designed for ease of use with remote, mouse or touchscreen.[CR][CR]Supp
orts -[CR][CR]Cinema Experience / Extra Artwork / Global Search / PVR / TV Next Aired / TV Tunes / W
atchlist / Weather Plus</description>
                <disclaimer>Originally coded by Wir3d/Jezz_X</disclaimer>
        </extension>
</addon>
<addon
        id="xbmc.repo.hitcher"
        name="Hitcher's repository"
        version="2.0.0"
        provider-name="Hitcher">
        <extension point="xbmc.addon.repository"
        name="Hitcher's Add-on Repository">
                <info>https://bitbucket.org/Hitcher/xbmc.repo.hitcher/raw/57094dbd903a/addons.xml</i
nfo>
                <checksum>https://bitbucket.org/Hitcher/xbmc.repo.hitcher/raw/57094dbd903a/addons.md
5</checksum>
                <datadir zip="true">https://bitbucket.org/Hitcher/xbmc.repo.hitcher/src/585aad574523
</datadir>
        </extension>
        <extension point="xbmc.addon.metadata">
                <summary>Hitcher's Add-ons for XBMC</summary>
                <description>Download and install Add-ons for XBMC.</description>
                <disclaimer>If it breaks, you get to keep the pieces</disclaimer>
                <platform>all</platform>
        </extension>
</addon>
Press any key to continue . . .

If I make this a variable and try to output it to the addons.xml it doesn't work.

Any help appreciated.

Thanks.

[Image: sig_zps3af3b48e.jpg]
find quote
Sinnocence Offline
Member+
Posts: 97
Joined: Oct 2007
Reputation: 4
Post: #2
Will redirecting the output satisfy your needs (i.e. remove the pause and run: mybatch.bat > addons.xml) ?
find quote
tree_jammer Offline
Team-XBMC Member
Posts: 50
Joined: Apr 2009
Reputation: 17
Post: #3
Sinnocense is correct! this will work


@echo off
FOR /F "skip=1 delims=" %%A IN (plugin.video.iplayer\addon.xml skin.foundation\addon.xml skin.xeebo\addon.xml xbmc.repo.hitcher\addon.xml) DO ECHO %%A
mybatch.bat > addons.xml
(This post was last modified: 2012-03-13 11:26 by tree_jammer.)
find quote
Hitcher Offline
Skilled Skinner
Posts: 9,976
Joined: Aug 2007
Reputation: 67
Location: Eastleigh, UK
Post: #4
Thanks guys, worked great.

Now how can I add text to the top and bottom of the output files?

Top -

PHP Code:
<?xml version="1.0" encoding="UTF-8"?>
<addons> 

Bottom -

PHP Code:
</addons

[Image: sig_zps3af3b48e.jpg]
find quote
Sinnocence Offline
Member+
Posts: 97
Joined: Oct 2007
Reputation: 4
Post: #5
You can just 'echo' it out, something like:

Code:
@echo off
echo ^<?xml version="1.0" encoding="UTF-8"?^>
echo ^<addons^>
FOR /F "skip=1 delims=" %%A IN (plugin.video.iplayer\addon.xml skin.foundation\addon.xml skin.xeebo\addon.xml xbmc.repo.hitcher\addon.xml) DO ECHO %%A
echo ^</addons^>

Note the inclusion of '^' before characters that have special meaning in dos. If you're adding more content to the bat file and start getting errors like "The syntax of the command is incorrect." then you're likely missing a '^' somewhere.
(This post was last modified: 2012-03-13 13:00 by Sinnocence.)
find quote
Hitcher Offline
Skilled Skinner
Posts: 9,976
Joined: Aug 2007
Reputation: 67
Location: Eastleigh, UK
Post: #6
Cool, I'm slowly learning it.

So far I've managed build, zip, add the version number to the zipped skin and changelog file, and finally move them to my repo folder. This is the next step and I've worked out how to make a MD5 file from the addons.xml but actually making it had me stuck.

If you don't mind there a couple of other things I'd like to achieve -

1. Would it be possible to search the sub folders for their addon.xml files without using their actually names?

2. Can the addons.xml build bat be run from another bat file?

Many thanks.

[Image: sig_zps3af3b48e.jpg]
find quote
Sinnocence Offline
Member+
Posts: 97
Joined: Oct 2007
Reputation: 4
Post: #7
(2012-03-13 12:11)Hitcher Wrote:  1. Would it be possible to search the sub folders for their addon.xml files without using their actually names?

You can list all the addon.xml files in all subdirectories by doing something like
Code:
dir addon.xml /s /b

(2012-03-13 12:11)Hitcher Wrote:  2. Can the addons.xml build bat be run from another bat file?

You can use 'call' or just the bat file name (path depending) to execute another bat file.

Putting the above together you might end up with something like:

Code:
for /f %%f in ('dir /s /b addon.xml') do mybatch.bat %%f

in a file called wrapper.bat (where /s includes subdirectories and /b strips other file info from the output of the dir command). Both wrapper.bat and mybatch.bat (your other file) should exist in parent directory for all addons you want to include (presumably your 'addon' directory).

If you have spaces in your file/directory names you may need to use a slightly more complicated version of the command, e.g.:

current directory & subdirectories
Code:
for /f "usebackq delims=|" %%f in (`dir /b /s "." ^| findstr /i addon.xml`) do mybatch.bat %%f

or

c:\xbmc\addons & subdirectories
Code:
for /f "usebackq delims=|" %%f in (`dir /b /s "C:\XBMC\addons" ^| findstr /i addon.xml`) do mybatch.bat %%f

[edit] the above is only an example answer for the question you asked. Assuming for the moment that you're trying to scan all addon.xml files under the addons directory and dump the concatinated output into addons.xml you can use a single.bat file. Recycling the above content gives us:

Code:
@echo off
SETLOCAL EnableDelayedExpansion
echo ^<?xml version="1.0" encoding="UTF-8"?^>
echo ^<addons^>
for /f "usebackq delims=|" %%f in (`dir /b /s "D:\programs\xbmc\portable_data\" ^| findstr /i addon.xml`) do (
   echo %%f
   SET "path=%%f"
   Call:DumpAddonXML !path!
   )
)
goto :END

:DumpAddonXML
echo %*
for /f "skip=1 delims=" %%a in (%*) do echo %%a
goto :eof

:END
echo ^</addons^>


If you wanted to make it less verbose, and automatically output into the directory where the .bat file is called (into addons.xml) you could make the following changes. This would mean that you could drop the .bat file into an addon directory & double click the file. Once finished addons.xml should exist in the directory with the desired content.
Code:
@echo off
SETLOCAL EnableDelayedExpansion
echo ^<?xml version="1.0" encoding="UTF-8"?^> >addons.xml
echo ^<addons^> >>addons.xml
for /f "usebackq delims=|" %%f in (`dir /b /s "." ^| findstr /i addon.xml`) do (
   SET "path=%%f"
   Call:DumpAddonXML !path!
   )
)
goto :END

:DumpAddonXML
for /f "skip=1 delims=" %%a in (%*) do echo %%a >>addons.xml
goto :eof

:END
echo ^</addons^> >>addons.xml

Please note that the ">addons.xml" is used on the first output line to either a) create a new file or b) overwrite an existing addons.xml file. Successive output lines use ">>addons.xml" in order to append content to the file.

[/edit]
(This post was last modified: 2012-03-13 13:18 by Sinnocence.)
find quote
Hitcher Offline
Skilled Skinner
Posts: 9,976
Joined: Aug 2007
Reputation: 67
Location: Eastleigh, UK
Post: #8
That's awesome, thanks for all the help and have some rep.

EDIT: Almost there unfortunately it's not stripping the first line from each addon.xml <?xml version="1.0" encoding="UTF-8"?>

EDIT2: Actually it is but for some reason they're getting listed twice - once with that and once without.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<addons>
<addon id="plugin.video.iplayer"
       name="iPlayer"
       version="2.4.13"
       provider-name="BuZz, Dink">
    <requires>
        <import addon="xbmc.python" version="1.0"/>
    </requires>
    <extension point="xbmc.python.pluginsource"
               library="default.py">
        <provides>video audio</provides>
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <summary>Watch TV and listen to radio from the BBC's iPlayer website</summary>
        <description>This XBMC plugin enables (UK only) the playing of TV and Radio catchup content from the BBC IPlayer website. Live radio and TV feeds are also supported.</description>
    </extension>
</addon>
<?xml version="1.0" encoding="UTF-8"?>
<addon
    id="skin.foundation"
    version="2.0.1"
    name="Foundation"
    provider-name="Hitcher">
    <requires>
        <import addon="xbmc.gui" version="3.00"/>
    </requires>
    <extension
    point="xbmc.gui.skin"
    defaultthemename="textures.xbt"
    debugging="false"
    effectslowdown="0.75">
        <res width="1280" height="720" aspect="16:9" default="true" folder="720p" />
        <res width="1920" height="1080" aspect="16:9" default="true" folder="1080i" />
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <summary>Created by Hitcher / Textures courtesy of Jezz_X</summary>
        <description>'Foundation' is a basic, fully functional XBMC skin designed to be used as a base for creating a new skin; or simply as a learning tool for the beginner.</description>
    </extension>
</addon><?xml version="1.0" encoding="UTF-8"?>
<addon
    id="skin.xeebo"
    version="4.0.0"
    name="XeeBo"
    provider-name="Hitcher">
    <requires>
        <import addon="xbmc.gui" version="3.00"/>
        <import addon="script.playalbum" version="0.0.3"/>
        <import addon="script.watchlist" version="0.0.4"/>
        <import addon="script.favourites" version="3.1.0"/>
        <import addon="script.randomitems" version="3.0.2"/>
        <import addon="script.globalsearch" version="0.1.5"/>
        <import addon="script.artwork.downloader" version="1.0.3"/>
        <import addon="script.tv.show.next.aired" version="3.0.2"/>
    </requires>
    <extension
        point="xbmc.gui.skin"
        defaultthemename="Textures.xbt"
        effectslowdown="1.00"
        debugging="false">
        <res width="1280" height="720" aspect="16:9" default="true" folder="720p" />
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <minversion app="xbmc">28000</minversion>
        <summary>Boxee style skin</summary>
        <description>Designed for ease of use with remote, mouse or touchscreen.[CR][CR]Supports -[CR][CR]Cinema Experience / Extra Artwork / Global Search / PVR / TV Next Aired / TV Tunes / Watchlist / Weather Plus</description>
        <disclaimer>Originally coded by Wir3d/Jezz_X</disclaimer>
    </extension>
</addon>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon
    id="xbmc.repo.hitcher"
    name="Hitcher's repository"
    version="2.0.0"
    provider-name="Hitcher">
    <extension point="xbmc.addon.repository"
        name="Hitcher's Add-on Repository">
        <info>https://bitbucket.org/Hitcher/xbmc.repo.hitcher/raw/57094dbd903a/addons.xml</info>  
        <checksum>https://bitbucket.org/Hitcher/xbmc.repo.hitcher/raw/57094dbd903a/addons.md5</checksum>  
        <datadir zip="true">https://bitbucket.org/Hitcher/xbmc.repo.hitcher/src/585aad574523</datadir>  
    </extension>
    <extension point="xbmc.addon.metadata">
        <summary>Hitcher's Add-ons for XBMC</summary>
        <description>Download and install Add-ons for XBMC.</description>
        <disclaimer>If it breaks, you get to keep the pieces</disclaimer>
        <platform>all</platform>
    </extension>
</addon>
<addon id="plugin.video.iplayer"
       name="iPlayer"
       version="2.4.13"
       provider-name="BuZz, Dink">
    <requires>
        <import addon="xbmc.python" version="1.0"/>
    </requires>
    <extension point="xbmc.python.pluginsource"
               library="default.py">
        <provides>video audio</provides>
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <summary>Watch TV and listen to radio from the BBC's iPlayer website</summary>
        <description>This XBMC plugin enables (UK only) the playing of TV and Radio catchup content from the BBC IPlayer website. Live radio and TV feeds are also supported.</description>
    </extension>
</addon>
<addon
    id="skin.alaska.hd"
    version="0.0.5"
    name="Alaska HD"
    provider-name="Hitcher">
    <requires>
        <import addon="xbmc.gui" version="3.00"/>
        <import addon="script.randomitems" version="1.0.1"/>
    </requires>
    <extension
        point="xbmc.gui.skin"
        defaultthemename="Textures.xbt"
        effectslowdown="1.00"
        debugging="false">
        <res width="1920" height="1080" aspect="16:9" default="true" folder="16x9" />
        <res width="1920" height="1200" aspect="16:10" folder="16x10" />
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <summary>Alaska in full hd</summary>
        <description>Built from from the original Alaska design by Duncan Harris</description>
    </extension>
</addon>
<addon
    id="skin.foundation"
    version="2.0.1"
    name="Foundation"
    provider-name="Hitcher">
    <requires>
        <import addon="xbmc.gui" version="3.00"/>
    </requires>
    <extension
    point="xbmc.gui.skin"
    defaultthemename="textures.xbt"
    debugging="false"
    effectslowdown="0.75">
        <res width="1280" height="720" aspect="16:9" default="true" folder="720p" />
        <res width="1920" height="1080" aspect="16:9" default="true" folder="1080i" />
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <summary>Created by Hitcher / Textures courtesy of Jezz_X</summary>
        <description>'Foundation' is a basic, fully functional XBMC skin designed to be used as a base for creating a new skin; or simply as a learning tool for the beginner.</description>
    </extension>
</addon>
<addon
    id="skin.xeebo"
    version="4.0.0"
    name="XeeBo"
    provider-name="Hitcher">
    <requires>
        <import addon="xbmc.gui" version="3.00"/>
        <import addon="script.playalbum" version="0.0.3"/>
        <import addon="script.watchlist" version="0.0.4"/>
        <import addon="script.favourites" version="3.1.0"/>
        <import addon="script.randomitems" version="3.0.2"/>
        <import addon="script.globalsearch" version="0.1.5"/>
        <import addon="script.artwork.downloader" version="1.0.3"/>
        <import addon="script.tv.show.next.aired" version="3.0.2"/>
    </requires>
    <extension
        point="xbmc.gui.skin"
        defaultthemename="Textures.xbt"
        effectslowdown="1.00"
        debugging="false">
        <res width="1280" height="720" aspect="16:9" default="true" folder="720p" />
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <minversion app="xbmc">28000</minversion>
        <summary>Boxee style skin</summary>
        <description>Designed for ease of use with remote, mouse or touchscreen.[CR][CR]Supports -[CR][CR]Cinema Experience / Extra Artwork / Global Search / PVR / TV Next Aired / TV Tunes / Watchlist / Weather Plus</description>
        <disclaimer>Originally coded by Wir3d/Jezz_X</disclaimer>
    </extension>
</addon>
<addon
    id="xbmc.repo.hitcher"
    name="Hitcher's repository"
    version="2.0.0"
    provider-name="Hitcher">
    <extension point="xbmc.addon.repository"
        name="Hitcher's Add-on Repository">
        <info>https://bitbucket.org/Hitcher/xbmc.repo.hitcher/raw/57094dbd903a/addons.xml</info>  
        <checksum>https://bitbucket.org/Hitcher/xbmc.repo.hitcher/raw/57094dbd903a/addons.md5</checksum>  
        <datadir zip="true">https://bitbucket.org/Hitcher/xbmc.repo.hitcher/src/585aad574523</datadir>  
    </extension>
    <extension point="xbmc.addon.metadata">
        <summary>Hitcher's Add-ons for XBMC</summary>
        <description>Download and install Add-ons for XBMC.</description>
        <disclaimer>If it breaks, you get to keep the pieces</disclaimer>
        <platform>all</platform>
    </extension>
</addon>
</addons>

[Image: sig_zps3af3b48e.jpg]
(This post was last modified: 2012-03-13 22:36 by da-anda.)
find quote
Sinnocence Offline
Member+
Posts: 97
Joined: Oct 2007
Reputation: 4
Post: #9
Strange, it works okay for me. That 'skip=1' basically says skip the first line of each file (first line is 0, second is 1, etc). The way we're using FOR should skip blank lines also.

Can you double check you have skip=1 there and that the addon.xml files where '<?xml version="1.0" encoding="UTF-8"?>' is included have '<?xml version="1.0" encoding="UTF-8"?>' on their first line (or, if not, that they only blank lines before it and nothing of substance) ?

Thanks.
(This post was last modified: 2012-03-13 13:38 by Sinnocence.)
find quote
Hitcher Offline
Skilled Skinner
Posts: 9,976
Joined: Aug 2007
Reputation: 67
Location: Eastleigh, UK
Post: #10
Just had a thought - the addon.xml files are also zipped up in the skin folder - does dos read them as well?

EDIT: I think it must do because I edited the un-zipped addon.xml files and they're the ones that are added to the bottom half of the output file, the ones at the top must be from the zipped folders.

[Image: sig_zps3af3b48e.jpg]
(This post was last modified: 2012-03-13 14:37 by Hitcher.)
find quote
Post Reply