wac_playlists_entry.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #include "wac_playlists_entry.h"
  2. wa::Components::playlists::playlist_entry::playlist_entry( const std::wstring &p_filename, const std::wstring &p_title, int p_length_ms )
  3. {
  4. this->__filename = p_filename;
  5. this->__filetitle = p_title;
  6. SetLengthMilliseconds( p_length_ms );
  7. }
  8. wa::Components::playlists::playlist_entry::playlist_entry( const std::wstring &p_filename, const std::wstring &p_title, int p_length_ms, int p_size )
  9. {
  10. this->__filename = p_filename;
  11. this->__filetitle = p_title;
  12. SetLengthMilliseconds( p_length_ms );
  13. SetSizeBytes( p_size );
  14. }
  15. wa::Components::playlists::playlist_entry::playlist_entry( const std::wstring &p_filename, const std::wstring &p_title, int p_length_ms, ifc_plentryinfo *p_info )
  16. {
  17. this->__filename = p_filename;
  18. this->__filetitle = p_title;
  19. SetLengthMilliseconds( p_length_ms );
  20. if ( p_info )
  21. {
  22. SetMediahash( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_MEDIAHASH ) );
  23. SetMetahash( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_METAHASH ) );
  24. SetCloudID( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_CLOUD_ID ) );
  25. SetCloudStatus( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_CLOUD_STATUS ) );
  26. SetCloudDevices( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_CLOUD_DEVICES ) );
  27. }
  28. }
  29. wa::Components::playlists::playlist_entry::playlist_entry( const std::wstring &p_filename, const std::wstring &p_title, int p_length_ms, int p_size, ifc_plentryinfo *p_info )
  30. {
  31. this->__filename = p_filename;
  32. this->__filetitle = p_title;
  33. SetLengthMilliseconds( p_length_ms );
  34. SetSizeBytes( p_size );
  35. if ( p_info )
  36. {
  37. SetMediahash( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_MEDIAHASH ) );
  38. SetMetahash( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_METAHASH ) );
  39. SetCloudID( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_CLOUD_ID ) );
  40. SetCloudStatus( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_CLOUD_STATUS ) );
  41. SetCloudDevices( p_info->GetExtendedInfo( _CONST_PLAYLIST_INFO_CLOUD_DEVICES ) );
  42. }
  43. }
  44. wa::Components::playlists::playlist_entry::playlist_entry( const std::wstring &p_filename, const std::wstring &p_title, int p_length_ms,
  45. const std::wstring &p_mediahash, const std::wstring &p_metahash, const std::wstring &p_cloud_id, const std::wstring &p_cloud_status, const std::wstring &p_cloud_devices )
  46. {
  47. this->__filename = p_filename;
  48. this->__filetitle = p_title;
  49. SetLengthMilliseconds( p_length_ms );
  50. this->__mediahash = p_mediahash;
  51. this->__metahash = p_metahash;
  52. SetCloudID( p_cloud_id );
  53. SetCloudStatus( p_cloud_status );
  54. this->__cloud_devices = p_cloud_devices;
  55. }
  56. wa::Components::playlists::playlist_entry::playlist_entry( const std::wstring &p_filename, const std::wstring &p_title, int p_length_ms, int p_size,
  57. const std::wstring &p_mediahash, const std::wstring &p_metahash, const std::wstring &p_cloud_id, const std::wstring &p_cloud_status, const std::wstring &p_cloud_devices )
  58. {
  59. this->__filename = p_filename;
  60. this->__filetitle = p_title;
  61. SetLengthMilliseconds( p_length_ms );
  62. SetSizeBytes( p_size );
  63. this->__mediahash = p_mediahash;
  64. this->__metahash = p_metahash;
  65. SetCloudID( p_cloud_id );
  66. SetCloudStatus( p_cloud_status );
  67. this->__cloud_devices = p_cloud_devices;
  68. }
  69. size_t wa::Components::playlists::playlist_entry::GetFilename( std::wstring &p_filename, size_t p_filename_max_length )
  70. {
  71. if ( p_filename.empty() )
  72. return this->__filename.size();
  73. if ( this->__filename.empty() )
  74. return 0;
  75. p_filename = this->__filename.substr( 0, p_filename_max_length );
  76. return 1;
  77. }
  78. size_t wa::Components::playlists::playlist_entry::GetTitle( std::wstring &p_title, size_t p_title_max_length )
  79. {
  80. if ( p_title.empty() )
  81. return this->__filetitle.size();
  82. if ( this->__filetitle.empty() )
  83. return 0;
  84. p_title = this->__filetitle.substr( 0, p_title_max_length );
  85. return 1;
  86. }
  87. size_t wa::Components::playlists::playlist_entry::GetExtendedInfo( const std::wstring &p_metadata, std::wstring &p_result, const size_t p_result_max_length )
  88. {
  89. if ( !__cloud_id.empty() )
  90. {
  91. if ( p_metadata.compare( _CONST_PLAYLIST_INFO_MEDIAHASH ) == 0 )
  92. {
  93. if ( !__mediahash.empty() )
  94. {
  95. p_result = __mediahash.substr( 0, p_result_max_length );
  96. return 1;
  97. }
  98. else
  99. return 0;
  100. }
  101. else if ( p_metadata.compare( _CONST_PLAYLIST_INFO_METAHASH ) == 0 )
  102. {
  103. if ( !__metahash.empty() )
  104. {
  105. p_result = __metahash.substr( 0, p_result_max_length );
  106. return 1;
  107. }
  108. else
  109. return 0;
  110. }
  111. else if ( p_metadata.compare( _CONST_PLAYLIST_INFO_CLOUD_ID ) == 0 )
  112. {
  113. if ( !__cloud_id.empty() )
  114. {
  115. p_result = __cloud_id.substr( 0, p_result_max_length );
  116. return 1;
  117. }
  118. else
  119. return 0;
  120. }
  121. else if ( p_metadata.compare( _CONST_PLAYLIST_INFO_CLOUD_STATUS ) == 0 )
  122. {
  123. if ( !__cloud_status.empty() )
  124. {
  125. p_result = __cloud_status.substr( 0, p_result_max_length );
  126. return 1;
  127. }
  128. else
  129. return 0;
  130. }
  131. else if ( p_metadata.compare( _CONST_PLAYLIST_INFO_CLOUD_DEVICES ) == 0 )
  132. {
  133. if ( !__cloud_devices.empty() )
  134. {
  135. p_result = __cloud_devices.substr( 0, p_result_max_length );
  136. return 1;
  137. }
  138. else
  139. return 0;
  140. }
  141. else if ( p_metadata.compare( _CONST_PLAYLIST_INFO_CLOUD ) == 0 )
  142. {
  143. if ( _wtoi( __cloud_id.c_str() ) > 0 )
  144. {
  145. wchar_t l_result_buffer[ 500 ] = {0};
  146. swprintf_s( l_result_buffer, p_result_max_length, L"#EXT-X-NS-CLOUD:mediahash=%s,metahash=%s,cloud_id=%s,cloud_status=%s,cloud_devices=%s", __mediahash.c_str(), __metahash.c_str(), __cloud_id.c_str(), __cloud_status.c_str(), __cloud_devices.c_str() );
  147. p_result = std::wstring( l_result_buffer );
  148. return 1;
  149. }
  150. }
  151. }
  152. return 0;
  153. }
  154. void wa::Components::playlists::playlist_entry::SetFilename( const std::wstring &p_filename )
  155. {
  156. this->__filename = p_filename;
  157. if ( p_filename.size() > 4 )
  158. __is_local_file = this->__filename.substr( 0, 4 ).compare( L"http" ) != 0;
  159. }
  160. void wa::Components::playlists::playlist_entry::SetTitle( const std::wstring &p_title )
  161. {
  162. this->__filetitle = p_title;
  163. this->__is_cached = !p_title.empty();
  164. }
  165. void wa::Components::playlists::playlist_entry::SetLengthMilliseconds( int p_length_ms )
  166. {
  167. if ( p_length_ms <= 0 )
  168. this->__length_ms = -1000;
  169. else
  170. this->__length_ms = p_length_ms;
  171. }
  172. void wa::Components::playlists::playlist_entry::SetMediahash( const std::wstring &p_mediahash )
  173. {
  174. this->__mediahash = p_mediahash;
  175. }
  176. void wa::Components::playlists::playlist_entry::SetSizeBytes( int p_size )
  177. {
  178. if ( p_size <= 0 )
  179. this->__size = 0;
  180. else
  181. this->__size = p_size;
  182. }
  183. void wa::Components::playlists::playlist_entry::SetMetahash( const std::wstring &p_metahash )
  184. {
  185. this->__metahash = p_metahash;
  186. }
  187. void wa::Components::playlists::playlist_entry::SetCloudID( const std::wstring &p_cloud_id )
  188. {
  189. if ( _wtoi( p_cloud_id.c_str() ) > 0 )
  190. this->__cloud_id = p_cloud_id;
  191. else
  192. this->__cloud_id.clear();
  193. }
  194. void wa::Components::playlists::playlist_entry::SetCloudStatus( const std::wstring &p_cloud_status )
  195. {
  196. if ( _wtoi( p_cloud_status.c_str() ) > 0 )
  197. this->__cloud_status = p_cloud_status;
  198. else
  199. this->__cloud_status.clear();
  200. }
  201. void wa::Components::playlists::playlist_entry::SetCloudDevices( const std::wstring &p_cloud_devices )
  202. {
  203. this->__cloud_devices = p_cloud_devices;
  204. }