MythTV  master
music.cpp
Go to the documentation of this file.
1 // Program Name: music.cpp
3 // Created : July 20, 2017
4 //
5 // Copyright (c) 2017 Paul Harrison <pharrison@mythtv.org>
6 //
7 // Licensed under the GPL v2 or later, see COPYING for details
8 //
10 
11 #include <cmath>
12 #include <unistd.h>
13 
14 #include "music.h"
15 
16 #include "musicmetadata.h"
17 
18 #include "mythversion.h"
19 #include "serviceUtil.h"
20 
22 //
24 
26  int nCount)
27 {
28  auto *all_music = new AllMusic();
29 
30  while (!all_music->doneLoading())
31  {
32  qApp->processEvents();
33  usleep(50000);
34  }
35 
36  MetadataPtrList *musicList = all_music->getAllMetadata();
37 
38  // ----------------------------------------------------------------------
39  // Build Response
40  // ----------------------------------------------------------------------
41 
42  auto *pMusicMetadataInfos = new DTC::MusicMetadataInfoList();
43 
44  nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, musicList->count() ) : 0;
45  nCount = (nCount > 0) ? std::min( nCount, musicList->count() ) : musicList->count();
46  int nEndIndex = std::min((nStartIndex + nCount), musicList->count() );
47 
48  for( int n = nStartIndex; n < nEndIndex; n++ )
49  {
50  DTC::MusicMetadataInfo *pMusicMetadataInfo = pMusicMetadataInfos->AddNewMusicMetadataInfo();
51 
52  MusicMetadata *metadata = musicList->at(n);
53 
54  if (metadata)
55  FillMusicMetadataInfo ( pMusicMetadataInfo, metadata, true );
56  }
57 
58  int curPage = 0;
59  int totalPages = 0;
60  if (nCount == 0)
61  totalPages = 1;
62  else
63  totalPages = (int)std::ceil((float)musicList->count() / nCount);
64 
65  if (totalPages == 1)
66  curPage = 1;
67  else
68  {
69  curPage = (int)std::ceil((float)nStartIndex / nCount) + 1;
70  }
71 
72  pMusicMetadataInfos->setStartIndex ( nStartIndex );
73  pMusicMetadataInfos->setCount ( nCount );
74  pMusicMetadataInfos->setCurrentPage ( curPage );
75  pMusicMetadataInfos->setTotalPages ( totalPages );
76  pMusicMetadataInfos->setTotalAvailable( musicList->count() );
77  pMusicMetadataInfos->setAsOf ( MythDate::current() );
78  pMusicMetadataInfos->setVersion ( MYTH_BINARY_VERSION );
79  pMusicMetadataInfos->setProtoVer ( MYTH_PROTO_VERSION );
80 
81  delete all_music;
82 
83  return pMusicMetadataInfos;
84 }
85 
87 //
89 
91 {
92  auto *all_music = new AllMusic();
93 
94  while (!all_music->doneLoading())
95  {
96  qApp->processEvents();
97  usleep(50000);
98  }
99 
100  MusicMetadata *metadata = all_music->getMetadata(Id);
101 
102  if (!metadata)
103  {
104  delete all_music;
105  throw(QString("No metadata found for selected ID!."));
106  }
107 
108  auto *pMusicMetadataInfo = new DTC::MusicMetadataInfo();
109 
110  FillMusicMetadataInfo(pMusicMetadataInfo, metadata, true);
111 
112  delete all_music;
113 
114  return pMusicMetadataInfo;
115 }
serviceUtil.h
AllMusic
Definition: musicmetadata.h:418
MusicMetadata
Definition: musicmetadata.h:81
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
mythversion.h
Music::GetTrackList
DTC::MusicMetadataInfoList * GetTrackList(int StartIndex, int Count) override
Definition: music.cpp:25
MYTH_BINARY_VERSION
#define MYTH_BINARY_VERSION
Update this whenever the plug-in ABI changes.
Definition: mythversion.h:15
MYTH_PROTO_VERSION
#define MYTH_PROTO_VERSION
Increment this whenever the MythTV network protocol changes.
Definition: mythversion.h:47
FillMusicMetadataInfo
void FillMusicMetadataInfo(DTC::MusicMetadataInfo *pVideoMetadataInfo, MusicMetadata *pMetadata, bool bDetails)
Definition: serviceUtil.cpp:502
music.h
MetadataPtrList
QList< MusicMetadata * > MetadataPtrList
Definition: musicmetadata.h:395
DTC::MusicMetadataInfo
Definition: musicMetadataInfo.h:26
DTC::MusicMetadataInfoList
Definition: musicMetadataInfoList.h:25
Music::GetTrack
DTC::MusicMetadataInfo * GetTrack(int Id) override
Definition: music.cpp:90
musicmetadata.h