MergePlaylist.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #include "main.h"
  2. #include "MergePlaylist.h"
  3. #include <strsafe.h>
  4. merge_pl_entry::merge_pl_entry( const wchar_t *p_filename, const wchar_t *p_title, int p_length_ms )
  5. {
  6. SetFilename( p_filename );
  7. SetTitle( p_title );
  8. SetLengthMilliseconds( p_length_ms );
  9. }
  10. merge_pl_entry::~merge_pl_entry()
  11. {
  12. plstring_release( this->filename );
  13. plstring_release( this->filetitle );
  14. }
  15. size_t merge_pl_entry::GetFilename( wchar_t *p_filename, size_t filenameCch )
  16. {
  17. if ( !this->filename )
  18. return 0;
  19. if ( !p_filename )
  20. return wcslen( this->filename );
  21. if ( !this->filename[ 0 ] )
  22. return 0;
  23. StringCchCopyW( p_filename, filenameCch, this->filename );
  24. return 1;
  25. }
  26. size_t merge_pl_entry::GetTitle( wchar_t *p_title, size_t titleCch )
  27. {
  28. if ( !this->filetitle )
  29. return 0;
  30. if ( !p_title )
  31. return wcslen( this->filetitle );
  32. if ( !this->filetitle[ 0 ] )
  33. return 0;
  34. StringCchCopyW( p_title, titleCch, this->filetitle );
  35. return 1;
  36. }
  37. int merge_pl_entry::GetLengthInMilliseconds()
  38. {
  39. return length;
  40. }
  41. size_t merge_pl_entry::GetExtendedInfo( const wchar_t *metadata, wchar_t *info, size_t infoCch )
  42. {
  43. return 0;
  44. }
  45. void merge_pl_entry::SetFilename( const wchar_t *p_filename )
  46. {
  47. plstring_release( this->filename );
  48. if ( p_filename && p_filename[ 0 ] )
  49. this->filename = plstring_wcsdup( p_filename );
  50. else
  51. this->filename = 0;
  52. }
  53. void merge_pl_entry::SetTitle( const wchar_t *p_title )
  54. {
  55. plstring_release( filetitle );
  56. if ( p_title && p_title[ 0 ] )
  57. {
  58. this->filetitle = plstring_wcsdup( p_title );
  59. this->cached = true;
  60. }
  61. else
  62. filetitle = 0;
  63. }
  64. void merge_pl_entry::SetLengthMilliseconds( int p_length_ms )
  65. {
  66. if ( p_length_ms <= 0 )
  67. this->length = -1000;
  68. else
  69. this->length = p_length_ms;
  70. }
  71. MergePlaylist::MergePlaylist()
  72. {
  73. total_time = 0;
  74. }
  75. void MergePlaylist::Clear()
  76. {
  77. for ( merge_pl_entry *l_merged_entry : entries )
  78. delete l_merged_entry;
  79. entries.clear();
  80. }
  81. void MergePlaylist::OnFile( const wchar_t *p_filename, const wchar_t *p_title, int lengthInMS, ifc_plentryinfo *info )
  82. {
  83. if ( lengthInMS > 0 )
  84. total_time += lengthInMS;
  85. entries.push_back( new merge_pl_entry( p_filename, p_title, lengthInMS ) );
  86. }
  87. void MergePlaylist::AppendWithInfo( const wchar_t *p_filename, const wchar_t *p_title, int lengthInMS )
  88. {
  89. if ( lengthInMS > 0 )
  90. total_time += lengthInMS;
  91. entries.push_back( new merge_pl_entry( p_filename, p_title, lengthInMS ) );
  92. }
  93. MergePlaylist::~MergePlaylist()
  94. {
  95. Clear();
  96. }
  97. size_t MergePlaylist::GetNumItems()
  98. {
  99. return entries.size();
  100. }
  101. size_t MergePlaylist::GetItem( size_t item, wchar_t *p_filename, size_t filenameCch )
  102. {
  103. if ( item >= entries.size() )
  104. return 0;
  105. return entries[ item ]->GetFilename( p_filename, filenameCch );
  106. }
  107. size_t MergePlaylist::GetItemTitle( size_t item, wchar_t *p_title, size_t titleCch )
  108. {
  109. if ( item >= entries.size() )
  110. return 0;
  111. return entries[ item ]->GetTitle( p_title, titleCch );
  112. }
  113. const wchar_t *MergePlaylist::ItemTitle( size_t item )
  114. {
  115. if ( item >= entries.size() )
  116. return 0;
  117. return entries[ item ]->filetitle;
  118. }
  119. const wchar_t *MergePlaylist::ItemName( size_t item )
  120. {
  121. if ( item >= entries.size() )
  122. return 0;
  123. return entries[ item ]->filename;
  124. }
  125. int MergePlaylist::GetItemLengthMilliseconds( size_t item )
  126. {
  127. if ( item >= entries.size() )
  128. return -1;
  129. return entries[ item ]->GetLengthInMilliseconds();
  130. }
  131. size_t MergePlaylist::GetItemExtendedInfo( size_t item, const wchar_t *metadata, wchar_t *info, size_t infoCch )
  132. {
  133. if ( item >= entries.size() )
  134. return 0;
  135. return entries[ item ]->GetExtendedInfo( metadata, info, infoCch );
  136. }
  137. void MergePlaylist::SetItemFilename( size_t item, const wchar_t *p_filename )
  138. {
  139. if ( item < entries.size() )
  140. entries[ item ]->SetFilename( p_filename );
  141. }
  142. void MergePlaylist::SetItemTitle( size_t item, const wchar_t *p_title )
  143. {
  144. if ( item < entries.size() )
  145. entries[ item ]->SetTitle( p_title );
  146. }
  147. void MergePlaylist::SetItemLengthMilliseconds( size_t item, int p_length_ms )
  148. {
  149. if ( item < entries.size() )
  150. entries[ item ]->SetLengthMilliseconds( p_length_ms );
  151. }
  152. void MergePlaylist::AppendPlaylist( MergePlaylist &copy )
  153. {
  154. for ( merge_pl_entry *l_merged_entry : copy.entries )
  155. {
  156. if ( l_merged_entry->filename && !HasFilename( l_merged_entry->filename ) )
  157. {
  158. if ( l_merged_entry->length > 0 )
  159. total_time += l_merged_entry->length;
  160. entries.push_back( l_merged_entry );
  161. }
  162. }
  163. copy.entries.clear();
  164. }
  165. bool MergePlaylist::HasFilename( const wchar_t *p_filename )
  166. {
  167. for ( merge_pl_entry *l_merged_entry : entries )
  168. {
  169. if ( l_merged_entry->filename && !_wcsicmp( p_filename, l_merged_entry->filename ) )
  170. return true;
  171. }
  172. return false;
  173. }
  174. #ifdef CBCLASS
  175. #undef CBCLASS
  176. #endif
  177. #define CBCLASS MergePlaylist
  178. START_MULTIPATCH;
  179. START_PATCH(patch_playlist)
  180. M_VCB(patch_playlist, ifc_playlist, IFC_PLAYLIST_CLEAR, Clear)
  181. //M_VCB(patch_playlist, ifc_playlist, IFC_PLAYLIST_APPENDWITHINFO, AppendWithInfo)
  182. //M_VCB(patch_playlist, ifc_playlist, IFC_PLAYLIST_APPEND, Append)
  183. M_CB(patch_playlist, ifc_playlist, IFC_PLAYLIST_GETNUMITEMS, GetNumItems)
  184. M_CB(patch_playlist, ifc_playlist, IFC_PLAYLIST_GETITEM, GetItem)
  185. M_CB(patch_playlist, ifc_playlist, IFC_PLAYLIST_GETITEMTITLE, GetItemTitle)
  186. M_CB(patch_playlist, ifc_playlist, IFC_PLAYLIST_GETITEMLENGTHMILLISECONDS, GetItemLengthMilliseconds)
  187. M_CB(patch_playlist, ifc_playlist, IFC_PLAYLIST_GETITEMEXTENDEDINFO, GetItemExtendedInfo)
  188. NEXT_PATCH(patch_playlistloadercallback)
  189. M_VCB(patch_playlistloadercallback, ifc_playlistloadercallback, IFC_PLAYLISTLOADERCALLBACK_ONFILE, OnFile);
  190. END_PATCH
  191. END_MULTIPATCH;