MythTV master
v2music.cpp
Go to the documentation of this file.
1
2// 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// C/C++
12#include <cmath>
13#include <unistd.h>
14
15// MythTV
17#include "libmythbase/mythversion.h"
19
20// MythBackend
21#include "v2music.h"
22#include "v2serviceUtil.h"
23
25//
27
28// This will be initialised in a thread safe manner on first use
30 (MUSIC_HANDLE, V2Music::staticMetaObject, &V2Music::RegisterCustomTypes))
31
33{
34 qRegisterMetaType<V2MusicMetadataInfoList*>("V2MusicMetadataInfoList");
35 qRegisterMetaType<V2MusicMetadataInfo*>("V2MusicMetadataInfo");
36}
37
39 : MythHTTPService(s_service)
40{
41}
42
44 int nCount)
45{
46 auto *all_music = new AllMusic();
47
48 while (!all_music->doneLoading())
49 {
50 qApp->processEvents();
51 usleep(50000);
52 }
53
54 MetadataPtrList *musicList = all_music->getAllMetadata();
55
56 // ----------------------------------------------------------------------
57 // Build Response
58 // ----------------------------------------------------------------------
59
60 auto *pMusicMetadataInfos = new V2MusicMetadataInfoList();
61
62 int musicListCount = musicList->count();
63 nStartIndex = (nStartIndex > 0) ? std::min( nStartIndex, musicListCount ) : 0;
64 nCount = (nCount > 0) ? std::min( nCount, musicListCount ) : musicListCount;
65 int nEndIndex = std::min((nStartIndex + nCount), musicListCount );
66
67 for( int n = nStartIndex; n < nEndIndex; n++ )
68 {
69 V2MusicMetadataInfo *pMusicMetadataInfo = pMusicMetadataInfos->AddNewMusicMetadataInfo();
70
71 MusicMetadata *metadata = musicList->at(n);
72
73 if (metadata)
74 V2FillMusicMetadataInfo ( pMusicMetadataInfo, metadata, true );
75 }
76
77 int curPage = 0;
78 int totalPages = 0;
79 if (nCount == 0)
80 totalPages = 1;
81 else
82 totalPages = (int)std::ceil((float)musicList->count() / nCount);
83
84 if (totalPages == 1)
85 curPage = 1;
86 else
87 {
88 curPage = (int)std::ceil((float)nStartIndex / nCount) + 1;
89 }
90
91 pMusicMetadataInfos->setStartIndex ( nStartIndex );
92 pMusicMetadataInfos->setCount ( nCount );
93 pMusicMetadataInfos->setCurrentPage ( curPage );
94 pMusicMetadataInfos->setTotalPages ( totalPages );
95 pMusicMetadataInfos->setTotalAvailable( musicList->count() );
96 pMusicMetadataInfos->setAsOf ( MythDate::current() );
97 pMusicMetadataInfos->setVersion ( MYTH_BINARY_VERSION );
98 pMusicMetadataInfos->setProtoVer ( MYTH_PROTO_VERSION );
99
100 delete all_music;
101
102 return pMusicMetadataInfos;
103}
104
106//
108
110{
111 auto *all_music = new AllMusic();
112
113 while (!all_music->doneLoading())
114 {
115 qApp->processEvents();
116 usleep(50000);
117 }
118
119 MusicMetadata *metadata = all_music->getMetadata(Id);
120
121 if (!metadata)
122 {
123 delete all_music;
124 throw(QString("No metadata found for selected ID!."));
125 }
126
127 auto *pMusicMetadataInfo = new V2MusicMetadataInfo();
128
129 V2FillMusicMetadataInfo(pMusicMetadataInfo, metadata, true);
130
131 delete all_music;
132
133 return pMusicMetadataInfo;
134}
static V2MusicMetadataInfo * GetTrack(int Id)
Definition: v2music.cpp:109
static V2MusicMetadataInfoList * GetTrackList(int StartIndex, int Count)
Definition: v2music.cpp:43
static void RegisterCustomTypes()
V2Music()
Definition: v2music.cpp:38
QList< MusicMetadata * > MetadataPtrList
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
Q_GLOBAL_STATIC_WITH_ARGS(MythHTTPMetaService, s_service,(MUSIC_HANDLE, V2Music::staticMetaObject, &V2Music::RegisterCustomTypes)) void V2Music
Definition: v2music.cpp:29
#define MUSIC_HANDLE
Definition: v2music.h:18
void V2FillMusicMetadataInfo(V2MusicMetadataInfo *pVideoMetadataInfo, MusicMetadata *pMetadata, bool bDetails)