AutoHotkey Community

It is currently May 27th, 2012, 2:02 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: My updated script
PostPosted: January 26th, 2010, 11:38 pm 
Offline

Joined: September 17th, 2005, 6:43 pm
Posts: 242
I hope that someone finds this useful.
This works with most FeedProxy feeds and others.
I re-wrote most of the old script to shrink the size of the ahk and to simplify it.
Code:
#singleinstance, force
gui, add, listbox,vplist gplist sort w300 h500
gui,add,listview,w800 h500 vpcast gpcasts altsubmit x+10,Episode Name|Downloaded|Date|URL
gui,add,edit,vedit w500 x10
gui,add,button,gadd,Add a new podcast
gui,add,button,ggo,Mark selected files for download
gui,add,button,gdownload,Download marked files
gui,add,button,gupdate,Update selected podcast
gui, show
Populate:
total=
guicontrol,,plist,|
loop, casts\*.ini
{
 stringreplace,file,a_loopfilename,.ini
 total=%total%%file%|
}
GuiControl,,plist,%total%
return
plist:
fileread,download,download.ini
gui,listview,pcast
lv_delete()
guicontrol,,pcasts,|
gui,submit,nohide
loop,read,casts\%plist%.ini
{
 if a_loopreadline contains title=
 {
  stringsplit,out,a_loopreadline,=
  iniread,date,casts\%plist%.ini,%out2%,date,error
  iniread,url,casts\%plist%.ini,%out2%,url1,error
  splitpath,url,file
  ifexist %plist%\%file%
  c=Downloaded
  else if download contains %url%
  c=Marked to download
  else
  c=Not Downloaded
  lv_add("",out2,c,date,url)
 }
}
lv_modifycol()
lv_modifycol(3,"SortDesc")
return
pcasts:
if a_guievent = doubleclick
{
 LV_Gettext(file,LV_GetNext(0),4)
 splitpath,file,file
 loop,%file%,1,1
 run %a_loopfilefullpath%
}
return
go:
gui,submit,nohide
loop,
{
 RowNumber := LV_GetNext(RowNumber)
 if not rownumber
 break
 loop,4
 lv_gettext(a%a_index%,rownumber,a_index)
 if a2 = downloaded
 continue
 lv_modify(rownumber,"",a1,"Marked for Download",a3,a4)
 splitpath,a4,file
 iniwrite,%plist%\%a4%,download.ini,url,%a1%
 loop,
 {
  iniread,out,download.ini,download,%a_index%,error
  if out=error
  {
   iniwrite,%a1%,download.ini,download,%a_index%
   break
  }
 }
}
lv_modifycol(2)
return
Add:
operation=newcast
gui, submit, nohide
urldownloadtofile,  %edit%, download.dnl
gosub, strip
iniwrite,%edit%,urlz.ulz,Sites,%file%
gosub, populate
guicontrol,,edit,
return
strip:
fileread, info, download.dnl
stringreplace, info, info, &, %a_space%and%a_space%, all
stringreplace, info, info, <item>, ®, all
needle = Ui)"(http://[^[:space:]]*(m4v|mp4|mp3))"
loop, parse, info, ®
{
 search=%a_loopfield%
 RegExMatch(a_loopfield, "Ui)<description>(.*)</description>" ,description)
 RegExMatch(a_loopfield, "Ui)<pubdate>(.*)</pubdate>" ,pubdate)
 RegExMatch(a_loopfield, "U)<title>(.*)</title>", title)
 RegExMatch(search,needle,url)
 if url1=
 filecreatedir,dnw
 fileappend,%a_loopfield%,dnw\%title1%.txt
 gosub, fix
 if a_index = 1
 {
  file := regexreplace(title1,"i)[^a-z0-9[:space:])(]")
  fileread, compare, casts\%file%.ini
  continue
 }
 title := regexreplace(title1,"i)[^a-z0-9[:space:]]")
 gosub, date
 description := regexreplace(description1,"U)(\t|\n|\r|<.*>|\&..;|\[.*]|\||]\>|)")
 stringleft, description1, description1, 150
 url=
 if islabel(operation)
 gosub, %operation%
}
return

f1::
reload
return


fix:
Loop
{
 regexmatch(url1, "`%(..)",ascii)
 StringReplace, url1, url1, `%%ascii1%, % Chr("0x" . ascii1), All
 if errorlevel <> 0
 break
}
return


date:
d = 1
loop, parse, pubdate, %a_space%
{
 if a_loopfield =
 continue
 p%d% = %a_loopfield%
 d += 1
}
loop, 12
{
 month = %a_index%
 if StrLen(month)=1
 month = 0%month%
 formattime, out, 2008%month%01, MMM
 if out = %p3%
 {
  if a_index < 10
  p3 = 0%a_index%
  else
  p3 = %a_index%
 }
}
if StrLen(p2) =1
p2 = 0%p2%
date = %p4%%p3%%p2%
return
update:
gui,submit,nohide
iniread,out,urlz.ulz,sites,%plist%
urldownloadtofile,%out%,download.dnl
operation=msg
gosub, strip
gosub, plist
return
msg:
iniread,out,casts\%plist%.ini,%title%,date,error
if out = error
{
 gosub, newcast
}
return

newcast:
if url1=
return
info=title,url1,date,description1
loop,parse,info,`,
{
 filecreatedir,casts
 iniwrite,% %a_loopfield%,casts\%file%.ini,%title%,%a_loopfield%
}
return

download:
ifnotexist,download.ini
{
 msgbox select some files to download first
 return
}
loop,
{
 iniread,out,download.ini,download,%a_index%
 if out=error
 break
 title=%out%
 iniread,out,download.ini,url,%out%
 stringsplit,out,out,\
 splitpath,out2,file
 filecreatedir,%out1%
 dir=%out1%
 settimer,flash,100
 urldownloadtofile,%out2%,%out1%\%file%
 settimer,flash,off
 inidelete,download.ini,url,%title%
 lv_modify(rownumber,"",a1,"Downloaded",a3,a4)
}
filedelete,download.ini
return
flash:
if flash=Downloading
flash=
else
flash=Downloading
Loop % LV_GetCount()
{
 LV_GetText(name, A_Index)
 if name = %title%
 {
  rownumber=%a_index%
  loop,4
  lv_gettext(a%a_index%,rownumber,a_index)
  lv_modifycol(2,100)
  lv_modify(rownumber,"",a1,flash,a3,a4)
  sleep,200
  break
 }
}
return
guiclose:
exitapp
return

Input the url of the RSS feed into the edit box and press add feed.
The feed will pop up into the left listbox.
Click on the feed you want to look at in the left box and the files will appear in the right listview.
Select all of the podcasts you would like to download and click on "Mark selected files for download"
Click on "Download marked files" and it will download them.
If a file had Downloaded by it you can double click on it and it will open the file in whatever file viewer you have setup as default.
To remove a podcast for the time being goto your a_scriptdir\casts folder and delete the file that holds the information for whatever podcast you do not wish to subscribe to.
This code was based heavily on maestrith's work ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 29th, 2010, 7:57 pm 
Offline

Joined: February 14th, 2007, 8:01 pm
Posts: 308
Maestrith. I really like your code and version. Since it is more manual than automatic, I will use the code, personally, for those podcasts where I do not want every episode--ones that are just too prolific (bbc news, leo laporte, world cafe, etc.). The current version, doesn't yet work with some podcasts with weird xml. Also, I think based on first run today, it doesn't yet allow downloading podcast from different subscriptions.

I used your code to make a list editor for my version. My version (based on your code, enhancements by joel and me) is more an auto run version, which only keeps lists of stuff downloaded since it cannot prophecy future casts titles, and if server has new stuff, it auto downloads.

I may get around to more fully using your code as a "new subscription adder" gui, in addition to downloaded list editor gui.

So both versions are good for differing tasks: one for automatically and magically getting those mp3/4s on you computer; and one for getting select episodes.

I will compile a version of the latest code and give it some icon and name. I intend to add some ini for output directory settings and program run at end. Plus any code we see needed. That is unless I can see a way of a total merge. Though to merge these, it would be ideal to keep two separate subscription lists and settings! Since, any subscription I don't wish to download every day would be in the latest maestrith routine, while regular subscriptions would be handled by the DJ version. A simple merge would be simply paste your code at end or beginning of the DJ version, make sure all labels are unique and add opening gui for which ever version user wishes to run, with auto version as default on timeout of dialog.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2010, 1:42 am 
Offline

Joined: February 14th, 2007, 8:01 pm
Posts: 308
I had some free time this afternoon, so I merged the two scripts for maximum benefit. Now, I can seamlessly use one program for daily downloading and for selective downloading of overly prolific Podcasters.

I take back part about marking only works for one Author. The main need is adding a button or two in new gui by maestrith, and adding some more compatibility with wacko xml, as done in automatic part of podcaster. Also, I am sure maestrith could clean up my code with more regex that he is great at.

Take a look.

download it at

http://www.autohotkey.net/~degarb/ahkpod

http://www.autohotkey.net/~degarb/ahkpod/ahkpod.exe



Code:

; AHK POD
; This script downloads all new podcast from the podcast-adresses stored in the
; %a_workingdir%\podcast-subscriptions.txt file
; The podcast.txt file should contain lines such as
; http://downloads.bbc.co.uk/podcasts/worldservice/globalnews/rss.xml
;

; The script stores the podcasts in the pdir-folder for example
; G:\Podcasts\00Global_News\20090317@1751.mp3 and uses id3.exe
; (http://home.wanadoo.nl/squell/files/id3-078w.zip) to tag the podcast as album
; "00Global_News" and title "20090317@1751" which is the publish-date and time.
; I put an 00 before the album name because I want all my podcasts to be at the
; top of my albumlist. After downloading and tagging  the scripts ask you if you
; want to delete old podcasts as defined by the variable timedelete. If you want
;? to download a specific podcast simply remove the line of your wanted podcast
;? in the DownloadedCasts\yoursubriction.txt -file
;
; If it is the first time you run the script it will create an settings.txt file
; with default values and an podcast.txt file with the above mentioned podcast.
; If you want to change the directory to where to download the podcasts, edit the
; downloadpodcast_to variable and if you want to update the list of podcasts but dont
; download them change the downloadnewpod variable to no. The variable timedelete
; in the settings.txt defines the days from current date to suggest delete of old mp3s.
;
; this script is based on maestrith script:
; http://www.autohotkey.com/forum/topic33847.html&highlight=itunes with an added
; functions. To have this script pop up as as run-option when you plugin your
; mp3/usb-device, compile the script to an exe-fil put the script in the
; root folder of your usb-device and edit or create an text-file called AUTORUN.INF
; in the root folder and put the following lines in that file
; [autorun]
; OPEN=AHK_pod.exe
; ACTION=Run AHK_pod.exe
;
; Hope you find the script usefull

;Added manual downloader, written by maestrith
;Added list editor, for easier marking for download of podcasts after newly adding podcast.
;added: Much time writing around whacko xml like how stuff works and naked scientist and npr freshair
;added auto timeout gui for catchup/dryrun, manual downloader or regular run. 

; todos: Fix manual list editor so updates right pane in real time.  To do this, need to rename /downloaded casts/podname-urlsplit.txt  this way url can be matched to files that need editing.
; 2do: need skip current file  (post is there a way to goto and kill url downloadtofile routine

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

#singleinstance, force
settitlematchmode,2

;the variable usbl is the devicelabel, eg the script can be run from a usb-device and works independet of lettername
usbl := SubStr(A_ScriptFullPath, 1, 1)

; script begins...
; checking settings.txt-file

installs:
ifnotexist, html
   filecreatedir, html
fileinstall, index.html, index.html
fileinstall, html\OtherClients.html,html\OtherClients.html
fileinstall, html\Taking your podcasts to another level.html,Taking your podcasts to another level.html   
fileinstall, html\What is a Podcast and Why Bother.html, html\What is a Podcast and Why Bother.html
fileinstall, html\Find Podcasts.html, html\Find Podcasts.html
fileinstall, example-podcasts-subscriptions.txt,example-podcasts-subscriptions.txt
fileinstall, podcasts-subscriptions.txt,podcasts-subscriptions.txt

fileinstall, html\ahkpod.ico,html\ahkpod.ico
FileInstall, COPYING.txt,COPYING.txt
FileInstall,TOS.html,TOS.html
fileinstall, html\winlogo.gif,html\winlogo.gif
fileinstall, html\HowToUse.html,html\HowToUse.html
fileinstall, ahkpod.ahk,ahkpod.ahk

ifNotExist settings.txt
{

 IniWrite, yes, settings.txt, settings, downloadnewpod
 IniWrite, podcasts, settings.txt, settings, downloadpodcast_to
 IniWrite, 5, settings.txt, settings, timedelete
;deg
 IniWrite, No, settings.txt, settings, DryRun
 IniWrite, RunOnExit, settings.txt, settings, RunOnExit
 IniWrite, %a_space%, settings.txt, settings, RunOnExitWorkingDir
 IniWrite, low, settings.txt, settings, priority
}
IniRead, downloadnewpod ,settings.txt, settings, downloadnewpod
IniRead, downloadpodcast_to ,settings.txt, settings,downloadpodcast_to
IniRead, timedelete ,settings.txt, settings,timedelete
IniRead, DryRun ,settings.txt, settings,DryRun ;deg
IniRead, RunOnExit ,settings.txt, settings,RunOnExit ;deg
IniRead, RunOnExitWorkingDir,settings.txt, settings,RunOnExitWorkingDir
IniRead, priority,settings.txt, settings,priority
filedelete, %a_workingdir%\downloadedthistime.txt
pdir = %usbl%:\%downloadpodcast_to%
FileCreateShortcut, %pdir%,DownloadedCasts\All-MyPodcasts-Directory Shortcut.lnk,%pdir%,MyPodcast Location

inivalidation:  ;deg

ifnotexist, %a_workingdir%\xml
filecreatedir, %a_workingdir%\xml
if DryRun=Error
{
 IniWrite, No, settings.txt, settings, DryRun
 DryRun=Yes
}
if RunOnExit=Error
{
 IniWrite, RunOnExit, settings.txt, settings, RunOnExit
RunOnExit=0
}
if RunOnExitWorkingDir=Error
{
 IniWrite, %a_space%, settings.txt, settings, RunOnExitWorkingDir
}
if priority=Error
{
 IniWrite, low, settings.txt, settings, priority
priority=low
}
process, priority, ahkpod.exe,%priority%

endinivalidation:

trays: ;deg
;Menu, tray, icon, mov.ico, ,
Menu, Tray, Tip, AHKPod!
menu, tray, Nostandard
menu, tray, add,Find Podcasts, getpodcasts
menu, tray, add,Edit Auto Subsciptions,EditSubsciptions
menu, tray, add,Edit Lists of Successful Downloads, listeditor
menu, tray, add, Open Current Xml, openxml
Menu, tray, add
Menu, tray, add, Schedule Run, Schedule
Menu, tray, add, Links of Helper Programs, Helpers
Menu, tray, add, Support, support
;menu, tray, add,AbortDownload , AbortDownload ;not possible
menu, tray, add,Exit , exitmanual
;Menu, Tray, Tip, AHK pod!
ifNotExist DownloadedCasts
{
filecreatedir DownloadedCasts
}

ifNotExist podcasts-subscriptions.txt
{
 fileappend, ; %a_tab% BBC World News`n, podcasts-subscriptions.txt 
 fileappend, http://downloads.bbc.co.uk/podcasts/worldservice/globalnews/rss.xml, podcasts-subscriptions.txt
}
ifNotExist ignoreduds.txt
 fileappend, Add any word on any line. If the word is found in url of an mp3`, then that mp3`, or ones like it`, cannot be tagged as a dud`, no matter the httpquery file size. Email author for diagnosis or bug fix.`n,ignoreduds.txt


fileappend, <FDM_Downloads_Info_List>`n, download.xml
setupdone:

IntroDialogs:
menu, tray, enable, Edit Lists of Successful Downloads
gosub, introgui1
sleep, 3000

winwaitclose, List Editor of Downloaded Stuff
winwaitclose, AHKPod: Intro Dialog
winwaitclose, ManualDownloader

/*
msgbox, , Edit podcast subscripton list?, Click 'yes' to continue normally.  Click 'no' to edit podcast subscripton list,20 ;deg

ifmsgbox No
   run, notepad.exe "%a_workingdir%\podcasts-subscriptions.txt"
else   
   continue=0
msgbox, 4, Normal or Dry Run, Click yes to run now normally?`n`nElse`,Click "No" to do a Dry Run. Great for first runs and after adding a podcast. This will build the downloaded list up to all possible casts.  Just click desired casts with DownloadedCasts Editor`, to download the ones you want.,560 ;deg
*/

winwaitclose, List Editor of Downloaded Stuff
winwaitclose, AHKPod: Intro Dialog
ifmsgbox No
{
   
   DryRun=yes
   msgbox,0 , Dry Run to buildup list of possible podcasts.,This will take a while`,depending on number of subscriptions and number of files in list.  Let program finish and start again.  Be sure after dry run`, to edit the downloaded cast to download the ones you really want.,20
}
else
conti=0

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
starting:

backups:
filecopy, podcasts-subscriptions3.txt,podcasts-subscriptions4.txt,1   ;deg
filecopy, podcasts-subscriptions2.txt,podcasts-subscriptions3.txt,1   ;deg
filecopy, podcasts-subscriptions1.txt,podcasts-subscriptions2.txt,1   ;deg
filecopy, podcasts-subscriptions.txt,podcasts-subscriptions1.txt,1   ;deg

filecopydir, %a_workingdir%\DownloadedCasts3,%a_workingdir%\DownloadedCasts4,1   ;deg
filecopydir, %a_workingdir%\DownloadedCasts2,%a_workingdir%\DownloadedCasts3,1   ;deg
filecopydir, %a_workingdir%\DownloadedCasts1,%a_workingdir%\DownloadedCasts2,1   ;deg
filecopydir, %a_workingdir%\DownloadedCasts,%a_workingdir%\DownloadedCasts1,1   ;deg



menu, tray, disable, Edit Lists of Successful Downloads
fileread, duds,%a_workingdir%\duddownloads.txt
filemove,%a_workingdir%\duddownloads.txt,%a_workingdir%\duddownloads-lastrun.txt,1

   ; checking podcasts-subscriptions.txt, compares new podcast and download new

ReadingSubscriptions:
Loop, read, podcasts-subscriptions.txt
{
    Loop, parse, A_LoopReadLine, `n
    {
tempdryrun=0
ifinstring, A_LoopField,;     ; lets skip semicolons and nearly blank lines
   continue
stringmid, one, A_LoopField,1,1
if one=:
{
   tempdryrun=1
   stringreplace, LoopField, A_LoopField,:http,http
}
stringlen, alflen,A_LoopField
if alflen<10
   continue
if tempdryrun=0
   urldownloadtofile, %A_LoopField%, download.dnl
if tempdryrun=1
   urldownloadtofile, %LoopField%, download.dnl
currentrss:=A_LoopField
Menu, Tray, Tip, AHKPod! %A_LoopField%
gosub, freshair2

;if freshair=1
;   continue
freshair=0

   operation = update1
   gosub, strip
filecopy, %a_workingdir%\download.dnl, %a_workingdir%\xml\%file%.xml,1

    }
}


fileappend, </FDM_Downloads_Info_List>, download.xml
fileread, download, download.xml
if download not contains <url>
{
 msgbox,0,, Nothing to download ,12
 ;gosub exit
}

dating:
; asks for delete old mp3
stringleft, A_Now2, A_Now, 8
stringleft, yy, A_Now2,4
stringright, dd, A_Now2,2
stringmid, mm,A_Now2, 5,2
ym:=(mm-1)/12  ; ym is conversion of month to percent of year. actually ym:=(mm-1)/12  but irrelevant since both filedate and now are adding a month, and so cancel eachother out
yd:=dd/365
py:=ym+yd
Stringmid,py,py,3,26
A_Now2=%yy%.%py%

;  actually    yy mm dd   needs to be translated into percent of year     so yy.(ym+yd)    ym=mm/12  and yd=dd/30(*1/12)  and no of days=nod/365
timedelete:=timedelete/365


{
 Loop, %pdir%\*.mp3 , ,1
 {
FileGetTime, filenamedate, %A_LoopFileFullPath%, M
;msgbox, date is %filenamedate% on file %A_LoopFileName%
  stringleft, filenamedate, filenamedate,8
;msgbox, %filenamedate%

stringleft, yy, filenamedate,4
stringright, dd, filenamedate,2
stringmid, mm,filenamedate, 5,2
ym:=(mm-1)/12
yd:=dd/365
py:=ym+yd
Stringmid,py,py,3,26
filenamedate=%yy%.%py%
date4del:=filenamedate+timedelete
due:=A_Now2 - date4del
;msgbox, filedate is %filenamedate% %yy% %mm% %dd%. days2del is %timedelete% ... now is %A_Now2%.. - dateof del is  %date4del%  and due is %due%
  If ( due > 0)
   {
;msgbox, overdue
    fileappend, `n%A_LoopFileFullPath%, oldmp3.txt
   }   
 }
}

gosub exit
return

strip:
fileread, info, download.dnl ;;read to get mp3url
stringreplace, info, info, &amp;, %a_space%and%a_space%, all
stringreplace, info, info, <item>, |, all
;needle = Ui)"<link>.*(mp3)  ;deg
needle = Ui)"(http://[^[:space:]]*(m4v|mp4|mp3))"

freshair=0

loop, parse, info, |
{

 RegExMatch(a_loopfield, "Ui)<description>(.*)</description>" ,description)
 RegExMatch(a_loopfield, "Ui)<pubdate>(.*)</pubdate>" ,pubdate)

;RegExMatch(a_loopfield, "U)<title>(.*)</title>)<title%a_space%>(.*)</title>", title)
RegExMatch(a_loopfield, "U)<title(.*)</title>", title)

 RegExMatch(a_loopfield, needle, url)
 RegExMatch(a_loopfield, "Ui)<link>(.*)</link>|<link >(.*)</link>" , urla) ;deg
;RegExMatch(a_loopfield, "Ui)<link>(.*)</link>" , urla) ;deg
 RegExMatch(a_loopfield, "<title>(.*)</title>" , titlea) ;deg
;* msgbox,url
 gosub, fix
 if a_index = 1
 {
  file2 := regexreplace(title1,"i)[^a-z0-9[:space:])(]")
  file := regexreplace(file2," ", "_")
  fileread, compare, DownloadedCasts\%file%.txt
  continue
 }
 title1 := regexreplace(title1,"i)[^a-z0-9[:space:]]")
 gosub, date
 description1 := regexreplace(description1,"U)(\t|\n|\r|<.*>|\&..;|\[.*]|\||]\>|)")
 stringleft, description1, description1, 150
 url=
urla=
titlea=;deg
 gosub, %operation%
}
return


fix:
Loop
{
 regexmatch(url1, "`%(..)",ascii)
 StringReplace, url1, url1, `%%ascii1%, % Chr("0x" . ascii1), All

 regexmatch(urla1, "`%(..)",ascii) ;deg

 StringReplace, urla1, urla1, `%%ascii1%, % Chr("0x" . ascii1), All  ;deg
 if errorlevel <> 0
 break
}
return


update1:
comparing4append:

fileread, compare, DownloadedCasts\%file%.txt


RegExMatch(compare, url1 ,found)
if found <>
   goto, forgetit
RegExMatch(compare, urla1 ,found)
if found <>
   goto, forgetit

RegExMatch(compare, title1 ,found)
if found =
{
 fileappend, %date%®%title1%®%url1%®%description1%`n, DownloadedCasts\%file%.txt
 fileappend, <download>`n<url>%url1%</url>`n<group>Video\%name%</group>`n</download>`n,    download.xml
 saveDir = %usbl%:\Podcasts\00%file%
 fileName = %date%.mp3
 ifNotExist %savedir%
 filecreatedir %savedir%

 sleep 50
 if downloadnewpod contains yes
  {
   gosub downloadpodcast
  }


 sleep 100
ifexist, %a_workingdir%\id3.exe ;deg
run id3.exe -2 -t "%date%" -l "00%file%" %title1%-%date%-%savedir2%.mp3,,hide
;run id3 -2 -t "%date%" -l "00%file%" %savedir%\%date%.mp3,,hide

}
forgetit:
forget=1
return
freshair=0

;/////////////////////////////////end regular
endregular:


date:
d = 1
loop, parse, pubdate, %a_space%
{
 if a_loopfield =
 continue
 p%d% = %a_loopfield%
 d += 1
}
loop, 12
{
 month = %a_index%
 if StrLen(month)=1
 month = 0%month%
 formattime, out, 2008%month%01, MMM
 if out = %p3%
 {
  if a_index < 10
  p3 = 0%a_index%
  else
  p3 = %a_index%
 }
 p5gammal := regexreplace(p5,":", "")
 stringleft, p5new, p5gammal,4
}
if StrLen(p2) =1
p2 = 0%p2%
date = %p4%%p3%%p2%@%p5new%
return

exit:

autoexit=0
exitmanual:
gui,destroy
menu, tray, enable, Edit Lists of Successful Downloads
;msgbox,percent is %percent%
IniWrite, No, settings.txt, settings, DryRun
fileread, oldmp3, oldmp3.txt
MsgBox=no

if oldmp3 contains mp3
{
   msgbox, 4,, Do you want to delete the following mp3-files? %oldmp3%,12
IfMsgBox, Yes
{
   msgbox, 0,Delete the old., You choose Yes!,You choose Yes! Deleting.
   Loop, read, oldmp3.txt
   {
   Filedelete, %A_LoopReadLine%
   }
}
}

filedelete download.xml
filedelete download.dnl
filedelete oldmp3.txt
fileread, dtt,downloadedthistime.txt   ;deg
msgbox,0, Done these, I downloaded: `n%dtt%,25   ;deg
;loop, DownloadedCasts\*.txt
;   run, notepad.exe "%A_LoopFileName%"
ifexist, %a_workingdir%\duddownloads.txt
{
   run, notepad.exe "%a_workingdir%\duddownloads.txt"
}
if DryRun=yes
{
msgbox,0, Instuctions, To download desired podcasts. Delete line in list of downloaded mp3s`, found in DownloadedCasts directory.,25
gosub, listeditor

}

pau:
sleep,5000
DetectHiddenWindows,off
winwaitclose, List Editor of Downloaded Stuff
winwaitclose,ManualDownloader
winwaitclose, Importing! Please stand by.
   
nowin:

;msgbox,0,,Click ok to exit program.,1200
if autoexit<>0
{
   fileread, list, DownloadedCasts\%file%.txt
   filedelete, %a_workingdir%\DownloadedCasts\%file%.txt
   stringreplace, list, list, %date%®%title1%®%url1%®%description1%,%a_space%,1
   fileappend, %list%, DownloadedCasts\%file%.txt
;   msgbox, autoexiting
}

ifnotequal,RunOnExit,0 ;deg
{
   ifexist, %RunOnExit%
   run, %RunOnExit%,%RunOnExitWorkingDir%   ;deg
}
exitapp
return

downloadpodcast:
savedir2:=savedir ;deg
 savedir2 := regexreplace(savedir2,"i)[^a-z0-9[:space:]]") ;deg
stringreplace,savedir2,savedir2,JPodcasts00, ;deg
;filenamedeg = %savedir2%-%fileName%-%date%.mp3 ;deg
;filenamedeg = %savedir2%-%title1%-%fileName% ;deg
;;stringmid,savedir3,savedir2,1,16
;;filenamedeg = %savedir3%-%title1%-%fileName% ;deg

filenamedeg = %title1%-%date%-%savedir2%.mp3 ;deg

if tempdryrun=1
 goto, skipdown
if DryRun=no
Progress, X0 Y63 h75 w430 A M T min,, ,%saveDir%\%filenamedeg% , bold ;deg %filename
winminimize,\00
         SetTimer, uProgress, 150
         totalFileSize := HttpQueryInfo(url1, 5)
 totalFileSizea=0
   ifnotinstring, url1, http
         totalFileSizea := HttpQueryInfo(urla1, 5) ;deg

winminimize,\00
;&
   fileName=title1

ifnotequal, DryRun, yes ;deg
        {
;   msgbox, %filenamedeg%
    UrlDownloadToFile, %url1%, %saveDir%\%filenamedeg%
ifnotinstring, url1, http
    UrlDownloadToFile, %urla1%, %saveDir%\%filenamedeg% ;deg
   }

AbortDownload:

ad:

;below;historyzine will not return httpquery,

sleep,100  ;npr freshair xml lists links to stories not mp3s (which are javascript embedded in story.)
FileGetSize, fs, %saveDir%\%filenamedeg% ,K
if fs<90
   filedelete,%saveDir%\%filenamedeg%

if fs>.3 ; test for got some file but no file size
    {
   if totalFileSizeall=
{
   goto, skipdeadisptest

}
      }

deadisptest:
if percent<.7
   a=0
if a<.01
{
   skipdud=0

if DryRun=Yes
   goto, endduds
duds:
Loop, read,%a_workingdir%\ignoreduds.txt
   {
      ifinstring,url1,%A_LoopReadLine%
      skipdud=1
;msgbox, skipdud %skipdud% .  url1 is %url1%  and A_LoopReadLine %A_LoopReadLine%
   }
;msgbox,Dud!!`n`npercent is %percent% a=%a%  b=%b% percent is %percent%..tfsa %totalFileSizeall%of %saveDir%\%filenamedeg%`,   and filesize is %fs%`nand url1 is %url1%

if skipdud=0
{
fileappend, %date%®%title1%®%url1%®%description1%%a_tab%%a_tab%percent is %percent% a=%a%  b=%b% percent is %percent%..tfsa %totalFileSizeall%`,   and filesize is %fs%`n,    duddownloads.txt 
delthedud:
   fileread, list, DownloadedCasts\%file%.txt
   filemove, %a_workingdir%\DownloadedCasts\%file%.txt,%a_workingdir%\DownloadedCasts\%file%.old,1
   stringreplace, list, list, %date%®%title1%®%url1%®%description1%,%a_space%,1
   fileappend, %list%, DownloadedCasts\%file%.txt
}
endduds:
yy=9
}
skipdeadisptest:
bb=9
skipdown:
fileappend, %saveDir%\%filenamedeg%`n, downloadedthistime.txt ;deg
         SetTimer, uProgress, off
         Progress, Off
         filegetSize,sizefil,%saveDir%\%fileName%
         if(sizefil = 1638)
         goto,nofile
       ;  msgbox,Download finished
return       

nofile:          ; When the file is not found, it creates a file of 1638 bytes
{
ifnotequal, DryRun, yes ;deg
   filedelete,%saveDir%\%fileName%
msgbox,File not found on the site.
}
return

uProgress:
   FileGetSize, fs, %saveDir%\%fileNamedeg% ,K
totalFileSizeall :=totalFileSize+totalFileSizea ;deg

   a := Floor(fs/totalFileSizeall * 100*1024) ;deg
   b := Floor(fs/totalFileSizeall * 10000*1024)/100 ;deg
   c := Floor(fs/totalFileSizea * 100*1024)  ;deg
   d := Floor(fs/totalFileSizea * 10000*1024)/100 ;deg
   SetFormat, float, 0.2
   b += 0
   d += 0   ;deg
TFileSize := totalFileSize / 1024
Tfs=%TFileSize%
TFileSizea := totalFileSizea / 1024  ;deg
Tfsa=%TFileSizea%  ;deg
e := a + c
f := b + d
Tfsall := tfs + Tfsa
percent := fs/Tfsall
if DryRun=no
Progress,%a%,%b%`%        downloaded: %fs% Kb.    of      %Tfsall% Kb.  ;deg
return

HttpQueryInfo(URL, QueryInfoFlag=21, Proxy="", ProxyBypass="") {
hModule := DllCall("LoadLibrary", "str", "wininet.dll")
If (Proxy != "")
AccessType=3
Else
AccessType=1
io_hInternet := DllCall("wininet\InternetOpenA"
, "str", "" ;lpszAgent
, "uint", AccessType
, "str", Proxy
, "str", ProxyBypass
, "uint", 0) ;dwFlags
If (ErrorLevel != 0 or io_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}
iou_hInternet := DllCall("wininet\InternetOpenUrlA"
, "uint", io_hInternet
, "str", url
, "str", "" ;lpszHeaders
, "uint", 0 ;dwHeadersLength
, "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
, "uint", 0) ;dwContext
If (ErrorLevel != 0 or iou_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}
VarSetCapacity(buffer, 1024, 0)
VarSetCapacity(buffer_len, 4, 0)
Loop, 5
{
  hqi := DllCall("wininet\HttpQueryInfoA"
  , "uint", iou_hInternet
  , "uint", QueryInfoFlag ;dwInfoLevel
  , "uint", &buffer
  , "uint", &buffer_len
  , "uint", 0) ;lpdwIndex
  If (hqi = 1) {
    hqi=success
    break
  }
}
IfNotEqual, hqi, success, SetEnv, res, timeout
If (hqi = "success") {
p := &buffer
Loop
{
  l := DllCall("lstrlen", "UInt", p)
  VarSetCapacity(tmp_var, l+1, 0)
  DllCall("lstrcpy", "Str", tmp_var, "UInt", p)
  p += l + 1
  res := res  . "`n" . tmp_var
  If (*p = 0)
  Break
}
StringTrimLeft, res, res, 1
}
DllCall("wininet\InternetCloseHandle",  "uint", iou_hInternet)
DllCall("wininet\InternetCloseHandle",  "uint", io_hInternet)
DllCall("FreeLibrary", "uint", hModule)
return, res
}
return
;;;;;;;;;;;;;;;;;;;;;;;
EditSubsciptions:
   run, notepad.exe "%a_workingdir%\podcasts-subscriptions.txt"
return

EditLists:
run, %a_workingdir%\DownloadedCasts
return

getpodcasts:
run, http://www.podcastalley.com/redirect.php?pod_id=14978
run, http://www.podbean.com/
run, http://www.google.com/search?hl=en&rlz=1C1GGLS_enUS329US329&q=audio+podcast+subscribe+&aq=f&oq=&aqi=
run, http://www.findpodcasts.com/popular.html
run, http://www.npr.org/rss/podcast/podcast_directory.php?type=title&value=all
run, http://podcastpickle.com/
run, %a_workingdir%\html\Find Podcasts.htm


return

helpers:
run, http://akronedge.info/wintersoft/mp3squisher/index.html
run, http://bitsum.com
run, http://autohotkey.com
return

support:
run, mailto:degarb@gmail.com
run, http://www.autohotkey.com/forum/viewtopic.php?p=324767#324767
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
openxml:
ifinstring, currentrss,http
run, %currentrss%
return
;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


freshair2:
freshair:
fileread,downloadfa,%a_workingdir%\download.dnl


if downloadfa contains mp4,mp3,aac,mpg
   {
   goto, skipfreshair
   }

freshair=1

stringreplace,podtitfa,downloadfa,title>,¬ ,all
;msgbox, %podtitfa%

loop,parse,podtitfa,¬
{

if a_index=2
   {
title=%a_loopfield%
stringreplace,title,title,<title>,
stringreplace,title,title,</title>,
stringreplace,title,title,/,
stringreplace,title,title,^,
stringreplace,title,title,$,
stringreplace,title,title,`,,
stringreplace,title,title,:,
stringreplace,title,title,/,
stringreplace,title,title,',
stringreplace,title,title,",
stringreplace,title,title,!,
stringreplace,title,title,),
stringreplace,title,title,(,
stringreplace,title,title,;,
stringreplace,title,title,\,
stringreplace,title,title,<,
stringreplace,title,title,>,

titl=%title%
file=%title%

   }
}   ;got freshair name

stringreplace,outfa,downloadfa,<item>,¬ ,all

loop,parse,outfa,¬
{
RegExMatch(a_loopfield, "U)<title(.*)</title>", title)

ifinstring, title, title
{
stringreplace,title,title,<title>,
stringreplace,title,title,</title>,
stringreplace,title,title,/,
stringreplace,title,title,`,,
stringreplace,title,title,:,
stringreplace,title,title,/,
stringreplace,title,title,',
stringreplace,title,title,",
stringreplace,title,title,!,
stringreplace,title,title,),
stringreplace,title,title,(,
stringreplace,title,title,;,
stringreplace,title,title,\,
;msgbox, my %title%  >%pubdate%> %description%
titl=%title%
}
 RegExMatch(a_loopfield, "Ui)<link>(.*)</link>" ,linkfa)
 listfa=%listfa%%linkfa1%`n
}

loop,parse,listfa,`n
{       ;parselist
if a_index=1
continue

if a_loopfield contains mp4,mp3,aac,mpg
{
;msgbox, trap2: OOps contains mp3
break
}
;msgbox, %a_loopfield% downloadingline 28
 urldownloadtofile,%a_loopfield%,downloadfa.dnl ;;;;;;;;;;;;;;;;;;;;;;;;get sub xml
 fileread,downloadfa,downloadfa.dnl
 stringreplace,downloadfa,downloadfa,href=,¿,all
 loop,parse,downloadfa,¿    ; final parse
 {
RegExMatch(a_loopfield, "Ui)<description>(.*)</description>" ,description)
stringreplace,description,description,<description>,
stringreplace,description,description,</description>,

RegExMatch(a_loopfield, "Ui)<pubdate>(.*)</pubdate>" ,pubdate)
stringreplace,pubdate,pubdate,<pubdate>,
stringreplace,pubdate,pubdate,</pubdate>,

;RegExMatch(a_loopfield, "U)<title>(.*)</title>)<title%a_space%>(.*)</title>", title)
RegExMatch(a_loopfield, "U)<title(.*)</title>", title)

ifinstring, title, title
{
stringreplace,title,title,<title>,
stringreplace,title,title,</title>,
stringreplace,title,title,/,
stringreplace,title,title,`,,
stringreplace,title,title,:,
stringreplace,title,title,/,
stringreplace,title,title,',
stringreplace,title,title,",
stringreplace,title,title,!,
stringreplace,title,title,),
stringreplace,title,title,(,
stringreplace,title,title,;,
stringreplace,title,title,\,
titl=%title%
}
;>>>>>>>>>>>>


  if a_loopfield contains mp3
  {
  RegExMatch(a_loopfield,"Ui).(.*)\.mp3",linkfa)
url1=%linkfa%
comparing:
fileread, compare, DownloadedCasts\%file%.txt
RegExMatch(compare, linkfa ,found)
if found =
{
;msgbox, sha not ther
 fileappend, %date%®%titl%®%url1%®%description%`n, DownloadedCasts\%file%.txt
; fileappend, <download>`n<url>%url1%</url>`n<group>Video\%name%</group>`n</download>`n,    download.xml
 saveDir = %usbl%:\Podcasts\00%file%
 ifNotExist %savedir%
 filecreatedir %savedir%
;msgbox, notdone:mp3 matched %linkfa1%`n: %title%`n%titl%`n%file%

 if dryrun<>yes
  {
;msgbox, mp3 matched %linkfa1%`n: %title%`n%titl%`n%file%
filenamedeg=%titl%.mp3
Progress, X0 Y63 h75 w430 A M T min,, ,%saveDir%\%filenamedeg% , bold ;deg %filename
winminimize,\00
         SetTimer, uProgress, 150
         totalFileSize := HttpQueryInfo(url1, 5)
 totalFileSizea=0
   ifnotinstring, url1, http
         totalFileSizea := HttpQueryInfo(urla1, 5) ;deg

winminimize,\00

titl:=substr(titl,1,28)
StringReplace, titl, titl, `%%ascii1%, % Chr("0x" . ascii1)
StringReplace, titl, titl, :,
stringreplace,titl,titl,/,
stringreplace,titl,titl,^,
stringreplace,titl,titl,$,
stringreplace,titl,titl,`,,
stringreplace,titl,titl,:,
stringreplace,titl,titl,/,
stringreplace,titl,titl,',
stringreplace,titl,titl,",
stringreplace,titl,titl,!,
stringreplace,titl,titl,),
stringreplace,titl,titl,(,
stringreplace,titl,titl,;,
stringreplace,titl,titl,\,
stringreplace,titl,titl,<,
stringreplace,titl,titl,>,

;fileappend,UrlDownloadToFile`, %linkfa1%.mp3`, %saveDir%\%titl%.mp3, problemurl.ahk

;
;clipboard=  UrlDownloadToFile`, %linkfa1%.mp3`, %saveDir%\%titl%.mp3
;msgbox, %saveDir%-fa
ifnotexist, %saveDir%-fa
   filecreatedir, %saveDir%-fa

UrlDownloadToFile, %linkfa1%.mp3, %saveDir%-fa\%titl%.mp3
sleep, 100
if fs<90
   filedelete,%saveDir%\%filenamedeg%
fileappend, %saveDir%\%filenamedeg%`n, downloadedthistime.txt ;deg


;gosub, freshairfilesizecheck
} ;end dryrun...
} ;end found
skiper:
;msgbox, skipper :%found%
  kjldf=1 ;
 } ;endloop,parse,downloadfa
} ;?
} ;end parselist
;goto regular or continue


skipfreshair:
return

;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;
;;;;;;;;;;;;;;

freshairfilesizecheck:
FileGetSize, fs, %saveDir%\%filenamedeg% ,K
if fs<90
   filedelete,%saveDir%\%filenamedeg%

if fs>.3 ; test for got some file but no file size
    {
   if totalFileSizeall=
{
   goto, skipdeadisptestfa

}
   }

;deadisptest
if percent<.7
   a=0
if a<.01
   skipdud=0
if DryRun=Yes
   goto, enddudsfa

if skipdud=0
{
fileappend, %date%®%title1%®%url1%®%description1%%a_tab%%a_tab%percent is %percent% a=%a%  b=%b% percent is %percent%..tfsa %totalFileSizeall%`,   and filesize is %fs%`n,    duddownloads.txt 
delthedudfa:
   fileread, list, DownloadedCasts\%file%.txt
   filemove, %a_workingdir%\DownloadedCasts\%file%.txt,%a_workingdir%\DownloadedCasts\%file%.old,1
   stringreplace, list, list, %date%®%title1%®%url1%®%description1%,%a_space%,1
   fileappend, %list%, DownloadedCasts\%file%.txt
}
enddudsfa:
yy=9

skipdeadisptestfa:
bb=9

fileappend, %saveDir%\%filenamedeg%`n, downloadedthistime.txt ;deg

return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


listeditor:

#singleinstance, force
settitlematchmode,2
Gui, Font, Bold
Gui, Font, s14
Gui, Font, underline
gui, add, text,h20 x40  S52 ,List Editor for Downloaded Podcasts:
Gui, Font, s7
 gui,add,button,x650 y10 gplist h7,Refresh Episode Listings

Gui, Font, normal
gui, add, listbox,vplist gplist sort w250 h300 x10
gui,add,listview,w550 h300 vpcast gpcasts altsubmit x+10,Episode

Gui, Font, Bold
Gui, Font, underline
gui, add, text,h30 x10  , Click on Left to select a subscription.%a_space%%a_space%%a_space%%a_space%%a_space%%a_tab%%a_tab%%a_space%%a_space%%a_space%& Double-Click on right box to delete items in your "Downloaded List", in order to download the item!
Gui, Font, s6
Gui, Font,
;gui, add, text,,
gui,add,edit,veditle w500 x10
gui,add,button,gadd,Add a new podcast or Edit subscription list ;need
Gui, Font, normal
;gui,add,button,gpopulate h7,Refresh Subscription List
gui,add,button,gstartdry h7,Start Another Dry Run
gui,add,button,gopenlists h7,Open Downloaded list directory
Gui, Font, Bold
Gui, Font, underline
gui,add,button,gstartdown w800,Start Downloading


gui, show,, List Editor of Downloaded Stuff

Populateautolisteditor:
GuiControl,, MainEdit
total=
guicontrol,,plist,|
Loop, DownloadedCasts\*.txt,,
{
  stringreplace,file,a_loopfilename,.ini
 total=%total%%file%|
}
GuiControl,,plist,%total%
return

plist:      ;Left menu
gui,listview,pcast
lv_delete()
guicontrol,,pcasts,|
gui,submit,nohide

guicontrol,,pcast,|
   

;msgbox,%plist% : %Rowtext%
Loop, Read, %a_workingdir%\DownloadedCasts\%plist%
{
 LV_Add("", A_LoopReadLine)
}
GuiControl,,pcast,%total%
return


pcasts:         ; right menu
if a_guievent = Doubleclick
{
   LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
Tooltip,  Will download next run!  Deleting "listed as downloaded": "%RowText%"
SetTimer, RemoveToolTip, 600

;LV_Delete()
fileread, chopthis,%a_workingdir%\DownloadedCasts\%plist%
stringreplace,chopthis,chopthis,%RowText%,
stringreplace,chopthis,chopthis,`r`n`r`n`r`n,`r`n,1
stringreplace,chopthis,chopthis,`r`n`r`n,`r`n,1
chopthis := RegExReplace(chopthis,"\R+", "`r`n")
;Loop
;{
;    StringReplace, chopthis, chopthis, `r`n`r`n, `r`n, UseErrorLevel
;    if ErrorLevel = 0  ; No more replacements needed.
;        break
;}
;msgbox, %chopthis%
filemove, %a_workingdir%\DownloadedCasts\%plist%,%a_workingdir%\DownloadedCasts\%plist%.old,1
fileappend,%chopthis%,%a_workingdir%\DownloadedCasts\%plist%
}
;Loop, Read, %a_workingdir%\DownloadedCasts\%plist%
;
;{
; LV_Add("", A_LoopReadLine)
;}
;GuiControl,,pcast,%total%

return

Add:
operation=newcast
gui, submit, nohide
fileappend, `n%editle%,%a_workingdir%\podcasts-subscriptions.txt
ifwinnotexist, podcast-subscriptions
   run, notepad.exe %a_workingdir%\podcasts-subscriptions.txt
sleep, 6000
   msgbox,0,Adding  subscriptions, Adding subscriptions will not show up in left panel until after a dry run.,12
WinMaximize, Adding subscriptions
return
return

startdry:
gui,destroy
dryrun=yes
goto, starting
return

startdown:
gui,destroy
dryrun=no
goto, starting
return

openlists:
run, %a_workingdir%\DownloadedCasts
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

guiclose1:
gui, destroy
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

introgui1:
gui,add,button,gExitManual x1060 y1,x
Gui, Add, picture, x0 y0 w260 h250, %a_workingdir%\html\ahkpod.ico
Gui, Font, Bold
Gui, Font, s14
/*
gui, add, text,y5 S52 gEditSubs,Edit My Automatic Subscriptions
Gui, Font, s7
 gui,add,button, gEditSubs h7,Edit My Auto Subscriptions
gui, add, text,

*/

;gui, add, text,  S52 gGoListEditor,DownloadedCasts List Editor
;Gui, Font, s7
; gui,add,button,gGoListEditor h7,Edit My Downloaded Lists with "DownloadedCasts List Editor""
;gui, add, text,

;Gui, Font, bold
Gui, Font, s6
gui,add,button,x260 y20 gimportopml,Import Opml


Gui, Font, Bold
Gui, Font, s14
gui, add, text,  S52 x260 y60 gManualDownloader, Manage Subscriptions: "ManualOnly" List and "Normal, Auto-Subscription" List
Gui, Font, s7
;gui, add, text,ManualDownloader,(This is a separate list of subscriptions that are never auto downloaded with normal run.`n Rather, the individual episode you mark for downloading, then click download marked.`n %a_tab%This is ideal for overly prolific podcasters.)
gui,add,button,gManualDownloader h7,Manage Subscriptions: Manual and Auto
Gui, Font, s7
gui, add, text

/*
Gui, Font, Bold
Gui, Font, s14
gui, add, text, S52 gDoDry, Do a List Building Run.
Gui, Font, s7
gui, add, text,gDoDry,(Great for first runs and after adding a podcast to regular/auto subscription list. `nThis will build the "Automatic Downloaded List" up to all possible casts. `n Just click desired episodes listed in "DownloadedCasts List Editor", to download the ones you want.)
gui,add,button,gDoDry h7,Do a Dry/List-Builder Run
gui, add, text,
Gui, Font, Bold
Gui, Font, s14
*/

Gui, Font, Bold
Gui, Font, s14, cred
gui, add, text, S52 gGo w800,Go Normal, Auto-Run!
Gui, Font, underline
Gui, Font, s26
gui,add,button,Default gGo h7 x530 y132 w170 h70 cRed,Go!
Gui, Font, normal
Gui, Font, bold
Gui, Font, s7
gui, add, text, x500 y240,(This dialog will time out in 3 minutes to do a normal run, for auto-subscriptions.)



SetTimer, go, 200000
gui, show,, AHKPod: Intro Dialog
return

go:
gui, submit
gui, destroy
return

DoDry:
dryrun=yes
gui, submit
gui, destroy
return

GoListEditor:
gui, submit
gui, destroy
goto, listeditor
return


EditSubs:
ifwinnotexist, podcast-subscriptions
   run, notepad.exe %a_workingdir%\podcasts-subscriptions.txt
;goto, ManualDownloader
return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::::::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::::::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::::::::::::::::::
ManualDownloader:
msgbox,0,Explanation, There are two subscription lists:  The "manual only" download list;  and the "Automatic Subscription list"`n`n You can add subscriptions directly to the automatic list`, or add to manual list`,`n%a_tab% download episodes you want`,`n %a_tab%then`, right click and add to automatic list. ,12
menu, tray, disable, Edit Lists of Successful Downloads
ManualDownloaderref:

SetTimer, go,off
gui,destroy
Gui, add, tab, vMyTab h280 w380 cNavy,ManualSubscription List Editor|Automatic Subscription List Editor
Gui, Tab,ManualSubscription List Editor
gui, add, listbox,vplist1 gplist1 sort w300 h400
gui,add,listview,w800 h400 vpcast1 gpcasts1 altsubmit x+10,Episode Name|Downloaded|date|URL
gui,add,edit,vedit w500 x10
gui,add,button,gAdd1 x520 y435,Add Subscription!
;gui,add,button,gupdate2 y437 x10,Update selected podcast
;gui,add,button,gAdd1 y437,Add a New Podcast Subscription
;gui,add,button,gDelManSub y437 x300, Delete Selected Subscription!
gui,add,button,ggo1 x10 y467,Mark selected files for download
gui,add, button,gdownload1 y467 x300,Download marked files
 
;gui,add,button,gEraseAllManual x10,Erase all Manual Podcast Subscriptions!
gui,add,button,gGuiClose x800 y467, Close and move on.

Menu, MyRightMenu, Add, Add this subscription to Normal-Automatic Subscriptions.,addauto ; ScanDisk Right Click Info
Menu, MyRightMenu, Add, Delete this subscription from manual subscription list., DelManSub
Menu, MyRightMenu, Add,Update selected podcast,update2   


tooltip, Right-click context menu available., 100, 150
sleep, 1000
SetTimer, RemoveToolTip, Off
ToolTip

ifnotexist, urlz.ulz
   {
      msgbox, 4, Choose, Do you want to look for the backup for subscriptions?
ifmsgbox yes
{
   ifexist, urlz-last.ulz
      filecopy, urlz-last.ulz, urlz.ulz
   filecopydir, %a_workingdir%\casts-backup, %a_workingdir%\casts
}
else
 msgbox, you chose no
}

Populate1:
total=
guicontrol,,plist1,|
loop, casts\*.ini
{
 stringreplace,file,a_loopfilename,.ini
 total=%total%%file%|
}
;msgbox, %total%
GuiControl,,plist1,%total%
;return

Gui, Tab, Automatic Subscription List Editor
;msgbox, Automatic Subscription List Editor
Gui, Font, Bold
Gui, Font, s14
Gui, Font, underline
gui, add, text,h20 x40 y27  S52 ,List Editor for Automatic Downloaded Podcasts:
;testing here
Gui, Font, s7
 gui,add,button,x650 y27 gplistaa h7,Refresh Episode Listings

Gui, Font, normal
gui, add, listbox,vplista gplista sort w250 h300 x10 y50
gui,add,listview,w550 h300 vpcasta gpcastsa altsubmit x+10,Episode

Gui, Font, Bold
Gui, Font, underline
gui, add, text,h30 x10 y370  , Click on Left to select a subscription.%a_space%%a_space%%a_space%%a_space%%a_space%%a_tab%%a_tab%%a_space%%a_space%%a_space%& Double-Click on right box to delete items in your "Downloaded List", in order to download the item!
Gui, Font, s6
Gui, Font,
;gui, add, text,,
gui,add,edit,vedit0 w500 x10 y385
gui,add,button,gadd0 x530 y385,Add a new podcast or Edit subscription list ;need
Gui, Font, normal
Gui, Font, cNavy
;gui,add,button,gpopulate h7,Refresh Subscription List
gui,add,button,gstartdry x10 h7 y440 cNavy,Start Another Dry Run to Catchup all Auto-Subscriptions' Episode Lists!
gui, add, text,
gui, add, text,gDoDry x10 h7 ,A Dry Run is great after adding a podcast to regular/auto subscription list. `nThis will build the "Automatic Downloaded List" up to all possible casts. `n After a dry run, just double click desired episodes in right pane here, to download the ones you want.)`n`nIt is unnecessary if you add a subscription to manual list first, mark and download episodes you want, then right click a selected manual podcast, and add to auto list.

Gui, Font, Bold
Gui, Font, underline

gui,add,button,gstartdown w600 y440 x450 cNavy,Start Downloading New Auto Subscriptions!
Gui, Font, bold
Gui, Font, underline
Gui, Font, s5
gui,add,button,gSchedule x10,Scheduler

;Menu, MyRightMenu2, Add, Click here to delete this subscription from auto subscription list., DelAutoSub
Menu, GuiContextMenu, Add, Click here to delete this subscription from auto subscription list., DelAutoSub
Menu, GuiContextMenu, Add, Click here to Open Downloaded list directory., openlists
Menu, GuiContextMenu, Add, Click here to Edit Raw Auto-Subscription List., editsubs

;gui, show,, List Editor of Downloaded Stuff

Populate:
GuiControl,, MainEdit
total=
guicontrol,,plist,|
Loop, DownloadedCasts\*.txt,,
{
  stringreplace,file,a_loopfilename,.ini
 total=%total%%file%|
}
GuiControl,,plist,%total%
gui, show,, ManualDownloader
; need to add populate0

Populateautolisteditor2:
GuiControl,, MainEdita
total=
guicontrol,,plista,|
Loop, DownloadedCasts\*.txt,,
{
  stringreplace,filea,a_loopfilename,.ini
 total=%total%%filea%|
}
GuiControl,,plista,%total%

return

;;;;;;;;;;;;;;;adding unique

Add0:
operation=newcast
gui, submit, nohide
fileappend, `n%edit0%,%a_workingdir%\podcasts-subscriptions.txt
ifwinnotexist, podcast-subscriptions
   run, notepad.exe %a_workingdir%\podcasts-subscriptions.txt
sleep, 6000
   msgbox,0,Adding  subscriptions, Adding subscriptions via this box will not show up in left panel until after a dry run.`nYou may desire to add in Manual tab`, then right click it to add to Automatic Subscription list.,12
WinMaximize, Adding subscriptions
return

plistaa:
gosub, populate
plista:      ;Left menu
;msgbox, %A_GuiEvent%
if A_GuiControl = plista
;if A_GuiEvent = RightClick
  {
;msgbox, %A_GuiEvent%%A_EventInfo%
castdel:=plista
LV_GetText(RowText, A_EventInfo) 
; msgbox, %RowText%:%plista%:%castdel%
GuiX:=A_GuiX+250
GuiY:=A_GuiY+250
 Menu,GuiContextMenu,Show, %GuiX%,%GuiY%
}
;msgbox,%A_GuiControl%
gui,listview,pcasta
lv_delete()
guicontrol,,pcastsa,|
gui,submit,nohide

guicontrol,,pcasta,|
   

;msgbox,%plist% : %Rowtext%
Loop, Read, %a_workingdir%\DownloadedCasts\%plista%
{
 LV_Add("", A_LoopReadLine)
}
GuiControl,,pcasta,%total%
return

pcastsa:
        ; right menu
if a_guievent = Doubleclick
{
   LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
Tooltip,  Will download next run!  Deleting "listed as downloaded": "%RowText%"
SetTimer, RemoveToolTip, 600

;LV_Delete()
fileread, chopthis,%a_workingdir%\DownloadedCasts\%plista%
stringreplace,chopthis,chopthis,%RowText%,
stringreplace,chopthis,chopthis,`r`n`r`n`r`n,`r`n,1
stringreplace,chopthis,chopthis,`r`n`r`n,`r`n,1
chopthis := RegExReplace(chopthis,"\R+", "`r`n")
;Loop
;{
;    StringReplace, chopthis, chopthis, `r`n`r`n, `r`n, UseErrorLevel
;    if ErrorLevel = 0  ; No more replacements needed.
;        break
;}
;msgbox, %chopthis%
filemove, %a_workingdir%\DownloadedCasts\%plista%,%a_workingdir%\DownloadedCasts\%plista%.old,1
fileappend,%chopthis%,%a_workingdir%\DownloadedCasts\%plista%
}
;Loop, Read, %a_workingdir%\DownloadedCasts\%plist%
;
;{
; LV_Add("", A_LoopReadLine)
;}
;GuiControl,,pcast,%total%

return
;;;;;;;;;;;;;;;;;adding unique


plist1:
   LV_GetText(RowText, A_EventInfo)
;msgbox, %plist1%: %RowText%
fileread,download,download.ini
gui,listview,pcast1
lv_delete()
guicontrol,,pcasts1,|
gui,submit,nohide
loop,read,casts\%plist1%.ini
{
 if a_loopreadline contains title=
 {
  stringsplit,out,a_loopreadline,=
  iniread,date1,casts\%plist1%.ini,%out2%,date1,error
  iniread,url,casts\%plist1%.ini,%out2%,url1,error
  splitpath,url,file
;;;;;changing cause need to mark as downloaded even after transcoding and deleting  ifexist %plist1%\%file%
fileread, manualdownloaded,manualdownloaded.txt
ifinstring, manualdownloaded, %file%
  c=Downloaded
  else if download contains %url%
  c=Marked to download
  else
  c=Not Downloaded
  lv_add("",out2,c,date1,url)
 }
}
lv_modifycol()
lv_modifycol(3,"SortDesc")
return

pcasts1:
if a_guievent = doubleclick
{
 LV_Gettext(file,LV_GetNext(0),4)
 splitpath,file,file
 loop,%file%,1,1
 run %a_loopfilefullpath%
}
return

go1:
gui,submit,nohide
loop,
{
 RowNumber := LV_GetNext(RowNumber)
 if not rownumber
 break
 loop,4
 lv_gettext(a%a_index%,rownumber,a_index)
 if a2 = downloaded
 continue
 lv_modify(rownumber,"",a1,"Marked for Download",a3,a4)
 splitpath,a4,file
 iniwrite,%plist1%\%a4%,download.ini,url,%a1%
 loop,
 {
  iniread,out,download.ini,download,%a_index%,error
  if out=error
  {
   iniwrite,%a1%,download.ini,download,%a_index%
   break
  }
 }
}
lv_modifycol(2)
return
Add1:
operation=newcast1
gui, submit, nohide
filedelete,download.dnl
urldownloadtofile,  %edit%, download.dnl


gosub, strip10
iniwrite,%edit%,urlz.ulz,Sites,%file%
;gosub, populate1
total=
guicontrol,,plist1,|
loop, casts\*.ini
{
 stringreplace,file,a_loopfilename,.ini
 total=%total%%file%|
}
;msgbox, %total%
GuiControl,,plist1,%total%

guicontrol,,edit,
filecopy,%a_workingdir%\urlz.ulz,%a_workingdir%\urlz-last.ulz,1
filecopydir, %a_workingdir%\casts, %a_workingdir%\casts-backup
;msgbox, added
;goto,ManualDownloader

return
 
strip1:
fileread, info, download.dnl
stringreplace, info, info, &amp;, %a_space%and%a_space%, all
stringreplace, info, info, <item>, ®, all
needle = Ui)"(http://[^[:space:]]*(m4v|mp4|mp3))"
loop, parse, info, ®
{
 search=%a_loopfield%
 RegExMatch(a_loopfield, "Ui)<description>(.*)</description>" ,description)
 RegExMatch(a_loopfield, "Ui)<pubdate>(.*)</pubdate>" ,pubdate)
 RegExMatch(a_loopfield, "U)<title(.*)</title>", title)
 RegExMatch(search,needle,url)
 if url1=
 filecreatedir,dnw
 fileappend,%a_loopfield%,dnw\%title1%.txt
 gosub, fix1
 if a_index = 1
 {
  file := regexreplace(title1,"i)[^a-z0-9[:space:])(]")
  fileread, compare, casts\%file%.ini
  continue
 }
 title := regexreplace(title1,"i)[^a-z0-9[:space:]]")
 gosub, date1
 description := regexreplace(description1,"U)(\t|\n|\r|<.*>|\&..;|\[.*]|\||]\>|)")
 stringleft, description1, description1, 150
 url=
 if islabel(operation)
 gosub, %operation%
}
return

f1::
reload
return


fix1:
Loop
{
 regexmatch(url1, "`%(..)",ascii)
 StringReplace, url1, url1, `%%ascii1%, % Chr("0x" . ascii1), All
 if errorlevel <> 0
 break
}
return


date1:
d = 1
loop, parse, pubdate, %a_space%
{
 if a_loopfield =
 continue
 p%d% = %a_loopfield%
 d += 1
}
loop, 12
{
 month = %a_index%
 if StrLen(month)=1
 month = 0%month%
 formattime, out, 2008%month%01, MMM
 if out = %p3%
 {
  if a_index < 10
  p3 = 0%a_index%
  else
  p3 = %a_index%
 }
}
if StrLen(p2) =1
p2 = 0%p2%
date1 = %p4%%p3%%p2%
return

update2:
gui,submit,nohide
iniread,out,urlz.ulz,sites,%plist1%
filedelete, download.dnl
urldownloadtofile,%out%,download.dnl
operation=msg1
gosub, strip1
gosub, plist1
gosub, pcasts1

;goto, manualdownloaderref
return

DelManSub:
gui,submit,nohide
iniread,out,urlz.ulz,sites,%plist1%
filedelete, casts\%plist1%.ini
fileread, sitedel, urlz.ulz
inidelete,urlz.ulz,sites,%plist1%
;goto, populate1
goto, manualdownloaderref
return

msg1:
iniread,out,casts\%plist1%.ini,%title%,date1,error
if out = error
{
 gosub, newcast1
}
return

newcast1:
if url1=
return
info=title,url1,date1,description1
loop,parse,info,`,
{
 filecreatedir,casts
 iniwrite,% %a_loopfield%,casts\%file%.ini,%title%,%a_loopfield%
}
return

download1:
ifnotexist,download.ini
{
 msgbox select some files to download first
 return
}
loop,
{
 iniread,out,download.ini,download,%a_index%
 if out=error
 break
 title=%out%
 iniread,out,download.ini,url,%out%
 stringsplit,out,out,\
 splitpath,out2,file
 filecreatedir,%out1%
 dir=%out1%
 settimer,flash1,30
;msgbox,%out2%`, %usbl%:\%downloadpodcast_to%\%out1%\%file%
ifnotexist, %usbl%:\%downloadpodcast_to%\%out1%
   filecreatedir, %usbl%:\%downloadpodcast_to%\%out1%
 urldownloadtofile,%out2%,%usbl%:\%downloadpodcast_to%\%out1%\%file%
fileappend,%out1%\%file%`n, manualdownloaded.txt
filegetsize,fs, %usbl%:\%downloadpodcast_to%\%out1%\%file%,k
if fs<90
   filedelete,%usbl%:\%downloadpodcast_to%\%out1%\%file%

 settimer,flash1,off
 inidelete,download.ini,url,%title%
 lv_modify(rownumber,"",a1,"Downloaded",a3,a4)
}
filedelete,download.ini
return

flash1:
if flash=Downloading
flash=
else
flash=Downloading
Loop % LV_GetCount()
{
 LV_GetText(name, A_Index)
 if name = %title%
 {
  rownumber=%a_index%
  loop,4
  lv_gettext(a%a_index%,rownumber,a_index)
  lv_modifycol(2,100)
  lv_modify(rownumber,"",a1,flash,a3,a4)
  sleep,200
  break
 }
}
return
 
EraseAllManual:
msgbox, 4, Erasing all!, Warning, this will erase all manual subscriptions as just seen.  `n Do you wish to continue?
ifmsgbox no
   return
Msgbox, This will not affect the automatic subscriptions.`nIf you change your mind`, there is a backup of all subscriptions in the ahkpod directory, until you start adding subscriptions.
filedelete, download.dnl
filedelete,urlz.ulz
fileremovedir, %a_workingdir%\dnw,1
fileremovedir, %a_workingdir%\casts,1
gui, destroy
goto, IntroDialogs
return

;right click menu
GuiContextMenu:
RowText=
if A_GuiControl = plist1
   {
LV_GetText(RowText2, A_EventInfo) 
; msgbox, %RowText2%
 Menu,MyRightMenu,Show, %A_GuiX%,%A_GuiY%
}
Return


addauto:
; msgbox,Adding %RowText% to auto subscriptions %file% :%plist1%
iniread,outurl,urlz.ulz,sites,%plist1%
msgbox, Adding to Recurring Automatic Subscritions: %plist1%=%outurl% to podcast-subscriptions.txt
fileappend, `;%plist1%`n%outurl%`n,%a_workingdir%\podcasts-subscriptions.txt
fileread, episodelist, %a_workingdir%\casts\%plist1%.ini
Loop
 {
    StringReplace, episodelist, episodelist, `r`n[,¿ , UseErrorLevel
    if ErrorLevel = 0  ; No more replacements needed.
        break
}
Loop
 {
    StringReplace, episodelist, episodelist, `r`n, , UseErrorLevel
    if ErrorLevel = 0  ; No more replacements needed.
        break
}
;Stringreplace,episodelist,episodelist,`r`n,,1
;Stringreplace,episodelist,episodelist,`n,,1
;episodelist := RegExReplace(episodelist,"\R+", "`r`n")
;episodelist := RegExReplace(episodelist,"`r`n[","¿")
;msgbox, %episodelist%
;episodelist := RegExReplace(episodelist,"\R","`r`n")
;fileappend, %episodelist%, testepisodelist.txt

loop, parse, episodelist,¿
{
;   msgbox, %a_index%=%A_LoopField%
   fileappend,%A_LoopField%`n, %a_workingdir%\DownloadedCasts\%plist1%.txt
}
return



guiclose:

gui, destroy
goto, IntroDialogs
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::::::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::::::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::::::::::::::::::
schedule:
run, Control Panel
winwait, Control Panel
winactivate, Control Panel
sleep, 1000
send,ss
controlsend,,ss,Control Panel
sleep, 1000
run, ::{d6277990-4c6a-11cf-8d87-00aa0060f5bf}
winwait, Scheduled Tasks
winactivate, Scheduled Tasks
;winmaximize,Scheduled Tasks
return

strip10:
fileread, info, download.dnl
stringreplace, info, info, &amp;, %a_space%and%a_space%, all
stringreplace, info, info, <item>, ®, all
needle = Ui)"(http://[^[:space:]]*(m4v|mp4|mp3))"
loop, parse, info, ®
{
 search=%a_loopfield%
 RegExMatch(a_loopfield, "Ui)<description>(.*)</description>" ,description)
 RegExMatch(a_loopfield, "Ui)<pubdate>(.*)</pubdate>" ,pubdate)
 RegExMatch(a_loopfield, "U)<title(.*)</title>", title)
 RegExMatch(search,needle,url)
 if url1=
 filecreatedir,dnw
 fileappend,%a_loopfield%,dnw\%title1%.txt
 
 gosub, fix1

 if a_index = 1
 {
  file := regexreplace(title1,"i)[^a-z0-9[:space:])(]")
  fileread, compare, casts\%file%.ini
  continue
 }
 title := regexreplace(title1,"i)[^a-z0-9[:space:]]")
 gosub, date1
 description := regexreplace(description1,"U)(\t|\n|\r|<.*>|\&..;|\[.*]|\||]\>|)")
 stringleft, description1, description1, 150
 url=
 if islabel(operation)

if url1=
return
info=title,url1,date1,description1
loop,parse,info,`,
{
 filecreatedir,casts
 iniwrite,% %a_loopfield%,casts\%file%.ini,%title%,%a_loopfield%
}


}


return

GuiContextMenu2:
RowText=

if A_GuiControl = plista
   {
LV_GetText(RowText22, A_EventInfo) 
 msgbox, %RowText2%
 Menu,MyRightMenu2,Show, %A_GuiX%,%A_GuiY%
}
Return

DelAutoSub:
LV_GetText(RowText22, A_EventInfo) 
run, notepad.exe podcasts-subscriptions.txt
;msgbox,  %plista%:%RowText%:%castdel%
filedelete, %a_workingdir%\DownloadedCasts\%castdel%
fileappend,filedelete`, %a_workingdir%\DownloadedCasts\%castdel%.txt`n,delrout.txt
tooltip,  %castdel%: deleted all episode files. You must manually delete the subscription entry from this txt file`, podcasts-subscriptions.txt `n and save file.,,250
sleep,16000
tooltip
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

importopml:

;FileSelectFile, OutputVar [, Options, RootDir\Filename, Prompt, Filter]
FileSelectFile, importedopml, , %a_workingdir%, Please select an opml file to import, *.opml
SplashTextOn, 300, 50, Importing! Please stand by., Importing! Please stand by.
fileread, importedopml ,%importedopml%
filedelete, temp.opml
fileappend, %importedopml%, temp.opml

loop, read, %a_workingdir%\temp.opml

{
   ifnotinstring,A_LoopReadLine,http   
      continue

;   msgbox, %A_LoopReadLine%
   Stringreplace,alf,A_LoopReadLine,   <outline text=",¬
   Stringreplace,alf,alf," type=",¬
   Stringreplace,alf,alf," xmlUrl=",¬
   Stringreplace,alf,alf," htmlUrl=",¬
   Stringreplace,alf,alf," />,¬
   Stringreplace,alf,alf,-,,1
   Stringreplace,alf,alf,#,,1


   loop, parse,alf, ¬
   {
   if A_Index=2
      {
         fileappend, %A_LoopField%,%a_workingdir%\urlz.ulz
         fileappend, =,%a_workingdir%\urlz.ulz
         fileappend, `n,%a_workingdir%\casts\%A_LoopField%.ini
         showtitle=%A_LoopField%
         }
;   msgbox, Title is %A_LoopField%

   if A_Index=4
{
         fileappend, %A_LoopField%`n,%a_workingdir%\urlz.ulz
         gosub, downloadlist
         }   ;   msgbox, xml is  %A_LoopField%

;   if A_Index=5
;   msgbox, http url is %A_LoopField%


   }
}
SplashTextOff

return

downloadlist:
filedelete, download.dnl
urldownloadtofile,%A_LoopField%,download.dnl
;msgbox, download.dnl
operation=msg1
;;;;;;;gosub, strip1
fileread, info, download.dnl
stringreplace, info, info, &amp;, %a_space%and%a_space%, all
stringreplace, info, info, <item>, ®, all
needle = Ui)"(http://[^[:space:]]*(m4v|mp4|mp3))"
loop, parse, info, ®
{
 search=%a_loopfield%
 RegExMatch(a_loopfield, "Ui)<description(.*)</description>" ,description)
 RegExMatch(a_loopfield, "Ui)<pubdate>(.*)</pubdate>" ,pubdate)
 RegExMatch(a_loopfield, "U)<title(.*)</title>", titl)
 StringReplace, titl, titl, `%%ascii1%, % Chr("0x" . ascii1), All

 RegExMatch(search,needle,url)

Stringreplace, titl, titl, <title>,
Stringreplace, titl, titl, <title >,
Stringreplace, titl, titl, </title>,
Stringreplace, titl, titl, </title >,
Stringreplace, titl, titl, -,

Stringreplace, url, url,",,1

Stringreplace, pubdate, pubdate, <pubdate>,
Stringreplace, pubdate, pubdate, <pubdate >,
Stringreplace, pubdate, pubdate, </pubdate>,
Stringreplace, pubdate, pubdate, </pubdate >,
stringmid,pubyear,pubdate,13,4
stringmid,pubday,pubdate,6,2
stringmid,pubmo,pubdate,9,3
if pubmo=jan
   pubmo=01
if pubmo=feb
   pubmo=02
if pubmo=mar
   pubmo=03
if pubmo=apr
   pubmo=04
if pubmo=may
   pubmo=05
if pubmo=jun
   pubmo=06
if pubmo=jul
   pubmo=07
if pubmo=aug
   pubmo=08
if pubmo=sep
   pubmo=09
if pubmo=oct
   pubmo=10
if pubmo=nov
   pubmo=11
if pubmo=dec
   pubmo=12
 description := regexreplace(description1,"U)(\t|\n|\r|<.*>|\&..;|\[.*]|\||]\>|)")
 stringleft, description1, description1, 150
;gosub, changepubdate


ifnotinstring, url, http
   continue
Stringreplace, titl, titl, -,

;msgbox, titl:%titl%-url:%url%-desc:%description%-pubdate:%pubdate%
;msgbox, `[%titl%`]`ntitle=%titl%`nurl1=%url%`ndate1=%pubdate%`ndescription1=%description%`n`n`, %a_workingdir%\casts\%showtitle%.ini
fileappend, `[%titl%`]`ntitle=%titl%`nurl1=%url%`ndate1=%pubyear%%pubmo%%pubday%`ndescription1=%description%`n, %a_workingdir%\casts\%showtitle%.ini
}
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



Last edited by degarb on February 9th, 2010, 5:19 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2010, 9:50 pm 
Offline

Joined: February 14th, 2007, 8:01 pm
Posts: 308
Today adding import opml (early beta without proper regex) and some minor bug fix. I updated posted code, and site (plus adding screenshot).


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], nimda, notsoobvious, Relayer and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group